🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## 翻译 我们使用 pipeline的 参数 `translation_xx_to_yy`使用英文转中文 ``` from transformers import pipeline, AutoModelWithLMHead, AutoTokenizer model = AutoModelWithLMHead.from_pretrained("Helsinki-NLP/opus-mt-en-zh") tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-zh") translation = pipeline("translation_en_to_zh", model=model, tokenizer=tokenizer) text = "The Home of Machine Learning" translated_text = translation(text, max_length=40)[0]['translation_text'] print(translated_text) // 机器学习之家 ```