Update README.md
Browse files
README.md
CHANGED
|
@@ -27,26 +27,33 @@ This is the model card of a 🤗 transformers model that has been pushed on the
|
|
| 27 |
- **License:** [More Information Needed]
|
| 28 |
- **Finetuned from model [google-t5-small]:** [More Information Needed]
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 32 |
|
| 33 |
-
|
| 34 |
model.to(device)
|
| 35 |
|
| 36 |
-
|
| 37 |
-
input_text = "сайн уу"
|
| 38 |
|
| 39 |
-
|
| 40 |
inputs = tokenizer(input_text, return_tensors="pt")
|
| 41 |
|
| 42 |
-
|
| 43 |
inputs = {k: v.to(device) for k, v in inputs.items() if k in ['input_ids', 'attention_mask']}
|
| 44 |
|
| 45 |
-
|
| 46 |
outputs = model.generate(**inputs)
|
| 47 |
|
| 48 |
-
|
| 49 |
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 50 |
|
| 51 |
-
|
| 52 |
print(f"Translated Text: {translated_text}")
|
|
|
|
| 27 |
- **License:** [More Information Needed]
|
| 28 |
- **Finetuned from model [google-t5-small]:** [More Information Needed]
|
| 29 |
|
| 30 |
+
|
| 31 |
+
- ** Load model directly
|
| 32 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 33 |
+
|
| 34 |
+
tokenizer = AutoTokenizer.from_pretrained("onlysainaa/cyrillic_to_script-t5-model")
|
| 35 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("onlysainaa/cyrillic_to_script-t5-model")
|
| 36 |
+
|
| 37 |
+
- ** Check if CUDA (GPU) is available
|
| 38 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 39 |
|
| 40 |
+
- ** Move the model to the same device (GPU or CPU)
|
| 41 |
model.to(device)
|
| 42 |
|
| 43 |
+
- ** Prepare text input
|
| 44 |
+
input_text = "сайн уу" - ** Mongolian greeting
|
| 45 |
|
| 46 |
+
- ** Tokenize the input text
|
| 47 |
inputs = tokenizer(input_text, return_tensors="pt")
|
| 48 |
|
| 49 |
+
- ** Move the input tensors to the same device as the model
|
| 50 |
inputs = {k: v.to(device) for k, v in inputs.items() if k in ['input_ids', 'attention_mask']}
|
| 51 |
|
| 52 |
+
- ** Generate translation
|
| 53 |
outputs = model.generate(**inputs)
|
| 54 |
|
| 55 |
+
- ** Decode the output to human-readable text
|
| 56 |
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 57 |
|
| 58 |
+
- ** Print the translated text
|
| 59 |
print(f"Translated Text: {translated_text}")
|