企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[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) // 机器学习之家 ```