xiangpeng.wxp commited on
Commit ·
7ac6057
1
Parent(s): ae21363
update usage
Browse files
README.md
CHANGED
|
@@ -65,29 +65,29 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
| 65 |
|
| 66 |
tokenizer = AutoTokenizer.from_pretrained("DAMO-NLP-MT/polylm-13b", use_fast=False)
|
| 67 |
|
| 68 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 69 |
model.eval()
|
| 70 |
|
| 71 |
-
input_doc = "Beijing is the capital of China.
|
| 72 |
|
| 73 |
inputs = tokenizer(input_doc, return_tensors="pt")
|
| 74 |
|
| 75 |
generate_ids = model.generate(
|
| 76 |
-
inputs.input_ids,
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
temperature=0.7,
|
| 83 |
-
repetition_penalty=1.0,
|
| 84 |
-
num_return_sequences=5
|
| 85 |
)
|
| 86 |
|
| 87 |
decoded = tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 88 |
|
| 89 |
print(f">>> {decoded}")
|
| 90 |
|
|
|
|
|
|
|
|
|
|
| 91 |
```
|
| 92 |
|
| 93 |
</details>
|
|
|
|
| 65 |
|
| 66 |
tokenizer = AutoTokenizer.from_pretrained("DAMO-NLP-MT/polylm-13b", use_fast=False)
|
| 67 |
|
| 68 |
+
model = AutoModelForCausalLM.from_pretrained("DAMO-NLP-MT/polylm-13b", device_map="auto")
|
| 69 |
model.eval()
|
| 70 |
|
| 71 |
+
input_doc = f"Beijing is the capital of China.\nTranslate this sentence from English to Chinese."
|
| 72 |
|
| 73 |
inputs = tokenizer(input_doc, return_tensors="pt")
|
| 74 |
|
| 75 |
generate_ids = model.generate(
|
| 76 |
+
inputs.input_ids,
|
| 77 |
+
attention_mask=inputs.attention_mask,
|
| 78 |
+
do_sample=False,
|
| 79 |
+
num_beams=4,
|
| 80 |
+
max_length=128,
|
| 81 |
+
early_stopping=True
|
|
|
|
|
|
|
|
|
|
| 82 |
)
|
| 83 |
|
| 84 |
decoded = tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 85 |
|
| 86 |
print(f">>> {decoded}")
|
| 87 |
|
| 88 |
+
### results
|
| 89 |
+
### Beijing is the capital of China.\nTranslate this sentence from English to Chinese.\\n北京是中华人民共和国的首都。\n ...
|
| 90 |
+
|
| 91 |
```
|
| 92 |
|
| 93 |
</details>
|