--- library_name: transformers tags: - code license: mit datasets: - taidng/UIT-ViQuAD2.0 language: - vi metrics: - exact_match - f1 pipeline_tag: question-answering --- # Model Card for ViT5-base fine-tuned model for question answering task ## Overview 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. ## Question answering view 1. **Task Formulation**
In the text-to-text framework, the question answering task is formulated as "Answer the question: [question] Context: [context]". The input consists of a question and a related context (a passage or document) that contains the information needed to answer the question. 3. **Input Processing**
Tokenization: The combined question and context are tokenized into subword units using ViT5's tokenizer, which is pretrained for Vietnamese. Task Specification: The input is prefixed with a task-specific instruction to help the model understand the nature of the task. 4. **Encoding**
Embedding: The tokenized input is converted into embeddings. 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. 5. **Decoding**
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. Output Tokenization: The generated tokens are converted back into human-readable text (the answer). 6. **Post-Processing**
Detokenization: The output tokens are detokenized to form a coherent and fluent answer. Answer Extraction: The model's output is refined to ensure that the generated text is a precise and relevant answer to the input question. # Dataset 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. ### Original Version: - Comprises over 23,000 question-answer (QA) pairs. - Sourced from 174 Vietnamese Wikipedia articles. ### UIT-ViQuAD 2.0: - Adds over 12,000 unanswerable questions to the same passages. - Includes new fields: is_impossible and plausible_answer. - These additions and modifications ensure that the dataset is more comprehensive by including both answerable and unanswerable questions. - The dataset has been refined to eliminate a few duplicated questions and answers. ### Fields in UIT-ViQuAD 2.0: - Context: The passage from which questions are derived. - Question: The question to be answered based on the context. - Answer: The correct answer extracted from the context for answerable questions. - is_impossible: A boolean indicating if the question is unanswerable (True) or answerable (False). - plausible_answer: For unanswerable questions, this provides a seemingly correct but actually incorrect answer extracted from the context. # The term for hyperparameters used in the fine-tuning process - epochs: 4 - batch_size: 16 - learning rate: 2e-5 - evaluation strategy: "steps" - save_total_limit: 1 - save_steps: 2000 - eval_steps: 2000 - gradient_accumulation_steps: 2 - eval_accumulation_steps: 2 - load_best_model_at_end: True # Best model saved while tuning - epoch: 3.3264033264033266 - learning_rate: 3.3679833679833685e-06 - train_loss: 0.4473 - eval_loss: 1.2475123405456543 # Evaluation - validation: - F1-score: 75.4081 - Exact-match: 58.6788 - test: - F1-score: 78.646 - Exact-match: 59.147 # Inference ## Using a pipeline as a high-level helper ```py from transformers import pipeline context=""" 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. 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. """ question=""" Trường UIT mang trong mình nhiệm vụ gì? """ pipe = pipeline("question-answering", model="PhucDanh/vit5-fine-tuning-for-question-answering") pipe(question=question, context=context) ``` ## Load model directly ```py from transformers import AutoTokenizer from transformers import AutoModelForQuestionAnswering import torch context=""" 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. 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. """ question=""" Trường UIT mang trong mình nhiệm vụ gì? """ tokenizer = AutoTokenizer.from_pretrained("PhucDanh/vit5-fine-tuning-for-question-answering") try: tokenizer.model_input_names.remove("token_type_ids") except: print("already removed!!!") inputs = tokenizer(question, context, return_tensors="pt") model = AutoModelForQuestionAnswering.from_pretrained("PhucDanh/vit5-fine-tuning-for-question-answering") with torch.no_grad(): outputs = model(**inputs) answer_start_index = outputs.start_logits.argmax() answer_end_index = outputs.end_logits.argmax() predict_answer_tokens = inputs.input_ids[0, answer_start_index : answer_end_index + 1] print(tokenizer.decode(predict_answer_tokens)) ``` # Inference API Contact for API token authentication ```py import requests API_URL = "https://api-inference.huggingface.co/models/PhucDanh/vit5-fine-tuning-for-question-answering" headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"} def query(payload): response = requests.post(API_URL, headers=headers, json=payload) return response.json() output = query({ "inputs": { "question": "What is my name?", "context": "My name is Clara and I live in Berkeley." }, }) ``` # Reference ## Model: ``` @article{phan2022vit5, title={Vit5: Pretrained text-to-text transformer for vietnamese language generation}, author={Phan, Long and Tran, Hieu and Nguyen, Hieu and Trinh, Trieu H}, journal={arXiv preprint arXiv:2205.06457}, year={2022} } @article{raffel2020exploring, title={Exploring the limits of transfer learning with a unified text-to-text transformer}, author={Raffel, Colin and Shazeer, Noam and Roberts, Adam and Lee, Katherine and Narang, Sharan and Matena, Michael and Zhou, Yanqi and Li, Wei and Liu, Peter J}, journal={Journal of machine learning research}, volume={21}, number={140}, pages={1--67}, year={2020} } ``` ## Dataset: ``` @article{Nguyen_2022, title={VLSP 2021-ViMRC Challenge: Vietnamese Machine Reading Comprehension}, volume={38}, ISSN={2615-9260}, url={http://dx.doi.org/10.25073/2588-1086/vnucsce.340}, DOI={10.25073/2588-1086/vnucsce.340}, number={2}, journal={VNU Journal of Science: Computer Science and Communication Engineering}, publisher={Vietnam National University Journal of Science}, author={Nguyen, Kiet and Tran, Son Quoc and Nguyen, Luan Thanh and Huynh, Tin Van and Luu, Son Thanh and Nguyen, Ngan Luu-Thuy}, year={2022}, month=dec} ```