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