開始使用免費開始

翻譯文字

你已經看過英翻西的範例。現在換你試試看相反方向:把西班牙文翻成英文。

已為你載入 pipeline

本練習屬於課程

Python 的 LLM 入門

檢視課程

練習說明

  • 定義西翻英(es_to_en)的 pipeline 任務。
  • 使用模型的 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"])
編輯並執行程式碼