9️⃣Translation

번역 모델을 사용하여 여러 언어에 걸쳐 대화형 에이전트를 구축할 수 있습니다. 이는 두 가지 방법으로 수행할 수 있습니다.

  1. Translate the dataset to a new language

  • 의도(입력) 및 응답의 데이터 집합을 대상 언어로 번역할 수 있습니다.

  • 그런 다음 이 새로운 데이터 세트로 새로운 의도 분류 모델을 학습할 수 있습니다.

  • 이를 통해 대상 언어로 응답을 교정하고 챗봇의 출력을 더 잘 제어할 수 있습니다.

  1. Translate the input and output of the agent

  • 사용자 입력에 번역 모델을 사용하여 챗봇이 이를 처리할 수 있도록 할 수 있습니다.

  • 그런 다음 챗봇의 출력을 사용자의 언어로 번역할 수 있습니다.

  • 이 접근 방식은 챗봇이 이전에 정의되지 않은 응답을 생성하므로 신뢰성이 떨어질 수 있습니다.

translation pipeline

'nllb-200-distilled-600M'

from transformers import pipeline 
import torch
/home/kubwa/anaconda3/envs/pytorch/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm
translator = pipeline(task="translation",
                      model="facebook/nllb-200-distilled-600M",
                      torch_dtype=torch.bfloat16) 
text = """\
My puppy is adorable, \
Your kitten is cute.
Her panda is friendly.
His llama is thoughtful. \
We all have nice pets!"""
text_translated = translator(text,
                             src_lang="eng_Latn",
                             tgt_lang="kor_Hang")

다른 언어를 선택하려면 페이지에서 다른 언어 코드를 찾을 수 있습니다: Languages in FLORES-200

For example:

  • Afrikaans: afr_Latn

  • Chinese: zho_Hans

  • Egyptian Arabic: arz_Arab

  • French: fra_Latn

  • German: deu_Latn

  • Greek: ell_Grek

  • Hindi: hin_Deva

  • Indonesian: ind_Latn

  • Italian: ita_Latn

  • Japanese: jpn_Jpan

  • Korean: kor_Hang

  • Persian: pes_Arab

  • Portuguese: por_Latn

  • Russian: rus_Cyrl

  • Spanish: spa_Latn

  • Swahili: swh_Latn

  • Thai: tha_Thai

  • Turkish: tur_Latn

  • Vietnamese: vie_Latn

  • Zulu: zul_Latn

text_translated
[{'translation_text': '내 강아지는 사랑스럽고, 당신의 새끼 고양이는 귀여운데, 그녀의 팬다는 친절하고, 그의 라마는 신중합니다. 우리 모두는 좋은 애완동물들을 가지고 있습니다.'}]

Last updated