frankmorales2020 commited on
Commit
a3dbb35
·
verified ·
1 Parent(s): a3a4f07

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +49 -0
README.md CHANGED
@@ -83,6 +83,55 @@ Use the code below to get started with the model.
83
 
84
  ### Training Procedure
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
 
88
  #### Preprocessing [optional]
 
83
 
84
  ### Training Procedure
85
 
86
+
87
+ ```python
88
+
89
+ from transformers import MBart50TokenizerFast, MBartForConditionalGeneration
90
+ import torch
91
+
92
+ repo_id = "frankmorales2020/kkadian-to-spanish-translator"
93
+ tokenizer = MBart50TokenizerFast.from_pretrained(repo_id)
94
+ model = MBartForConditionalGeneration.from_pretrained(repo_id)
95
+
96
+ def test_model(sentences):
97
+ tokenizer.src_lang = "[akk_AK]"
98
+ es_id = tokenizer.convert_tokens_to_ids("es_XX")
99
+
100
+ for text in sentences:
101
+ inputs = tokenizer(text, return_tensors="pt")
102
+ with torch.no_grad():
103
+ generated_tokens = model.generate(
104
+ **inputs,
105
+ forced_bos_token_id=es_id,
106
+ max_new_tokens=60,
107
+ num_beams=5
108
+ )
109
+ translation = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
110
+
111
+ print("-" * 40)
112
+ print(f"AKKADIAN: {text}")
113
+ print(f"SPANISH: {translation}")
114
+
115
+ # List your test cases here
116
+ examples = [
117
+ "šarrum bītam iṣbat",
118
+ "ekallam īpuš"
119
+ ]
120
+
121
+ test_model(examples)
122
+ print("-" * 40)
123
+ ```
124
+ ```python
125
+
126
+ ----------------------------------------
127
+ AKKADIAN: šarrum bītam iṣbat
128
+ SPANISH: el rey tomó la casa
129
+ ----------------------------------------
130
+ AKKADIAN: ekallam īpuš
131
+ SPANISH: él construyó el palacio
132
+ ----------------------------------------
133
+
134
+ ```
135
  <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
136
 
137
  #### Preprocessing [optional]