kentof commited on
Commit
f997dd0
·
verified ·
1 Parent(s): 80f2d13

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +80 -0
README.md CHANGED
@@ -3,6 +3,86 @@ library_name: transformers
3
  tags: []
4
  ---
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  # Model Card for Model ID
7
 
8
  <!-- Provide a quick summary of what the model is/does. -->
 
3
  tags: []
4
  ---
5
 
6
+ # Evaluation with `elyza-tasks-100-TV_0.jsonl`
7
+
8
+ ```python
9
+ # Put elyza-tasks-100-TV_0.jsonl in the current directory.
10
+
11
+ # Needed for Google Colabolatory
12
+ # !pip install -U bitsandbytes
13
+
14
+ # Load the model
15
+ from transformers import (
16
+ AutoModelForCausalLM,
17
+ AutoTokenizer,
18
+ BitsAndBytesConfig,
19
+ )
20
+ import torch
21
+
22
+ model_id = "kentof/llm-jp-3-13b-finetune"
23
+
24
+ bnb_config = BitsAndBytesConfig(
25
+ load_in_4bit=True,
26
+ bnb_4bit_quant_type="nf4",
27
+ bnb_4bit_compute_dtype=torch.bfloat16,
28
+ )
29
+
30
+ model = AutoModelForCausalLM.from_pretrained(
31
+ model_id,
32
+ quantization_config=bnb_config,
33
+ device_map="auto"
34
+ )
35
+
36
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
37
+
38
+ # Load tasks
39
+ import json
40
+ datasets = []
41
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
42
+ item = ""
43
+ for line in f:
44
+ line = line.strip()
45
+ item += line
46
+ if item.endswith("}"):
47
+ datasets.append(json.loads(item))
48
+ item = ""
49
+
50
+ # Generate
51
+ from tqdm import tqdm
52
+
53
+ results = []
54
+ for data in tqdm(datasets):
55
+
56
+ input = data["input"]
57
+
58
+ prompt = f"""### 指示
59
+ {input}
60
+ ### 回答
61
+ """
62
+
63
+ tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
64
+ attention_mask = torch.ones_like(tokenized_input)
65
+
66
+ with torch.no_grad():
67
+ outputs = model.generate(
68
+ tokenized_input,
69
+ attention_mask=attention_mask,
70
+ max_new_tokens=100,
71
+ do_sample=False,
72
+ repetition_penalty=1.2,
73
+ pad_token_id=tokenizer.eos_token_id
74
+ )[0]
75
+ output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
76
+
77
+ results.append({"task_id": data["task_id"], "input": input, "output": output})
78
+
79
+ # Write a file
80
+ with open(f"./{model_id}-outputs.jsonl", 'w', encoding='utf-8') as f:
81
+ for result in results:
82
+ json.dump(result, f, ensure_ascii=False) # ensure_ascii=False for handling non-ASCII characters
83
+ f.write('\n')
84
+ ```
85
+
86
  # Model Card for Model ID
87
 
88
  <!-- Provide a quick summary of what the model is/does. -->