将客户评论翻译成法语
一家全球电商公司正在分析英语用户的反馈。为支持法语客服团队,公司需要将这些评论翻译成法语。作为 NLP 流水线的一部分,您的任务是使用 Hugging Face 的 pipeline 自动化完成评论翻译。
本练习是课程的一部分
Python 中的自然语言处理(NLP)
练习说明
- 使用
"Helsinki-NLP/opus-mt-en-fr"模型创建一个translator管道。 - 将提供的
review从英语翻译成法语。
交互式实操练习
通过完成这段示例代码来试试这个练习。
from transformers import pipeline
# Create the translation pipeline
translator = pipeline(task="____", model="____")
review = "The hotel was clean and the staff were very friendly."
# Translate the review
translation = ____
print(translation)