File size: 5,949 Bytes
1fde615
 
 
ffb1942
 
 
 
 
 
 
 
 
1fde615
 
ffb1942
1fde615
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ffb1942
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
---
license: mit
task_categories:
- question-answering
- text-generation
language:
- vi
tags:
- vietnamese
- t5
- nlp
- question-generation
pretty_name: HVU Question Generation Dataset
size_categories:
- 10K<n<100K
---

# HVU_GQ

**HHVU_GQ** is a project dedicated to sharing datasets and tools for **Question Generation Processing (NLP)**, developed and maintained by the research team at **Hung Vuong University (HVU), Phu Tho, Vietnam**.  
This project is supported by **Hung Vuong University, Phu Tho, Vietnam**, with the aim of advancing research and applications in low-resource language processing, particularly for the Vietnamese language.

---

## 📚 Overview

This repository enables you to:
1. Fine-tune the [VietAI/vit5-base](https://huggingface.co/datasets/DANGDOCAO/GeneratingQuestions) model on your own QA dataset.
2. Generate multiple, diverse questions given a user-provided text passage (context).

---

## 📁 Dataset Format

Your dataset must follow the **SQuAD v2.0** JSON structure:

```json
{
  "version": "v2.0",
  "data": [
    {
      "title": "Đồ uống nào của Việt Nam từng lọt top ngon nhất thế giới?",
      "paragraphs": [
        {
          "qas": [
            {
              "id": "q1_1",
              "question": "Đồ uống nào của Việt Nam từng lọt top ngon nhất thế giới?",
              "answers": [
                {
                  "text": "Theo bản đánh giá tháng 2/2023 của Taste Atlas...",
                  "answer_start": "Theo bản đánh giá tháng 2/2023 của Taste Atlas..."
                }
              ],
              "is_impossible": false
            }
          ]
        }
      ]
    }
  ]
}
```

**Required fields:**
- `title` → used as context
- `question` → target question
- `answers[0].text` → seed answer for training
- `is_impossible` → filter for valid QAs

**File name:** `30ktrain.json` (UTF-8)

---

## 📁 Datasets

This repository provides datasets for **training** and **evaluating** Vietnamese question generation models.

### 🔹 `DataTotalQCAtriples30k/`
- **`30ktrain.json`** → 30,000 QCA triples for training.

### 🔹 `Datatest1k/`
- **`testorgin1k.json`** → 1,000 examples for manual & automatic evaluation.

### 🔹 `Datatrain29k/`
- **`29kcorpustag.json`** → 29,000 preprocessed QCA triples.

> All files are UTF-8 encoded and ready for direct use in NLP pipelines.

---

## 📊 Evaluation Results

We performed **manual evaluation on 500 samples** and **automatic evaluation on 1,000 samples**.

| Evaluation Type  | Precision | Recall | F1-Score |
|------------------|-----------|--------|----------|
| Automatic (1000) | 0.85      | 0.83   | 0.84     |
| Manual (500)     | 0.88      | 0.86   | 0.87     |

---

## 🔧 Installation

Create a virtual environment and install dependencies:

### Windows (PowerShell)
```powershell
python -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
pip install torch transformers datasets scikit-learn
```

### Linux / macOS
```bash
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install torch transformers datasets scikit-learn
```

---

## 🚀 Training (Fine-tuning)

Make sure `30ktrain.json` is in the same folder as `fine_tune_qg.py`.

Run:
```bash
python fine_tune_qg.py
```

**What happens:**
- Loads `30ktrain.json`
- Splits into 80% train / 20% validation
- Tokenizes using `T5Tokenizer`
- Fine-tunes `VietAI/vit5-base` for 3 epochs
- Saves model + tokenizer to `t5-viet-qg-finetuned/`

**Key training parameters** (edit in `fine_tune_qg.py` if needed):
- `per_device_train_batch_size`: 1
- `learning_rate`: 2e-4
- `num_train_epochs`: 3
- `max_input_length`: 512
- `max_target_length`: 64

---

## 💡 Generating Questions

Once training is done, use `generate_question.py` to generate new questions.

Ensure:
- `MODEL_DIR``t5-viet-qg-finetuned/`
- `DATA_PATH``30ktrain.json`

Run:
```bash
python generate_question.py
```

Steps:
1. Enter a context passage (Vietnamese)
2. Enter number of questions (default 20, max 200)
3. Script will:
   - Find best match in dataset by title similarity
   - Use matched answer + your context
   - Generate multiple unique questions with top-k & top-p sampling
4. Output lists generated questions.

---

## ⚙️ Generation Settings

In `generate_question.py`, tweak:
- `top_k` (default 60)
- `top_p` (default 0.95)
- `temperature` (default 0.9)
- `no_repeat_ngram_size` (default 3)
- `repetition_penalty` (default 1.12)

---

## 📂 Project Structure

```
.
├── fine_tune_qg.py
├── generate_question.py
├── 30ktrain.json
├── t5-viet-qg-finetuned/
├── README.md
└── LICENSE
```

---

## 🔍 Example Usage

**Training**
```bash
python fine_tune_qg.py
```

**Generating**
```bash
python generate_question.py
```

Example:
```
Nhập đoạn văn bản:
 Cà phê sữa đá là đồ uống nổi tiếng ở Việt Nam.

Nhập vào số lượng câu hỏi bạn cần: 5

✅ Các câu hỏi mới được sinh ra:
1. Loại cà phê nào nổi tiếng ở Việt Nam?
2. Tại sao cà phê sữa đá được yêu thích?
3. Cà phê sữa đá gồm những nguyên liệu gì?
4. Nguồn gốc của cà phê sữa đá là từ đâu?
5. Cà phê sữa đá Việt Nam được pha chế như thế nào?
```

---

## 🤝 Contribution

You’re welcome to:
- Open issues
- Submit pull requests
- Suggest new datasets

---

## 📄 License

Licensed under the MIT License – see the `LICENSE` file for details.

---

## 📬 Contact

- **Ha Nguyen-Tien** (Corresponding author)  
  Email: nguyentienha@hvu.edu.vn  

- **Phuc Le-Hong**  
  Email: Lehongphuc20021408@gmail.com

- **DANG DO CAO**  
  Email: docaodang532001@gmail.com

---

*This repository is part of an effort to advance Vietnamese NLP by making question generation more accessible for researchers and developers.*