Update README.md
Browse files
README.md
CHANGED
@@ -97,23 +97,23 @@ Use the code below to get started with the model.
|
|
97 |
```python
|
98 |
import torch
|
99 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
100 |
torch.manual_seed(42)
|
101 |
|
102 |
-
PROMPT_TEMPLATE = '''
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
{criteria_rubrics}
|
117 |
'''
|
118 |
|
119 |
instruction = 'Сколько будет 2+2?'
|
@@ -121,7 +121,9 @@ reference_answer = ''
|
|
121 |
answer = 'Будет 4'
|
122 |
criteria_name = 'Правильность ответа'
|
123 |
criteria_rubrics = '''0: Дан неправильный ответ или ответ отсутствует.
|
|
|
124 |
1: Ответ модели неполный (не на все вопросы задания получен ответ, в формулировке ответа отсутствует часть информации).
|
|
|
125 |
2: Ответ модели совпадает с эталонным или эквивалентен ему.'''
|
126 |
|
127 |
prompt = PROMPT_TEMPLATE.format(instruction=instruction,
|
@@ -135,7 +137,8 @@ tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
|
135 |
model = AutoModelForCausalLM.from_pretrained(
|
136 |
MODEL_PATH,
|
137 |
torch_dtype="auto",
|
138 |
-
device_map="auto"
|
|
|
139 |
)
|
140 |
|
141 |
messages = [
|
@@ -147,14 +150,17 @@ text = tokenizer.apply_chat_template(
|
|
147 |
add_generation_prompt=True
|
148 |
)
|
149 |
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
150 |
-
|
|
|
151 |
**model_inputs,
|
152 |
max_new_tokens=4096
|
153 |
)
|
154 |
generated_ids = [
|
155 |
-
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids,
|
156 |
]
|
|
|
157 |
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
|
|
158 |
print(response)
|
159 |
```
|
160 |
|
|
|
97 |
```python
|
98 |
import torch
|
99 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
100 |
+
|
101 |
torch.manual_seed(42)
|
102 |
|
103 |
+
PROMPT_TEMPLATE = '''### Задание для оценки:
|
104 |
+
{instruction}
|
105 |
+
|
106 |
+
### Эталонный ответ:
|
107 |
+
{reference_answer}
|
108 |
+
|
109 |
+
### Ответ для оценки:
|
110 |
+
{answer}
|
111 |
+
|
112 |
+
### Критерий оценки:
|
113 |
+
{criteria_name}
|
114 |
+
|
115 |
+
### Шкала оценивания по критерию:
|
116 |
+
{criteria_rubrics}
|
|
|
117 |
'''
|
118 |
|
119 |
instruction = 'Сколько будет 2+2?'
|
|
|
121 |
answer = 'Будет 4'
|
122 |
criteria_name = 'Правильность ответа'
|
123 |
criteria_rubrics = '''0: Дан неправильный ответ или ответ отсутствует.
|
124 |
+
|
125 |
1: Ответ модели неполный (не на все вопросы задания получен ответ, в формулировке ответа отсутствует часть информации).
|
126 |
+
|
127 |
2: Ответ модели совпадает с эталонным или эквивалентен ему.'''
|
128 |
|
129 |
prompt = PROMPT_TEMPLATE.format(instruction=instruction,
|
|
|
137 |
model = AutoModelForCausalLM.from_pretrained(
|
138 |
MODEL_PATH,
|
139 |
torch_dtype="auto",
|
140 |
+
device_map="auto",
|
141 |
+
trust_remote_code=True
|
142 |
)
|
143 |
|
144 |
messages = [
|
|
|
150 |
add_generation_prompt=True
|
151 |
)
|
152 |
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
153 |
+
|
154 |
+
sequence_ids = model.generate(
|
155 |
**model_inputs,
|
156 |
max_new_tokens=4096
|
157 |
)
|
158 |
generated_ids = [
|
159 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, sequence_ids)
|
160 |
]
|
161 |
+
|
162 |
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
163 |
+
|
164 |
print(response)
|
165 |
```
|
166 |
|