시퀀스 생성 작업

Python으로 배우는 Natural Language Processing (NLP)

Fouad Trad

Machine Learning Engineer

시퀀스 생성

  • 입력을 바탕으로 새 텍스트 생성
  • 포함 작업:
    • 텍스트 요약
    • 텍스트 번역
    • 언어 모델링

종이에 연필로 문장을 쓰는 GIF.

Python으로 배우는 Natural Language Processing (NLP)

텍스트 요약

  • 긴 문서를 핵심만 담은 짧은 버전으로 압축
  • 유용한 경우:
    • 장문의 뉴스 기사
    • 연구 논문
    • 보고서
    • 이메일

다수의 책 더미에서 요약 문서가 생성되는 이미지.

Python으로 배우는 Natural Language Processing (NLP)

텍스트 요약 파이پ라인

from transformers import pipeline

summarizer = pipeline(task="summarization", model="cnicu/t5-small-booksum")
text = """The Amazon rainforest, often referred to as the "lungs of the Earth," is one of the most biologically diverse regions in the world. Spanning over nine countries in South America, the majority of the forest lies in Brazil. It is home to an estimated 390 billion individual trees, divided into 16,000 different species. The rainforest plays a critical role in regulating the global climate by absorbing vast amounts of carbon dioxide and producing oxygen."""
result = summarizer(text)
print(result)
[{'summary_text': 'the Amazon rainforest is one of the most biologically diverse regions in the world. 
The majority of the forest lies in Brazil. The rainforest plays a critical role in regulating the 
global climate by absorbing vast amounts of carbon dioxide and producing oxygen.'}]
Python으로 배우는 Natural Language Processing (NLP)

텍스트 번역

  • 텍스트를 다른 언어로 변환
  • 다국어 애플리케이션에 핵심:
    • 국제 웹사이트
    • 고객 지원 도구

영어(Good morning)에서 프랑스어(Bonjour)로 번역되는 예시 이미지.

Python으로 배우는 Natural Language Processing (NLP)

텍스트 번역 파이프라인

translator = pipeline(task="translation", model="Helsinki-NLP/opus-mt-en-fr")

sentence = "The rainforest helps regulate the Earth's climate."
result = translator(sentence)
print(result)
[{'translation_text': 'La forêt tropicale aide à réguler le climat de la Terre.'}]
Python으로 배우는 Natural Language Processing (NLP)

언어 모델링

  • 프롬프트 기반 다음 단어 예측
  • 다양한 응용의 기반:
    • 자동완성
    • 이야기 생성
    • 챗봇 응답

프롬프트를 주면 모델이 텍스트를 생성하는 언어 모델링 개요 이미지.

Python으로 배우는 Natural Language Processing (NLP)

언어 모델링 파이프라인

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


prompt = "Once upon a time,"
result = generator(prompt, max_length=30, num_return_sequences=3)
print(result)
[{'generated_text': "Once upon a time, my life wasn't so good, I kept my things tidy. The 
                     more time I spend with my children the more ..."}, 
 {'generated_text': 'Once upon a time, we began a process of finding the right answers to 
                     some big questions," said Jim Pelterer, a lecturer at the 
                     University...'}, 
 {'generated_text': 'Once upon a time, a man came along and took in the city, and found out 
                     that a strange woman had just walked in and was dancing about...'}]
Python으로 배우는 Natural Language Processing (NLP)

연습해 봅시다!

Python으로 배우는 Natural Language Processing (NLP)

Preparing Video For Download...