PhucDanh commited on
Commit
cdfcbe4
·
verified ·
1 Parent(s): b355d0d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +152 -1
README.md CHANGED
@@ -11,4 +11,155 @@ metrics:
11
  - exact_match
12
  - f1
13
  pipeline_tag: question-answering
14
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  - exact_match
12
  - f1
13
  pipeline_tag: question-answering
14
+ ---
15
+ # Model Card for ViT5-base fine-tuned model for question answering task
16
+
17
+ ## Overview
18
+ ViT5 is a pretrained text-to-text transformer model designed specifically for Vietnamese language generation tasks. It is based on the T5 (Text-to-Text Transfer Transformer) architecture developed by Google, which has been adapted and fine-tuned for the Vietnamese language. ViT5 is capable of handling various natural language processing (NLP) tasks such as translation, summarization, question answering, and text generation, all within the Vietnamese linguistic context.
19
+
20
+ ## Question answering view
21
+ 1. Task Formulation
22
+ In the text-to-text framework, the question answering task is formulated as "Answer the question: [question] Context: [context]".
23
+ The input consists of a question and a related context (a passage or document) that contains the information needed to answer the question.
24
+ 2. Input Processing
25
+ Tokenization: The combined question and context are tokenized into subword units using ViT5's tokenizer, which is pretrained for Vietnamese.
26
+ Task Specification: The input is prefixed with a task-specific instruction to help the model understand the nature of the task.
27
+ 3. Encoding
28
+ Embedding: The tokenized input is converted into embeddings.
29
+ Self-Attention: The encoder applies self-attention mechanisms to generate context-aware representations of the input text, integrating information from both the question and the context.
30
+ 4. Decoding
31
+ Conditional Generation: The decoder generates the output text (the answer) based on the encoded representations. The cross-attention mechanism helps the decoder focus on relevant parts of the context while generating the answer.
32
+ Output Tokenization: The generated tokens are converted back into human-readable text (the answer).
33
+ 5. Post-Processing
34
+ Detokenization: The output tokens are detokenized to form a coherent and fluent answer.
35
+ Answer Extraction: The model's output is refined to ensure that the generated text is a precise and relevant answer to the input question.
36
+
37
+ # Dataset
38
+ The Vietnamese QA dataset, created by Nguyen et al. (2020), is known as UIT-ViQuAD and was introduced in their research paper. This dataset has also been used in a shared task.
39
+ ### Original Version:
40
+ - Comprises over 23,000 question-answer (QA) pairs.
41
+ - Sourced from 174 Vietnamese Wikipedia articles.
42
+ ### UIT-ViQuAD 2.0:
43
+ - Adds over 12,000 unanswerable questions to the same passages.
44
+ - Includes new fields: is_impossible and plausible_answer.
45
+ - These additions and modifications ensure that the dataset is more comprehensive by including both answerable and unanswerable questions.
46
+ - The dataset has been refined to eliminate a few duplicated questions and answers.
47
+ ### Fields in UIT-ViQuAD 2.0:
48
+ - Context: The passage from which questions are derived.
49
+ - Question: The question to be answered based on the context.
50
+ - Answer: The correct answer extracted from the context for answerable questions.
51
+ - is_impossible: A boolean indicating if the question is unanswerable (True) or answerable (False).
52
+ - plausible_answer: For unanswerable questions, this provides a seemingly correct but actually incorrect answer extracted from the context.
53
+
54
+ # The term for hyperparameters used in the fine-tuning process
55
+ - epochs = 4
56
+ - batch_size = 16
57
+ - learning rate = 2e-5
58
+ - evaluation strategy = "steps"
59
+ - save_total_limit = 1
60
+ - save_steps = 2000
61
+ - eval_steps = 2000
62
+ - gradient_accumulation_steps = 2
63
+ - eval_accumulation_steps = 2
64
+ - load_best_model_at_end = True
65
+
66
+ # Best result
67
+ - epoch = 3250207813798838
68
+ - grad_norm = 136582374572754
69
+ - learning_rate = 3.3610648918469217e-06
70
+ - loss = 0.9397
71
+ - step = 2000
72
+ - eval_loss = 0.7907648682594299
73
+
74
+ # Inference
75
+ ## Using a pipeline as a high-level helper
76
+ ```py
77
+ from transformers import pipeline
78
+
79
+ context="""
80
+ Trường Đại học Công nghệ Thông tin (ĐH CNTT), Đại học Quốc gia Thành phố Hồ Chí Minh (ĐHQG-HCM) là trường đại học công lập đào tạo về công nghệ thông tin và truyền thông (CNTT&TT) được thành lập theo quyết định số 134/2006/QĐ-TTg ngày 08/06/2006 của Thủ tướng Chính phủ. Là trường thành viên của ĐHQG-HCM, trường ĐH CNTT có nhiệm vụ đào tạo nguồn nhân lực công nghệ thông tin chất lượng cao, góp phần tích cực vào sự phát triển của nền công nghiệp công nghệ thông tin Việt Nam, đồng thời tiến hành nghiên cứu khoa học và chuyển giao công nghệ thông tin tiên tiến, đặc biệt là hướng vào các ứng dụng nhằm góp phần đẩy mạnh sự nghiệp công nghiệp hóa, hiện đại hóa đất nước.
81
+ Sau hơn 10 năm xây dựng và phát triển, hiện trường ĐH CNTT sở hữu cơ sở vật chất gồm khu học tập, nghiên cứu và làm việc được đầu tư xây dựng khang trang, hiện đại với tổng diện tích trên 14 hecta trong khuôn viên khu đô thị ĐHQG-HCM.
82
+ """
83
+ question="""
84
+ Trường UIT mang trong mình nhiệm vụ gì?
85
+ """
86
+
87
+ pipe = pipeline("question-answering", model="PhucDanh/Bartpho-fine-tuning-model-for-question-answering")
88
+ pipe(question=question, context=context)
89
+ ```
90
+
91
+ ## Load model directly
92
+ ```py
93
+ from transformers import AutoTokenizer
94
+ from transformers import AutoModelForQuestionAnswering
95
+ import torch
96
+
97
+ context="""
98
+ Trường Đại học Công nghệ Thông tin (ĐH CNTT), Đại học Quốc gia Thành phố Hồ Chí Minh (ĐHQG-HCM) là trường đại học công lập đào tạo về công nghệ thông tin và truyền thông (CNTT&TT) được thành lập theo quyết định số 134/2006/QĐ-TTg ngày 08/06/2006 của Thủ tướng Chính phủ. Là trường thành viên của ĐHQG-HCM, trường ĐH CNTT có nhiệm vụ đào tạo nguồn nhân lực công nghệ thông tin chất lượng cao, góp phần tích cực vào sự phát triển của nền công nghiệp công nghệ thông tin Việt Nam, đồng thời tiến hành nghiên cứu khoa học và chuyển giao công nghệ thông tin tiên tiến, đặc biệt là hướng vào các ứng dụng nhằm góp phần đẩy mạnh sự nghiệp công nghiệp hóa, hiện đại hóa đất nước.
99
+ Sau hơn 10 năm xây dựng và phát triển, hiện trường ĐH CNTT sở hữu cơ sở vật chất gồm khu học tập, nghiên cứu và làm việc được đầu tư xây dựng khang trang, hiện đại với tổng diện tích trên 14 hecta trong khuôn viên khu đô thị ĐHQG-HCM.
100
+ """
101
+ question="""
102
+ Trường UIT mang trong mình nhiệm vụ gì?
103
+ """
104
+
105
+ tokenizer = AutoTokenizer.from_pretrained("PhucDanh/Bartpho-fine-tuning-model-for-question-answering")
106
+ tokenizer.model_input_names.remove("token_type_ids")
107
+
108
+ inputs = tokenizer(question, context, return_tensors="pt")
109
+
110
+ model = AutoModelForQuestionAnswering.from_pretrained("PhucDanh/Bartpho-fine-tuning-model-for-question-answering")
111
+ with torch.no_grad():
112
+ outputs = model(**inputs)
113
+
114
+ answer_start_index = outputs.start_logits.argmax()
115
+ answer_end_index = outputs.end_logits.argmax()
116
+
117
+ predict_answer_tokens = inputs.input_ids[0, answer_start_index : answer_end_index + 1]
118
+ print(tokenizer.decode(predict_answer_tokens))
119
+ ```
120
+
121
+ # Inference API
122
+ Contact for API token authentication
123
+ ```py
124
+ import requests
125
+
126
+ API_URL = "https://api-inference.huggingface.co/models/PhucDanh/Bartpho-fine-tuning-model-for-question-answering"
127
+ headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
128
+
129
+ def query(payload):
130
+ response = requests.post(API_URL, headers=headers, json=payload)
131
+ return response.json()
132
+
133
+ output = query({
134
+ "inputs": {
135
+ "question": "What is my name?",
136
+ "context": "My name is Clara and I live in Berkeley."
137
+ },
138
+ })
139
+ ```
140
+
141
+ # Reference
142
+ ## Model:
143
+ ```
144
+ @article{tran2021bartpho,
145
+ title={BartPho: pre-trained sequence-to-sequence models for Vietnamese},
146
+ author={Tran, Nguyen Luong and Le, Duong Minh and Nguyen, Dat Quoc},
147
+ journal={arXiv preprint arXiv:2109.09701},
148
+ year={2021}
149
+ }
150
+ ```
151
+ ## Dataset:
152
+ ```
153
+ @article{Nguyen_2022,
154
+ title={VLSP 2021-ViMRC Challenge: Vietnamese Machine Reading Comprehension},
155
+ volume={38},
156
+ ISSN={2615-9260},
157
+ url={http://dx.doi.org/10.25073/2588-1086/vnucsce.340},
158
+ DOI={10.25073/2588-1086/vnucsce.340},
159
+ number={2},
160
+ journal={VNU Journal of Science: Computer Science and Communication Engineering},
161
+ publisher={Vietnam National University Journal of Science},
162
+ author={Nguyen, Kiet and Tran, Son Quoc and Nguyen, Luan Thanh and Huynh, Tin Van and Luu, Son Thanh and Nguyen, Ngan Luu-Thuy},
163
+ year={2022},
164
+ month=dec}
165
+ ```