feat add no_repeat_ngram
Browse files- README.md +8 -2
- generation_config.json +1 -0
README.md
CHANGED
@@ -42,8 +42,11 @@ Example translate Russian to Chinese
|
|
42 |
```python
|
43 |
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
44 |
|
|
|
|
|
45 |
model_name = 'utrobinmv/t5_translate_en_ru_zh_large_1024'
|
46 |
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
|
|
47 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
48 |
|
49 |
prefix = 'translate to zh: '
|
@@ -52,7 +55,7 @@ src_text = prefix + "Съешь ещё этих мягких французск
|
|
52 |
# translate Russian to Chinese
|
53 |
input_ids = tokenizer(src_text, return_tensors="pt")
|
54 |
|
55 |
-
generated_tokens = model.generate(**input_ids)
|
56 |
|
57 |
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|
58 |
print(result)
|
@@ -66,8 +69,11 @@ and Example translate Chinese to Russian
|
|
66 |
```python
|
67 |
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
68 |
|
|
|
|
|
69 |
model_name = 'utrobinmv/t5_translate_en_ru_zh_large_1024'
|
70 |
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
|
|
71 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
72 |
|
73 |
prefix = 'translate to ru: '
|
@@ -76,7 +82,7 @@ src_text = prefix + "再吃这些法国的甜蜜的面包。"
|
|
76 |
# translate Russian to Chinese
|
77 |
input_ids = tokenizer(src_text, return_tensors="pt")
|
78 |
|
79 |
-
generated_tokens = model.generate(**input_ids)
|
80 |
|
81 |
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|
82 |
print(result)
|
|
|
42 |
```python
|
43 |
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
44 |
|
45 |
+
device = 'cuda' #or 'cpu' for translate on cpu
|
46 |
+
|
47 |
model_name = 'utrobinmv/t5_translate_en_ru_zh_large_1024'
|
48 |
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
49 |
+
model.to(device)
|
50 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
51 |
|
52 |
prefix = 'translate to zh: '
|
|
|
55 |
# translate Russian to Chinese
|
56 |
input_ids = tokenizer(src_text, return_tensors="pt")
|
57 |
|
58 |
+
generated_tokens = model.generate(**input_ids,to(device))
|
59 |
|
60 |
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|
61 |
print(result)
|
|
|
69 |
```python
|
70 |
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
71 |
|
72 |
+
device = 'cuda' #or 'cpu' for translate on cpu
|
73 |
+
|
74 |
model_name = 'utrobinmv/t5_translate_en_ru_zh_large_1024'
|
75 |
model = T5ForConditionalGeneration.from_pretrained(model_name)
|
76 |
+
model.to(device)
|
77 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
78 |
|
79 |
prefix = 'translate to ru: '
|
|
|
82 |
# translate Russian to Chinese
|
83 |
input_ids = tokenizer(src_text, return_tensors="pt")
|
84 |
|
85 |
+
generated_tokens = model.generate(**input_ids,to(device))
|
86 |
|
87 |
result = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|
88 |
print(result)
|
generation_config.json
CHANGED
@@ -5,5 +5,6 @@
|
|
5 |
"max_new_tokens": 1024,
|
6 |
"repetition_penalty": 5.0,
|
7 |
"num_beams": 5,
|
|
|
8 |
"transformers_version": "4.33.0"
|
9 |
}
|
|
|
5 |
"max_new_tokens": 1024,
|
6 |
"repetition_penalty": 5.0,
|
7 |
"num_beams": 5,
|
8 |
+
"no_repeat_ngram_size": 3,
|
9 |
"transformers_version": "4.33.0"
|
10 |
}
|