NanoTranslator-365M-immersive_translate-v1 is a translation model specifically designed for
Chinese-English bilingual
translation, trained with 200M data from the
wmt-19
dataset, based on
NanoLM-365M-Base
.
This model is trained following the Immersive Translate prompt format and can be deployed as an OpenAI format interface using tools like vllm and lmdeploy for utilization.
How to use
Below is a method to call the model using transformers. The prompt follows the immersive translation format to ensure optimal results.
import torch
from typing importLiteralfrom transformers import AutoModelForCausalLM, AutoTokenizer
model_path = 'Mxode/NanoTranslator-365M-immersive_translate-v1'
model = AutoModelForCausalLM.from_pretrained(model_path).to('cuda:0', torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained(model_path)
deftranslate(
text: str, to: Literal["chinese", "english"] = "chinese", **kwargs
):
generation_args = dict(
max_new_tokens = kwargs.pop("max_new_tokens", 512),
do_sample = kwargs.pop("do_sample", True),
temperature = kwargs.pop("temperature", 0.35),
top_p = kwargs.pop("top_p", 0.8),
top_k = kwargs.pop("top_k", 40),
**kwargs
)
prompt = """Translate the following source text to {to}. Output translation directly without any additional text. Source Text: {text} Translated Text:"""
messages = [
{"role": "system", "content": "You are a professional, authentic machine translation engine."},
{"role": "user", "content": prompt.format(to=to, text=text)}
]
inputs = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([inputs], return_tensors="pt").to(model.device)
generated_ids = model.generate(model_inputs.input_ids, **generation_args)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids inzip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
return response
text = "After a long day at work, I love to unwind by cooking a nice dinner and watching my favorite TV series. It really helps me relax and recharge for the next day."
response = translate(text=text, to='chinese')
print(f'Translation: {response}')
"""Translation: 工作了一天,我喜欢吃一顿美味的晚餐,看我最喜欢的电视剧,这样做有助于我放松,补充能量。"""
Runs of Mxode NanoTranslator-365M-immersive_translate-v1 on huggingface.co
0
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs
More Information About NanoTranslator-365M-immersive_translate-v1 huggingface.co Model
More NanoTranslator-365M-immersive_translate-v1 license Visit here:
NanoTranslator-365M-immersive_translate-v1 huggingface.co is an AI model on huggingface.co that provides NanoTranslator-365M-immersive_translate-v1's model effect (), which can be used instantly with this Mxode NanoTranslator-365M-immersive_translate-v1 model. huggingface.co supports a free trial of the NanoTranslator-365M-immersive_translate-v1 model, and also provides paid use of the NanoTranslator-365M-immersive_translate-v1. Support call NanoTranslator-365M-immersive_translate-v1 model through api, including Node.js, Python, http.
NanoTranslator-365M-immersive_translate-v1 huggingface.co is an online trial and call api platform, which integrates NanoTranslator-365M-immersive_translate-v1's modeling effects, including api services, and provides a free online trial of NanoTranslator-365M-immersive_translate-v1, you can try NanoTranslator-365M-immersive_translate-v1 online for free by clicking the link below.
Mxode NanoTranslator-365M-immersive_translate-v1 online free url in huggingface.co:
NanoTranslator-365M-immersive_translate-v1 is an open source model from GitHub that offers a free installation service, and any user can find NanoTranslator-365M-immersive_translate-v1 on GitHub to install. At the same time, huggingface.co provides the effect of NanoTranslator-365M-immersive_translate-v1 install, users can directly use NanoTranslator-365M-immersive_translate-v1 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
NanoTranslator-365M-immersive_translate-v1 install url in huggingface.co: