今天來試試翻譯(Translation),這是最常見的 NLP 應用之一。
實際操作
使用translation pipeline,在Colab輸入程式碼
from transformers import pipeline
translator = pipeline("translation_en_to_zh", model="Helsinki-NLP/opus-mt-en-zh")
text = "Artificial intelligence is transforming the future of healthcare."
result = translator(text, max_length=40)
print(result[0]['translation_text'])
得出的結果為
對於我這種醫資系背景的學生來說,翻譯的應用場景非常多:
雖然Hugging Face提供的模型不一定像Google翻譯那樣完整,但它的好處是能嵌進自己的應用程式裡,做出更客製化的翻譯工具。