Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,59 @@
|
|
| 1 |
-
---
|
| 2 |
-
license:
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
- zh
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
Github: https://github.com/jasonNLP/TAT-R1
|
| 9 |
+
|
| 10 |
+
## Quickstart
|
| 11 |
+
Here provides a code snippet to show you how to load the tokenizer and model and how to generate contents.
|
| 12 |
+
|
| 13 |
+
```python
|
| 14 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 15 |
+
|
| 16 |
+
model_name = "hhoh/TAT-R1"
|
| 17 |
+
|
| 18 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 19 |
+
model_name,
|
| 20 |
+
torch_dtype="auto",
|
| 21 |
+
device_map="auto"
|
| 22 |
+
)
|
| 23 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
system_prompt = """A conversation between User and Assistant. The User asks a question, and the Assistant solves it. \
|
| 27 |
+
The Assistant first thinks about the reasoning process in the mind and then provides the User with the answer. \
|
| 28 |
+
The reasoning process is enclosed within <think> </think> and answer is enclosed within <answer> </answer> tags, respectively, \
|
| 29 |
+
i.e., <think> reasoning process here </think> <answer> answer here </answer>. \
|
| 30 |
+
|
| 31 |
+
User:
|
| 32 |
+
{}
|
| 33 |
+
|
| 34 |
+
Assistant:
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
# For English to Chinese translation, use:
|
| 38 |
+
query = "Translate the flowing text into Chinese, do not explain:\n{}"
|
| 39 |
+
# For Chinese to English translation, use:
|
| 40 |
+
# query = "Translate the flowing text into English, do not explain:\n{}"
|
| 41 |
+
|
| 42 |
+
src_text = "Plants make oxygen which humans breathe, and they take in carbon-dioxide which humans exhale (that is, breathe out)."
|
| 43 |
+
prompt = system_prompt.format(query.format(src_text))
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
model_inputs = tokenizer([prompt], return_tensors="pt").to(model.device)
|
| 47 |
+
|
| 48 |
+
generated_ids = model.generate(
|
| 49 |
+
**model_inputs,
|
| 50 |
+
max_new_tokens=2048
|
| 51 |
+
)
|
| 52 |
+
generated_ids = [
|
| 53 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 54 |
+
]
|
| 55 |
+
|
| 56 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 57 |
+
print(response)
|
| 58 |
+
|
| 59 |
+
```
|