Update README.md
Browse files
README.md
CHANGED
@@ -70,23 +70,25 @@ pip install -q ./transformers
|
|
70 |
```
|
71 |
|
72 |
```python
|
73 |
-
from transformers import
|
74 |
|
75 |
-
ckpt = '
|
76 |
|
77 |
-
tokenizer =
|
78 |
-
model =
|
79 |
|
80 |
-
|
81 |
|
82 |
-
|
|
|
|
|
83 |
input_ids = inputs.input_ids.to('cuda')
|
84 |
attention_mask = inputs.attention_mask.to('cuda')
|
85 |
-
output = model.generate(input_ids, attention_mask=attention_mask)
|
86 |
return tokenizer.decode(output[0], skip_special_tokens=True)
|
87 |
|
88 |
|
89 |
-
|
90 |
```
|
91 |
|
92 |
Created by: [Narrativa](https://www.narrativa.com/)
|
|
|
70 |
```
|
71 |
|
72 |
```python
|
73 |
+
from transformers import MBart50TokenizerFast, MBartForConditionalGeneration
|
74 |
|
75 |
+
ckpt = 'mbart-large-50-finetuned-opus-en-pt-translation'
|
76 |
|
77 |
+
tokenizer = MBart50TokenizerFast.from_pretrained(ckpt)
|
78 |
+
model = MBartForConditionalGeneration.from_pretrained(ckpt).to("cuda")
|
79 |
|
80 |
+
tokenizer.src_lang = 'en_XX'
|
81 |
|
82 |
+
def translate(text):
|
83 |
+
|
84 |
+
inputs = tokenizer(text, return_tensors='pt')
|
85 |
input_ids = inputs.input_ids.to('cuda')
|
86 |
attention_mask = inputs.attention_mask.to('cuda')
|
87 |
+
output = model.generate(input_ids, attention_mask=attention_mask, forced_bos_token_id=tokenizer.lang_code_to_id['pt_XX'])
|
88 |
return tokenizer.decode(output[0], skip_special_tokens=True)
|
89 |
|
90 |
|
91 |
+
translate('here your English text to be translated to Portuguese...')
|
92 |
```
|
93 |
|
94 |
Created by: [Narrativa](https://www.narrativa.com/)
|