losca commited on
Commit
71d7128
1 Parent(s): b74d086

Update README.md

Browse files

Added example usage

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