사전 학습된 LLM 활용

Python으로 배우는 LLM 입문

Jasmin Ludolf

Senior Data Science Content Developer, DataCamp

언어 이해

텍스트 분류, 요약, 감성 분석, 질의응답 등의 작업을 나타내는 그림이 주변에 있는 책상에 앉은 사람

Python으로 배우는 LLM 입문

언어 생성

텍스트 생성 및 번역 작업을 나타내는 그림이 주변에 있는 책상에 앉은 사람

Python으로 배우는 LLM 입문

텍스트 생성

generator = pipeline(task="text-generation", model="distilgpt2")

prompt = "The Gion neighborhood in Kyoto is famous for"

output = generator(prompt, max_length=100, pad_token_id=generator.tokenizer.eos_token_id)
  • 일관성
  • 의미 있는 내용
  • 사람과 유사한 텍스트
  • eos_token_id: 시퀀스 종료 토큰 ID
Python으로 배우는 LLM 입문

텍스트 생성

두 시퀀스(we should go, i really like to travel)의 토큰 ID, 패딩 및 EOS 위치를 나타낸 그림

  • pad_token_id: max_length까지 빈 공간을 채움
  • 패딩: 토큰 추가
  • generator.tokenizer.eos_token_id로 설정하면 학습을 통해 의미 있는 텍스트의 끝을 표시
  • 모델은 max_length 또는 pad_token_id까지 생성
  • truncation = True
Python으로 배우는 LLM 입문

텍스트 생성

generator = pipeline(task="text-generation", model="distilgpt2")

prompt = "The Gion neighborhood in Kyoto is famous for"

output = generator(prompt, max_length=100, pad_token_id=generator.tokenizer.eos_token_id)

print(output[0]["generated_text"])
The Gion neighborhood in Kyoto is famous for its many colorful green forests, such as the 
Red Hill, the Red River and the Red River. The Gion neighborhood is home to the world's 
tallest trees.
  • 프롬프트가 모호하면 출력이 불량할 수 있음
Python으로 배우는 LLM 입문

출력 유도

generator = pipeline(task="text-generation", model="distilgpt2")


review = "This book was great. I enjoyed the plot twist in Chapter 10." response = "Dear reader, thank you for your review." prompt = f"Book review:\n{review}\n\nBook shop response to the review:\n{response}"
output = generator(prompt, max_length=100, pad_token_id=generator.tokenizer.eos_token_id) print(output[0]["generated_text"])
Dear reader, thank you for your review. We'd like to thank you for your reading!
Python으로 배우는 LLM 입문

언어 번역

  • Hugging Face에서 번역 태스크 및 모델 전체 목록 제공
translator = pipeline(task="translation_en_to_es", model="Helsinki-NLP/opus-mt-en-es")

text = "Walking amid Gion's Machiya wooden houses was a mesmerizing experience."
output = translator(text, clean_up_tokenization_spaces=True)
print(output[0]["translation_text"])
Caminar entre las casas de madera Machiya de Gion fue una experiencia fascinante.
Python으로 배우는 LLM 입문

연습해 봅시다!

Python으로 배우는 LLM 입문

Preparing Video For Download...