Files changed (1) hide show
  1. README.md +40 -3
README.md CHANGED
@@ -1,3 +1,40 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+
5
+ This is a many-to-many model for Creole-English, English-Creole and Creole-Creole MT, trained from scratch on all data.
6
+
7
+ ```
8
+ from transformers import MBartForConditionalGeneration, AutoModelForSeq2SeqLM
9
+ from transformers import AlbertTokenizer, AutoTokenizer
10
+
11
+ tokenizer = AutoTokenizer.from_pretrained("n8rob/kreyol-mt-scratch", do_lower_case=False, use_fast=False, keep_accents=True)
12
+
13
+ # The tokenizer we use is based on the AlbertTokenizer class which is essentially sentencepiece. We train this sentencepeice model from scratch.
14
+ # Or use tokenizer = AlbertTokenizer.from_pretrained("n8rob/kreyol-mt-scratch", do_lower_case=False, use_fast=False, keep_accents=True)
15
+
16
+ model = AutoModelForSeq2SeqLM.from_pretrained("n8rob/kreyol-mt-scratch")
17
+
18
+ # Or use model = MBartForConditionalGeneration.from_pretrained("n8rob/kreyol-mt-scratch")
19
+
20
+ # Some initial mapping
21
+ bos_id = tokenizer._convert_token_to_id_with_added_voc("<s>")
22
+ eos_id = tokenizer._convert_token_to_id_with_added_voc("</s>")
23
+ pad_id = tokenizer._convert_token_to_id_with_added_voc("<pad>")
24
+
25
+ # First tokenize the input and outputs. The format below is how the model was trained so the input should be "Sentence </s> <2hwc>". Similarly, the output should be "<2eng> Sentence </s>".
26
+ # For Hawaiian Creole to English translation, we need to use language indicator tags: <2hwc> and <2eng> where hwc represents Hawaiian Creole and eng represents English.
27
+ # The following language indicator tokens are usable: <2acf>, <2aoa>, <2ara>, <2aze>, <2bah>, <2brc>, <2bzj>, <2bzk>, <2cab>, <2ceb>, <2cri>, <2crs>, <2dcr>, <2deu>, <2djk>, <2eng>, <2fab>, <2fng>, <2fpe>, <2fra>, <2gcf>, <2gcr>, <2gpe>, <2gul>, <2gyn>, <2hat>, <2icr>, <2jam>, <2kea>, <2kri>, <2ktu>, <2lou>, <2mart1259>, <2mfe>, <2mue>, <2nep>, <2pap>, <2pcm>, <2por>, <2pov>, <2pre>, <2rcf>, <2sag>, <2spa>, <2srm>, <2srn>, <2svc>, <2tpi>, <2trf>, <2wes>, <2zho>
28
+ # For what language each language code corresponds to please look here: https://github.com/JHU-CLSP/Kreyol-MT?tab=readme-ov-file#building-machine-translation-for-latin-american-caribbean-and-colonial-african-creole-languages
29
+
30
+ inp = tokenizer('Wen dey wen stretch him out fo whip him real hard , Paul wen tell da captain dat stay dea , "Dis okay in da rules fo da Rome peopo ? fo you fo whip one guy dat get da same rights jalike da Rome peopo ? even one guy dat neva do notting wrong ?" </s> <2hwc>', add_special_tokens=False, return_tensors="pt", padding=True).input_ids
31
+
32
+ model.eval() # Set dropouts to zero
33
+
34
+ model_output=model.generate(inp, use_cache=True, num_beams=4, max_length=60, min_length=1, early_stopping=True, pad_token_id=pad_id, bos_token_id=bos_id, eos_token_id=eos_id, decoder_start_token_id=tokenizer._convert_token_to_id_with_added_voc("<2eng>"))
35
+
36
+ decoded_output=tokenizer.decode(model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
37
+
38
+ print(decoded_output)
39
+
40
+ ```