BERT for Question Answering
On SQuAD 2.0
1
Question Answering (QA)
2
Question Answering (QA)
• Là một trong những nhiệm vụ lâu đời nhất của NLP (1961)
• Liên quan đến việc xây dựng các hệ thống tự động trả lời các câu
hỏi do con người đặt ra bằng ngôn ngữ tự nhiên.
3
Types of Questions in Modern Systems
• Câu hỏi sự thật (Factoid questions)
• Thủ đô của Việt Nam là gì?
• Khoảng cách từ mặt trăng đến trái đất bao nhiêu?
• Mèo thích bắt chuột không?
• Câu hỏi phức tạp (Complex questions)
• Trẻ em cần được chăm sóc thế nào để phát triển
toàn diện?
• Người dân Việt Nam nghĩ gì về việc đi du lịch?
4
Paradigms for QA
• IR-based approaches
• TREC; IBM Watson; Google
• Knowledge-based and Hybrid approaches
• IBM Watson; Apple Siri; Wolfram Alpha; True Knowledge Evi
5
IR-based Factoid QA
Document
DocumentDocument
Docume
ntDocume
ntDocume
ntDocume
ntDocume
nt
Question
Processing
Passage
Retrieval
Query
Formulation
Answer Type
Detection
Question
Passage
Retrieval
Document
Retrieval
Answer
Processing
Answer
passages
Indexing
Relevant
Docs
Document
DocumentDocument
6
Knowledge-based approaches (Siri)
• Xây dựng semantic representation cho việc truy vấn
• Giờ, Ngày, Vi trí, Thực thể, Số lượng…
• Ánh xạ từ ngữ nghĩa này để truy vấn dữ liệu hoặc tài
nguyên có cấu trúc
• Geospatial databases
• Ontologies (Wikipedia infoboxes, dbPedia, WordNet, Yago)
• Restaurant review sources and reservation services
• Scientific databases
7
Hybrid approaches (IBM Watson)
• Xây dựng shallow semantic representation cho việc
truy vấn
• Sử dụng các phương thức của IR để tạo ra các câu trả
lời ứng viên
• Chấm điểm mỗi câu trả lời ứng viên dựa vào các
nguồn kiến thức phong phú hơn
• Geospatial databases
• Temporal reasoning
• Taxonomical classification
8
SQuAD 2.0
9
SQuAD
• Stanford Question Answering Dataset (SQuAD)
• Là bộ gồm nhiều câu hỏi và câu trả lời dựa trên các bài viết trên
Wikipedia
• Câu trả lời cho một câu hỏi có thể là 1 đoạn văn bản, 1 khoảng văn
bản hoăc câu hỏi không trả lời được
10
SQuAD 2.0
• SQuAD2.0 Kết hợp 100,000 câu hỏi trong SQuAD1.1 và trên 50,000
câu hỏi mới, những câu hỏi không có câu trả lời.
11
12
{
"version": "v2.0",
"data": [
{
"title": "Normans",
"paragraphs": [
{
"qas": [
{
"question": "In what country is Normandy located?",
"id": "56ddde6b9a695914005b9628",
"answers": [
{
"text": "France",
"answer_start": 159
}
],
"is_impossible": false
}
],
"context": "The Normans (Norman: Nourmands; French: Normands; Latin: Normanni) were the
people who in the 10th and 11th centuries gave their name to Normandy, a region in France.
They were descended from Norse ("Norman" comes from "Norseman") raiders and pirates from
Denmark, Iceland and Norway who, under their leader Rollo, agreed to swear fealty to King
Charles III of West Francia. Through generations of assimilation and mixing with the native
Frankish and Roman-Gaulish populations, their descendants would gradually merge with the
Carolingian-based cultures of West Francia. The distinct cultural and ethnic identity of the
Normans emerged initially in the first half of the 10th century, and it continued to evolve
over the succeeding centuries."
}
]
}
]
}
JSON Structure
13
BERT: Bidirectional Encoder
Representations from
Transformers
14
BERT, OpenAI GPT, and ELMo
15
• Các model trước đây thường chỉ dùng ngữ cảnh trái (left context)
hoặc ngữ cảnh phải (right context), nhưng ngôn ngữ cần cả 2 ngữ
cảnh.
• => BERT ra đời
Model architecture
• Gồm nhiều lớp bidirectional Transformer encoder
• 2 Model cơ bản
• BERTBASE: L=12, H=768, A=12, Total Parameters=110M
• BERTLARGE: L=24, H=1024, A=16, Total Parameters=340M
• L: Số layers (Transformer blocks)
• H: Kích thước lớp ẩn
• A: Số lượng self-attention heads
16
Pre-training BERT
• Masked Language Model (MLM)
• Input:
my dog is hairy
• sẽ được chuyển thành
my dog is [MASK]
• sau đó [MASK] sẽ được thay thế bằng một từ ngẫu nhiên, ví dụ
my dog is apple
• Giữ lại câu gốc và tính độ lệch so với từ dự đoán thông qua hàm mất
mát cross entropy
17
Pre-training BERT
• Next Sentence Prediction (NSP)
Input = [CLS] the man went to [MASK] store [SEP]
he bought a gallon [MASK] milk SEP]
Label = IsNext
Input = [CLS] the man [MASK] to the store [SEP]
penguin [MASK] are flight ##less birds [SEP]
Label = NotNext
18
Fine-tuning BERT
• Câu A - B từ quá trình tiền huấn luyện
được trở thành:
• Những cặp câu trong paraphrasing task
• Những cặp giả thiết – tiền đề trong
entailment task
• Những cặp câu hỏi – đoạn văn trong
question answering task
• Một cặp degenerate text - <rỗng> trong
text classicfication hoặc sequence
tagging task
19
Input Representation
• Token Embeddings: sử dụng pretrained WordPiece embeddings
• Position Embeddings: sử dụng learned Position Embeddings
• Sử dụng [SEP] để phân tách các câu
• Sử dụng [CLS] để phân tách các lớp (gồm nhiều câu)
20
Transformer Encoders
• Transformer là một kiến trúc dựa vào
Attention trong NLP
• BERT là một bidirectional Transformer
encoder nhiều lớp
• BERT không sử dụng lớp decoder như
các kiến trúc Transformer khác.
21
Inside an Encoder Block
• Có khoảng 12-14 khối encoder liên tiếp
22
Inside an Encoder Block
• Input Embedding
• Hello, how are you?”
• → [“Hello”, “,” , “how”, “are”, “you”, “?”]
• → [34, 90, 15, 684, 55, 193]
23
Inside an Encoder Block
• Posotional Encoding
• Tạo ma trận P với:
• X = Z + P
24
Inside an Encoder Block
• Multi-Head Attention
25
Inside an Encoder Block
• Feed forward Network
• Add & Norm
26
Reesult
27
SQuAD 1.1
28
SQuAD v2.0
29
nbest_predictions.json{
"56ddde6b9a695914005b9628": [
{
"text": "mands; French: Normands; Latin: Normanni) were the
people who in the 10th and 11th centuries gave their",
"probability": 0.05308649383291742,
"start_logit": 0.36476194858551025,
"end_logit": 0.7789570689201355
},
{
"text": "based",
"probability": 0.05172724203669382,
"start_logit": 0.4540586471557617,
"end_logit": 0.6637223958969116
}
]
}
30
References
• Slide “Question Answering” of Standford university
• BERT for Question Answering on SQuAD 2.0, Yuwen Zhang, Zhaozhuo
Xu
• BERT: Pre-training of Deep Bidirectional Transformers for Language
Understanding, Google AI Language
• Attention Is All You Need, Ashish Vaswani
31

Bert for question answering on SQuAD 2.0

  • 1.
    BERT for QuestionAnswering On SQuAD 2.0 1
  • 2.
  • 3.
    Question Answering (QA) •Là một trong những nhiệm vụ lâu đời nhất của NLP (1961) • Liên quan đến việc xây dựng các hệ thống tự động trả lời các câu hỏi do con người đặt ra bằng ngôn ngữ tự nhiên. 3
  • 4.
    Types of Questionsin Modern Systems • Câu hỏi sự thật (Factoid questions) • Thủ đô của Việt Nam là gì? • Khoảng cách từ mặt trăng đến trái đất bao nhiêu? • Mèo thích bắt chuột không? • Câu hỏi phức tạp (Complex questions) • Trẻ em cần được chăm sóc thế nào để phát triển toàn diện? • Người dân Việt Nam nghĩ gì về việc đi du lịch? 4
  • 5.
    Paradigms for QA •IR-based approaches • TREC; IBM Watson; Google • Knowledge-based and Hybrid approaches • IBM Watson; Apple Siri; Wolfram Alpha; True Knowledge Evi 5
  • 6.
    IR-based Factoid QA Document DocumentDocument Docume ntDocume ntDocume ntDocume ntDocume nt Question Processing Passage Retrieval Query Formulation AnswerType Detection Question Passage Retrieval Document Retrieval Answer Processing Answer passages Indexing Relevant Docs Document DocumentDocument 6
  • 7.
    Knowledge-based approaches (Siri) •Xây dựng semantic representation cho việc truy vấn • Giờ, Ngày, Vi trí, Thực thể, Số lượng… • Ánh xạ từ ngữ nghĩa này để truy vấn dữ liệu hoặc tài nguyên có cấu trúc • Geospatial databases • Ontologies (Wikipedia infoboxes, dbPedia, WordNet, Yago) • Restaurant review sources and reservation services • Scientific databases 7
  • 8.
    Hybrid approaches (IBMWatson) • Xây dựng shallow semantic representation cho việc truy vấn • Sử dụng các phương thức của IR để tạo ra các câu trả lời ứng viên • Chấm điểm mỗi câu trả lời ứng viên dựa vào các nguồn kiến thức phong phú hơn • Geospatial databases • Temporal reasoning • Taxonomical classification 8
  • 9.
  • 10.
    SQuAD • Stanford QuestionAnswering Dataset (SQuAD) • Là bộ gồm nhiều câu hỏi và câu trả lời dựa trên các bài viết trên Wikipedia • Câu trả lời cho một câu hỏi có thể là 1 đoạn văn bản, 1 khoảng văn bản hoăc câu hỏi không trả lời được 10
  • 11.
    SQuAD 2.0 • SQuAD2.0Kết hợp 100,000 câu hỏi trong SQuAD1.1 và trên 50,000 câu hỏi mới, những câu hỏi không có câu trả lời. 11
  • 12.
  • 13.
    { "version": "v2.0", "data": [ { "title":"Normans", "paragraphs": [ { "qas": [ { "question": "In what country is Normandy located?", "id": "56ddde6b9a695914005b9628", "answers": [ { "text": "France", "answer_start": 159 } ], "is_impossible": false } ], "context": "The Normans (Norman: Nourmands; French: Normands; Latin: Normanni) were the people who in the 10th and 11th centuries gave their name to Normandy, a region in France. They were descended from Norse ("Norman" comes from "Norseman") raiders and pirates from Denmark, Iceland and Norway who, under their leader Rollo, agreed to swear fealty to King Charles III of West Francia. Through generations of assimilation and mixing with the native Frankish and Roman-Gaulish populations, their descendants would gradually merge with the Carolingian-based cultures of West Francia. The distinct cultural and ethnic identity of the Normans emerged initially in the first half of the 10th century, and it continued to evolve over the succeeding centuries." } ] } ] } JSON Structure 13
  • 14.
  • 15.
    BERT, OpenAI GPT,and ELMo 15 • Các model trước đây thường chỉ dùng ngữ cảnh trái (left context) hoặc ngữ cảnh phải (right context), nhưng ngôn ngữ cần cả 2 ngữ cảnh. • => BERT ra đời
  • 16.
    Model architecture • Gồmnhiều lớp bidirectional Transformer encoder • 2 Model cơ bản • BERTBASE: L=12, H=768, A=12, Total Parameters=110M • BERTLARGE: L=24, H=1024, A=16, Total Parameters=340M • L: Số layers (Transformer blocks) • H: Kích thước lớp ẩn • A: Số lượng self-attention heads 16
  • 17.
    Pre-training BERT • MaskedLanguage Model (MLM) • Input: my dog is hairy • sẽ được chuyển thành my dog is [MASK] • sau đó [MASK] sẽ được thay thế bằng một từ ngẫu nhiên, ví dụ my dog is apple • Giữ lại câu gốc và tính độ lệch so với từ dự đoán thông qua hàm mất mát cross entropy 17
  • 18.
    Pre-training BERT • NextSentence Prediction (NSP) Input = [CLS] the man went to [MASK] store [SEP] he bought a gallon [MASK] milk SEP] Label = IsNext Input = [CLS] the man [MASK] to the store [SEP] penguin [MASK] are flight ##less birds [SEP] Label = NotNext 18
  • 19.
    Fine-tuning BERT • CâuA - B từ quá trình tiền huấn luyện được trở thành: • Những cặp câu trong paraphrasing task • Những cặp giả thiết – tiền đề trong entailment task • Những cặp câu hỏi – đoạn văn trong question answering task • Một cặp degenerate text - <rỗng> trong text classicfication hoặc sequence tagging task 19
  • 20.
    Input Representation • TokenEmbeddings: sử dụng pretrained WordPiece embeddings • Position Embeddings: sử dụng learned Position Embeddings • Sử dụng [SEP] để phân tách các câu • Sử dụng [CLS] để phân tách các lớp (gồm nhiều câu) 20
  • 21.
    Transformer Encoders • Transformerlà một kiến trúc dựa vào Attention trong NLP • BERT là một bidirectional Transformer encoder nhiều lớp • BERT không sử dụng lớp decoder như các kiến trúc Transformer khác. 21
  • 22.
    Inside an EncoderBlock • Có khoảng 12-14 khối encoder liên tiếp 22
  • 23.
    Inside an EncoderBlock • Input Embedding • Hello, how are you?” • → [“Hello”, “,” , “how”, “are”, “you”, “?”] • → [34, 90, 15, 684, 55, 193] 23
  • 24.
    Inside an EncoderBlock • Posotional Encoding • Tạo ma trận P với: • X = Z + P 24
  • 25.
    Inside an EncoderBlock • Multi-Head Attention 25
  • 26.
    Inside an EncoderBlock • Feed forward Network • Add & Norm 26
  • 27.
  • 28.
  • 29.
  • 30.
    nbest_predictions.json{ "56ddde6b9a695914005b9628": [ { "text": "mands;French: Normands; Latin: Normanni) were the people who in the 10th and 11th centuries gave their", "probability": 0.05308649383291742, "start_logit": 0.36476194858551025, "end_logit": 0.7789570689201355 }, { "text": "based", "probability": 0.05172724203669382, "start_logit": 0.4540586471557617, "end_logit": 0.6637223958969116 } ] } 30
  • 31.
    References • Slide “QuestionAnswering” of Standford university • BERT for Question Answering on SQuAD 2.0, Yuwen Zhang, Zhaozhuo Xu • BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding, Google AI Language • Attention Is All You Need, Ashish Vaswani 31

Editor's Notes

  • #5 Các hệ thống hiện tại chủ yếu giải quyết Factoid questions
  • #6 IR: Information Retrieval: Truy xuất thông itin
  • #7 QUESTION PROCESSING: Xác định loại câu hỏi, loại câu trả lời, chủ đề, mối quan hệ Công thức hóa truy vấn (Formulate queries) và gởi đến search engine PASSAGE RETRIEVAL Retrieve ranked documents Break into suitable passages and rerank ANSWER PROCESSING Xuất ra và xếp hạng các câu trả lời ứng viên
  • #8 Semantic representation is an abstract (formal) language in which meanings can be represented.
  • #16 BERT uses a bidirectional Transformer. OpenAI GPT uses a left-to-right Transformer. ELMo uses the concatenation of independently trained left-to-right and right-toleft LSTMs to generate features for downstream tasks. Among the three, only BERT representations are jointly conditioned on both left and right context in all layers. In addition to the architecture differences, BERT and OpenAI GPT are fine-tuning approaches, while ELMo is a feature-based approach Downstream tasks is what the field calls those supervised-learning tasks that utilize a pre-trained model or component
  • #21 Token Embeddings: sử dụng pretrained WordPiece embeddings * bài báo: Google’s Neural Machine Translation System: Bridging the Gap between Human and Machine Translation Position Embeddings: sử dụng learned Position Embeddings bài báo Convolutional Sequence to Sequence Learning