Update README.md
Browse filesAdded example usage
README.md
CHANGED
@@ -15,6 +15,29 @@ This is a finetuning of a MarianMT pretrained on English-Chinese. The target lan
|
|
15 |
The first phase of training (mixed) is performed on a dataset containing both English-Chinese and English-Vietnamese sentences.
|
16 |
The second phase of training (pure) is performed on a dataset containing only English-Vietnamese sentences.
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
### Training results
|
20 |
|
|
|
15 |
The first phase of training (mixed) is performed on a dataset containing both English-Chinese and English-Vietnamese sentences.
|
16 |
The second phase of training (pure) is performed on a dataset containing only English-Vietnamese sentences.
|
17 |
|
18 |
+
### Example
|
19 |
+
```
|
20 |
+
%%capture
|
21 |
+
!pip install transformers transformers[sentencepiece]
|
22 |
+
|
23 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
24 |
+
# Download the pretrained model for English-Vietnamese available on the hub
|
25 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("CLAck/en-vi")
|
26 |
+
|
27 |
+
tokenizer = AutoTokenizer.from_pretrained("CLAck/en-vi")
|
28 |
+
# Download a tokenizer that can tokenize English since the model Tokenizer doesn't know anymore how to do it
|
29 |
+
# We used the one coming from the initial model
|
30 |
+
# This tokenizer is used to tokenize the input sentence
|
31 |
+
tokenizer_en = AutoTokenizer.from_pretrained('Helsinki-NLP/opus-mt-en-zh')
|
32 |
+
# These special tokens are needed to reproduce the original tokenizer
|
33 |
+
tokenizer_en.add_tokens(["<2zh>", "<2vi>"], special_tokens=True)
|
34 |
+
|
35 |
+
sentence = "The cat is on the table"
|
36 |
+
# This token is needed to identify the target language
|
37 |
+
input_sentence = "<2vi> " + sentence
|
38 |
+
translated = model.generate(**tokenizer_en(input_sentence, return_tensors="pt", padding=True))
|
39 |
+
output_sentence = [tokenizer.decode(t, skip_special_tokens=True) for t in translated]
|
40 |
+
```
|
41 |
|
42 |
### Training results
|
43 |
|