--- license: mit language: - vi metrics: - exact_match - f1 library_name: transformers pipeline_tag: question-answering --- # Model Card for Model ID This modelcard aims to be a base template for new models. It has been generated using [this raw template](https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md?plain=1). ## Task Question-answer model in Vietnamese language ## Model Details ### Model Description - **Developed by:** Tô Hoàng Minh Tiến - **Finetuned from model :** xml-roberta-base ## How to Get Started with the Model Use the code below to get started with the model. ```python # Load model directly from transformers import AutoTokenizer, TFAutoModelForQuestionAnswering tokenizer = AutoTokenizer.from_pretrained("Tien-THM/QAVi") model = TFAutoModelForQuestionAnswering.from_pretrained("Tien-THM/QAVi") import numpy as np def Inference(context, question): encoding = tokenizer(context, question, return_tensors='tf') start_pos = model(encoding).start_logits end_pos = model(encoding).end_logits s = np.argmax(start_pos[0]) e = np.argmax(end_pos[0]) print(tokenizer.decode(encoding['input_ids'][0][s:e+1])) question = 'Elon Musk là người nước nào?' context = 'Elon Reeve Musk FRS (sinh ngày 28 tháng 6 năm 1971), là một kỹ sư, nhà tài phiệt, nhà phát minh, doanh nhân công nghệ và nhà từ thiện người Mỹ gốc Nam Phi.' Inference(context, question) # Answer: người Mỹ gốc Nam Phi ``` ```python context_1 = """ Elon Reeve Musk FRS (sinh ngày 28 tháng 6 năm 1971), là một kỹ sư, nhà tài phiệt, nhà phát minh, doanh nhân công nghệ và nhà từ thiện người Mỹ gốc Nam Phi. """ question_1 = 'Elon Musk là người nước nào?' question_2 = 'Elon Musk sinh ngày bao nhiêu?' Inference(context_1, question_1) Inference(context_1, question_2) ``` ```python context_2 = """ Elon Musk cùng với em trai, Kimbal, đồng sáng lập ra Zip2, một công ty phần mềm web và được hãng Compaq mua lại với giá 340 triệu USD vào năm 1999. """ question_3 = 'Elon có em trai?' question_4 = 'Hãng Compaq mua lại Zip2 với giá bao nhiêu?' Inference(context_2, question_3) Inference(context_2, question_4) ``` ```python context_3 = """John vừa mới trở về từ chuyến công tác ở Paris. Anh ấy đã tham gia một hội thảo quốc tế về nghệ thuật số. Trong hội thảo, John đã gặp nhiều nghệ sĩ và chia sẻ kinh nghiệm của mình trong việc sáng tạo nghệ thuật số """ question_5 = 'John đã tham gia sự kiện gì ở Paris?' question_6 = 'John đã gặp được ai?' Inference(context_3, question_5) Inference(context_3, question_6) ``` ## Training Details ### Training Data Using 2 datasets: * Zalo Challenge 2022 * XSQUAD Vi ### Training Procedure #### Optimization: * Adam #### Loss function * Cross entropy #### Training Hyperparameters * Learning rate: 2e-5 * Batch size: 16 * Epoch: 4 #### Training Loss | Epoch | Train loss | Validation loss | Exact Match | |----------|----------|----------|----------| | #1 | 3.0424 | 1.3987 | 0.68 | | #2 | 0.9563 | 1.2139 | 0.74 | | #3 | 0.3920 | 1.4264 | 0.75 | | #4 | 0.2175 | 1.4742 | 0.74 | I restored the check point in the 2nd epoch ## Evaluation ### Testing Data, Factors & Metrics #### Metrics * Exact Match: 0.74 * F1: 0.84