Задачи генерации последовательностей

Обработка естественного языка (NLP) на Python

Fouad Trad

Machine Learning Engineer

Генерация последовательностей

  • Создаёт новый текст на основе входных данных
  • Включает такие задачи, как:
    • Суммаризация текста
    • Перевод текста
    • Языковое моделирование

GIF с карандашом, пишущим предложения на бумаге.

Обработка естественного языка (NLP) на Python

Суммаризация текста

  • Сжимает длинные документы до краткого изложения ключевых моментов
  • Применяется при работе с:
    • Объёмными новостными статьями
    • Научными статьями
    • Отчётами
    • Электронными письмами

Изображение стопки книг и сгенерированного из них краткого резюме.

Обработка естественного языка (NLP) на Python

Конвейер суммаризации текста

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.'}]
Обработка естественного языка (NLP) на Python

Перевод текста

  • Переводит текст с одного языка на другой
  • Необходим в многоязычных приложениях:
    • Международные сайты
    • Инструменты поддержки клиентов

Изображение перевода текста с английского (Good morning) на французский (Bonjour).

Обработка естественного языка (NLP) на Python

Конвейер перевода текста

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.'}]
Обработка естественного языка (NLP) на Python

Языковое моделирование

  • Предсказывает следующие слова на основе заданного запроса
  • Лежит в основе многих приложений:
    • Автодополнение
    • Генерация историй
    • Ответы чат-бота

Изображение, показывающее принцип языкового моделирования: запрос подаётся модели, которая генерирует текст.

Обработка естественного языка (NLP) на Python

Конвейер языкового моделирования

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...'}]
Обработка естественного языка (NLP) на Python

Давайте потренируемся!

Обработка естественного языка (NLP) на Python

Preparing Video For Download...