import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import logging
logging.getLogger("transformers.tokenization_utils_base").setLevel(logging.ERROR)
model_name = f"piyazon/uyghur_translate_dev2"
src_lang = "eng_Latn"
tgt_lang = "uig_Arab"# Priority: CUDA > MPS > CPUif torch.cuda.is_available():
device = torch.device("cuda")
elif torch.backends.mps.is_available():
device = torch.device("mps")
else:
device = torch.device("cpu")
print(f"Using device: cuda")
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name).to(device)
tokenizer.src_lang = src_lang
text = "Let's answer a question: What is the radius of the Earth? The Earth's average radius is approximately 6371 kilometers, which is the average value of the distance from the equator to the poles."# 1. PRE-PROCESSING (Crucial Step)
inputs = tokenizer(
text,
return_tensors="pt",
padding=True,
truncation=True,
).to(device)
# 2. PREPARE TARGET TOKEN
forced_bos_token_id = tokenizer.convert_tokens_to_ids(tgt_lang)
# 3. GENERATIONwith torch.no_grad():
out = model.generate(
**inputs,
forced_bos_token_id=forced_bos_token_id,
max_new_tokens=128,
num_beams=4,
no_repeat_ngram_size=3
)
# 4. DECODE# Clean up the output
translation = tokenizer.batch_decode(out, skip_special_tokens=True)[0]
print(translation)
Runs of piyazon uyghur_translate_dev2 on huggingface.co
0
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
-13
30-day runs
More Information About uyghur_translate_dev2 huggingface.co Model
uyghur_translate_dev2 huggingface.co
uyghur_translate_dev2 huggingface.co is an AI model on huggingface.co that provides uyghur_translate_dev2's model effect (), which can be used instantly with this piyazon uyghur_translate_dev2 model. huggingface.co supports a free trial of the uyghur_translate_dev2 model, and also provides paid use of the uyghur_translate_dev2. Support call uyghur_translate_dev2 model through api, including Node.js, Python, http.
uyghur_translate_dev2 huggingface.co is an online trial and call api platform, which integrates uyghur_translate_dev2's modeling effects, including api services, and provides a free online trial of uyghur_translate_dev2, you can try uyghur_translate_dev2 online for free by clicking the link below.
piyazon uyghur_translate_dev2 online free url in huggingface.co:
uyghur_translate_dev2 is an open source model from GitHub that offers a free installation service, and any user can find uyghur_translate_dev2 on GitHub to install. At the same time, huggingface.co provides the effect of uyghur_translate_dev2 install, users can directly use uyghur_translate_dev2 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
uyghur_translate_dev2 install url in huggingface.co: