File size: 3,704 Bytes
15a21cc
 
7c1d87e
 
 
 
 
 
 
15a21cc
7c1d87e
 
 
 
 
0733fb9
 
7c1d87e
 
 
 
 
 
 
 
 
ccbe315
 
7c1d87e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
afa2fdf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c1d87e
 
 
 
8e99096
 
 
7c1d87e
 
 
ccbe315
 
 
 
 
7c1d87e
 
 
 
 
 
 
 
 
 
 
 
 
ccbe315
7c1d87e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
---
license: mit
language:
- vi
metrics:
- exact_match
- f1
library_name: transformers
pipeline_tag: question-answering
---
# Model Card for Model ID

<!-- Provide a quick summary of what the model is/does. -->

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

<!-- Provide a longer summary of what this model is. -->



- **Developed by:** Tô Hoàng Minh Tiến
- **Finetuned from model :** xml-roberta-base


<!-- Provide the basic links for the model. -->


## 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
<!-- This section describes the evaluation protocols and provides the results. -->

### Testing Data, Factors & Metrics

#### Metrics

* Exact Match: 0.74
* F1: 0.84