开始使用免费开始使用

翻译文本

您已经看过英译西的示例。现在请尝试相反方向:把西班牙语翻译成英语。

pipeline 已为您加载。

本练习是课程的一部分

Python 中的 LLM 入门

查看课程

练习说明

  • 定义西译英的 pipeline 任务(es_to_en)。
  • 使用模型的 pipeline 翻译 spanish_text

交互式实操练习

通过完成这段示例代码来试试这个练习。

spanish_text = "Este curso sobre LLMs se está poniendo muy interesante"

# Define the pipeline
translator = pipeline(task=____, model="Helsinki-NLP/opus-mt-es-en")

# Translate the Spanish text
translations = ____(____, clean_up_tokenization_spaces=True)

print(translations[0]["translation_text"])
编辑并运行代码