Nhiệm vụ tạo chuỗi

Natural Language Processing (NLP) bằng Python

Fouad Trad

Machine Learning Engineer

Tạo chuỗi

  • Tạo văn bản mới từ đầu vào đã cho
  • Gồm các tác vụ:
    • Tóm tắt văn bản
    • Dịch văn bản
    • Mô hình ngôn ngữ

GIF bút chì viết câu trên giấy.

Natural Language Processing (NLP) bằng Python

Tóm tắt văn bản

  • Cô đọng tài liệu dài thành bản ngắn nêu bật ý chính
  • Hữu ích khi xử lý:
    • Bài báo dài
    • Bài nghiên cứu
    • Báo cáo
    • Email

Hình ảnh chồng sách và một bản tóm tắt tạo ra từ đó.

Natural Language Processing (NLP) bằng Python

Pipeline tóm tắt văn bản

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.'}]
Natural Language Processing (NLP) bằng Python

Dịch văn bản

  • Chuyển văn bản từ ngôn ngữ này sang ngôn ngữ khác
  • Thiết yếu cho ứng dụng đa ngôn ngữ:
    • Website quốc tế
    • Công cụ hỗ trợ khách hàng

Hình minh họa văn bản được dịch từ tiếng Anh (Good morning) sang tiếng Pháp (Bonjour).

Natural Language Processing (NLP) bằng Python

Pipeline dịch văn bản

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.'}]
Natural Language Processing (NLP) bằng Python

Mô hình ngôn ngữ

  • Dự đoán từ tiếp theo dựa trên một prompt đã cho
  • Nền tảng cho nhiều ứng dụng:
    • Tự động hoàn thành
    • Tạo truyện
    • Phản hồi chatbot

Hình minh họa mô hình ngôn ngữ: nhập một prompt và máy tạo văn bản.

Natural Language Processing (NLP) bằng Python

Pipeline mô hình ngôn ngữ

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...'}]
Natural Language Processing (NLP) bằng Python

Ayo berlatih!

Natural Language Processing (NLP) bằng Python

Preparing Video For Download...