rain1024 commited on
Commit
c5ce298
·
unverified ·
1 Parent(s): d734595

Add technical report

Browse files
Files changed (1) hide show
  1. TECHNICAL_REPORT.md +419 -0
TECHNICAL_REPORT.md ADDED
@@ -0,0 +1,419 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Technical Report: Vietnamese POS Tagger (TRE-1)
2
+
3
+ ## Executive Summary
4
+
5
+ This report documents the development, training, evaluation, and deployment of a Vietnamese Part-of-Speech (POS) tagger using Conditional Random Fields (CRF). The model achieves **95.57% accuracy** on the UUD-v0.1 dataset and is deployed on Hugging Face at [undertheseanlp/tre-1](https://huggingface.co/undertheseanlp/tre-1).
6
+
7
+ ---
8
+
9
+ ## 1. Introduction
10
+
11
+ ### 1.1 Problem Statement
12
+
13
+ Part-of-Speech tagging is a fundamental NLP task that assigns grammatical categories (noun, verb, adjective, etc.) to each word in a sentence. For Vietnamese, this task presents unique challenges:
14
+
15
+ - **Analytic language**: Vietnamese lacks inflectional morphology
16
+ - **Word segmentation**: Compound words and multi-syllable words require proper tokenization
17
+ - **Limited resources**: Fewer annotated datasets compared to English
18
+
19
+ ### 1.2 Objectives
20
+
21
+ 1. Train a high-accuracy POS tagger for Vietnamese
22
+ 2. Use underthesea-compatible feature templates for integration
23
+ 3. Deploy the model on Hugging Face for public access
24
+ 4. Provide comprehensive evaluation and documentation
25
+
26
+ ---
27
+
28
+ ## 2. Dataset
29
+
30
+ ### 2.1 Data Source
31
+
32
+ | Property | Value |
33
+ |----------|-------|
34
+ | **Name** | UUD-v0.1 (Vietnamese Universal Dependencies) |
35
+ | **Source** | [undertheseanlp/UDD-v0.1](https://huggingface.co/datasets/undertheseanlp/UDD-v0.1) |
36
+ | **Format** | CoNLL-U |
37
+ | **Domain** | Vietnamese legal documents |
38
+ | **License** | Open source |
39
+
40
+ ### 2.2 Dataset Statistics
41
+
42
+ | Split | Sentences | Tokens |
43
+ |-------|-----------|--------|
44
+ | Total | 3,000 | 64,814 |
45
+ | Train (80%) | 2,400 | ~51,851 |
46
+ | Test (20%) | 600 | ~12,963 |
47
+
48
+ ### 2.3 Tag Distribution
49
+
50
+ | Tag | Description | Count | Percentage |
51
+ |-----|-------------|-------|------------|
52
+ | NOUN | Noun | 4,245 | 32.8% |
53
+ | VERB | Verb | 3,070 | 23.7% |
54
+ | PUNCT | Punctuation | 1,254 | 9.7% |
55
+ | ADP | Adposition | 1,226 | 9.5% |
56
+ | CCONJ | Coordinating conjunction | 601 | 4.6% |
57
+ | AUX | Auxiliary | 588 | 4.5% |
58
+ | ADV | Adverb | 501 | 3.9% |
59
+ | ADJ | Adjective | 450 | 3.5% |
60
+ | NUM | Numeral | 273 | 2.1% |
61
+ | DET | Determiner | 259 | 2.0% |
62
+ | PRON | Pronoun | 210 | 1.6% |
63
+ | PROPN | Proper noun | 69 | 0.5% |
64
+ | SCONJ | Subordinating conjunction | 7 | 0.05% |
65
+ | X | Other | 7 | 0.05% |
66
+ | PART | Particle | 4 | 0.03% |
67
+
68
+ **Observation**: The dataset exhibits significant class imbalance, with NOUN and VERB comprising over 56% of all tokens.
69
+
70
+ ---
71
+
72
+ ## 3. Methodology
73
+
74
+ ### 3.1 Model Architecture
75
+
76
+ **Algorithm**: Conditional Random Fields (CRF)
77
+
78
+ CRF is a discriminative probabilistic model for sequence labeling. Given an input sequence $X = (x_1, x_2, ..., x_n)$, CRF models the conditional probability:
79
+
80
+ $$P(Y|X) = \frac{1}{Z(X)} \exp\left(\sum_{i=1}^{n} \sum_{k} \lambda_k f_k(y_{i-1}, y_i, X, i)\right)$$
81
+
82
+ Where:
83
+ - $Y = (y_1, y_2, ..., y_n)$ is the label sequence
84
+ - $f_k$ are feature functions
85
+ - $\lambda_k$ are learned weights
86
+ - $Z(X)$ is the partition function
87
+
88
+ ### 3.2 Feature Engineering
89
+
90
+ The model uses **27 feature templates** inspired by the underthesea NLP library:
91
+
92
+ #### Current Token Features (10)
93
+ ```
94
+ T[0] - Word form
95
+ T[0].lower - Lowercase form
96
+ T[0].istitle - Is title case
97
+ T[0].isupper - Is uppercase
98
+ T[0].isdigit - Is digit
99
+ T[0].isalpha - Is alphabetic
100
+ T[0].prefix2 - First 2 characters
101
+ T[0].prefix3 - First 3 characters
102
+ T[0].suffix2 - Last 2 characters
103
+ T[0].suffix3 - Last 3 characters
104
+ ```
105
+
106
+ #### Context Features (12)
107
+ ```
108
+ T[-1], T[-1].lower, T[-1].istitle, T[-1].isupper - Previous token
109
+ T[-2], T[-2].lower - Token at -2
110
+ T[1], T[1].lower, T[1].istitle, T[1].isupper - Next token
111
+ T[2], T[2].lower - Token at +2
112
+ ```
113
+
114
+ #### N-gram Features (2)
115
+ ```
116
+ T[-1,0] - Bigram (previous, current)
117
+ T[0,1] - Bigram (current, next)
118
+ ```
119
+
120
+ #### Dictionary Features (3)
121
+ ```
122
+ T[0].is_in_dict - Current token in dictionary
123
+ T[-1,0].is_in_dict - Bigram in dictionary
124
+ T[0,1].is_in_dict - Bigram in dictionary
125
+ ```
126
+
127
+ ### 3.3 Training Configuration
128
+
129
+ | Parameter | Value | Description |
130
+ |-----------|-------|-------------|
131
+ | Algorithm | lbfgs | Limited-memory BFGS optimization |
132
+ | c1 | 1.0 | L1 regularization coefficient |
133
+ | c2 | 0.001 | L2 regularization coefficient |
134
+ | max_iterations | 100 | Maximum training iterations |
135
+ | feature.possible_transitions | True | Include all possible transitions |
136
+
137
+ ### 3.4 Implementation
138
+
139
+ **Libraries Used**:
140
+ - `python-crfsuite` (0.9.11) - CRF implementation
141
+ - `scikit-learn` (1.6.1) - Evaluation metrics
142
+ - `datasets` (4.5.0) - Data loading from Hugging Face
143
+ - `wandb` (0.24.0) - Experiment tracking
144
+
145
+ **Code Structure**:
146
+ ```
147
+ tre/
148
+ ├── train_underthesea_crf.py # Training script
149
+ ├── test_hf_model.py # Model testing
150
+ ├── hf_model/ # Hugging Face deployment
151
+ │ ├── handler.py # Inference handler
152
+ │ ├── pos_tagger.crfsuite # Trained model
153
+ │ ├── requirements.txt # Dependencies
154
+ │ └── README.md # Model card
155
+ └── pos_tagger_underthesea.crfsuite # Local model
156
+ ```
157
+
158
+ ---
159
+
160
+ ## 4. Results
161
+
162
+ ### 4.1 Overall Performance
163
+
164
+ | Metric | Score |
165
+ |--------|-------|
166
+ | **Accuracy** | 95.57% |
167
+ | **Precision (macro)** | 91.25% |
168
+ | **Recall (macro)** | 86.11% |
169
+ | **F1 (macro)** | 87.45% |
170
+ | **F1 (weighted)** | 95.54% |
171
+
172
+ ### 4.2 Per-Tag Performance
173
+
174
+ | Tag | Precision | Recall | F1-Score | Support |
175
+ |-----|-----------|--------|----------|---------|
176
+ | PUNCT | 1.00 | 1.00 | 1.00 | 1,254 |
177
+ | CCONJ | 0.99 | 0.99 | 0.99 | 601 |
178
+ | PRON | 0.98 | 0.98 | 0.98 | 210 |
179
+ | AUX | 0.97 | 0.99 | 0.98 | 588 |
180
+ | ADP | 0.98 | 0.96 | 0.97 | 1,226 |
181
+ | NOUN | 0.95 | 0.97 | 0.96 | 4,245 |
182
+ | VERB | 0.94 | 0.95 | 0.94 | 3,070 |
183
+ | ADJ | 0.95 | 0.90 | 0.92 | 450 |
184
+ | NUM | 0.95 | 0.89 | 0.92 | 273 |
185
+ | PROPN | 0.93 | 0.90 | 0.91 | 69 |
186
+ | ADV | 0.93 | 0.85 | 0.89 | 501 |
187
+ | DET | 0.90 | 0.78 | 0.83 | 259 |
188
+ | SCONJ | 0.80 | 0.57 | 0.67 | 7 |
189
+ | X | 1.00 | 0.43 | 0.60 | 7 |
190
+ | PART | 0.43 | 0.75 | 0.55 | 4 |
191
+
192
+ ### 4.3 Confusion Matrix
193
+
194
+ ![Confusion Matrix](confusion_matrix_underthesea.png)
195
+
196
+ ### 4.4 Per-Tag Metrics Visualization
197
+
198
+ ![Per-Tag Metrics](per_tag_metrics_underthesea.png)
199
+
200
+ ---
201
+
202
+ ## 5. Error Analysis
203
+
204
+ ### 5.1 Common Errors
205
+
206
+ | Error Type | True Label | Predicted | Count | Example |
207
+ |------------|------------|-----------|-------|---------|
208
+ | NOUN → VERB | NOUN | VERB | 127 | "quyết định" (decision/decide) |
209
+ | VERB → NOUN | VERB | NOUN | 98 | "thực hiện" (implement) |
210
+ | ADV → ADJ | ADV | ADJ | 43 | "rất" (very) |
211
+ | DET → PRON | DET | PRON | 35 | "các" (the/plural marker) |
212
+
213
+ ### 5.2 Error Causes
214
+
215
+ 1. **Lexical Ambiguity**: Many Vietnamese words can function as multiple parts of speech
216
+ 2. **Class Imbalance**: Rare tags (PART, SCONJ, X) have insufficient training examples
217
+ 3. **Context Limitation**: CRF window size may miss long-range dependencies
218
+ 4. **Domain Specificity**: Legal domain vocabulary may differ from general Vietnamese
219
+
220
+ ---
221
+
222
+ ## 6. Deployment
223
+
224
+ ### 6.1 Hugging Face Model Hub
225
+
226
+ **Model URL**: [https://huggingface.co/undertheseanlp/tre-1](https://huggingface.co/undertheseanlp/tre-1)
227
+
228
+ **Files Deployed**:
229
+ | File | Size | Description |
230
+ |------|------|-------------|
231
+ | `pos_tagger.crfsuite` | 459 KB | Trained CRF model |
232
+ | `handler.py` | 4.5 KB | Custom inference handler |
233
+ | `requirements.txt` | 28 B | Python dependencies |
234
+ | `README.md` | 2.5 KB | Model card |
235
+
236
+ ### 6.2 Usage
237
+
238
+ #### Python (Local)
239
+
240
+ ```python
241
+ from huggingface_hub import hf_hub_download
242
+ import pycrfsuite
243
+
244
+ # Download model
245
+ model_path = hf_hub_download(
246
+ repo_id="undertheseanlp/tre-1",
247
+ filename="pos_tagger.crfsuite"
248
+ )
249
+
250
+ # Load model
251
+ tagger = pycrfsuite.Tagger()
252
+ tagger.open(model_path)
253
+ ```
254
+
255
+ #### Inference API
256
+
257
+ ```python
258
+ import requests
259
+
260
+ API_URL = "https://api-inference.huggingface.co/models/undertheseanlp/tre-1"
261
+ headers = {"Authorization": "Bearer YOUR_TOKEN"}
262
+
263
+ response = requests.post(
264
+ API_URL,
265
+ headers=headers,
266
+ json={"inputs": "Tôi yêu Việt Nam"}
267
+ )
268
+ print(response.json())
269
+ ```
270
+
271
+ ### 6.3 Example Predictions
272
+
273
+ | Input | Output |
274
+ |-------|--------|
275
+ | "Tôi yêu Việt Nam" | Tôi/PROPN yêu/VERB Việt/PROPN Nam/PROPN |
276
+ | "Hà Nội là thủ đô" | Hà/PROPN Nội/PROPN là/AUX thủ/NOUN đô/ADJ |
277
+ | "Học sinh đang học bài" | Học/PROPN sinh/VERB đang/ADV học/VERB bài/PUNCT |
278
+
279
+ ---
280
+
281
+ ## 7. Comparison with Baselines
282
+
283
+ | Model | Accuracy | F1 (macro) | Notes |
284
+ |-------|----------|------------|-------|
285
+ | Basic CRF | 95.17% | 87.01% | Standard features |
286
+ | **TRE-1 (This work)** | **95.57%** | **87.45%** | Underthesea features |
287
+ | Improvement | +0.40% | +0.44% | |
288
+
289
+ ---
290
+
291
+ ## 8. Limitations
292
+
293
+ 1. **Tokenization Required**: Model expects pre-tokenized input (whitespace-separated)
294
+ 2. **Domain Bias**: Trained on legal documents, may underperform on casual text
295
+ 3. **Rare Tags**: Poor performance on PART, SCONJ, X due to limited samples
296
+ 4. **No Word Segmentation**: Does not handle Vietnamese word segmentation
297
+
298
+ ---
299
+
300
+ ## 9. Future Work
301
+
302
+ 1. **Data Augmentation**: Generate synthetic examples for rare tags
303
+ 2. **Multi-domain Training**: Include news, social media, and conversational data
304
+ 3. **Neural Models**: Experiment with BiLSTM-CRF and Transformer-based models
305
+ 4. **Word Segmentation Integration**: Combine with VnCoreNLP or underthesea tokenizer
306
+ 5. **Active Learning**: Prioritize annotation of ambiguous cases
307
+
308
+ ---
309
+
310
+ ## 10. Experiment Tracking
311
+
312
+ All experiments are logged to Weights & Biases:
313
+
314
+ - **Project**: [pos-tagger-vietnamese](https://wandb.ai/rain1024/pos-tagger-vietnamese)
315
+ - **Run Name**: underthesea-crf
316
+ - **Run ID**: 2kbta2ew
317
+
318
+ ---
319
+
320
+ ## 11. Reproducibility
321
+
322
+ ### Environment
323
+
324
+ ```bash
325
+ Python: 3.9+
326
+ OS: Linux 5.15.0-139-generic
327
+ ```
328
+
329
+ ### Dependencies
330
+
331
+ ```
332
+ python-crfsuite>=0.9.11
333
+ datasets>=4.5.0
334
+ scikit-learn>=1.6.1
335
+ huggingface-hub>=0.20.0
336
+ ```
337
+
338
+ ### Training Command
339
+
340
+ ```bash
341
+ python train_underthesea_crf.py
342
+ ```
343
+
344
+ ### Model Checksum
345
+
346
+ ```
347
+ pos_tagger_underthesea.crfsuite
348
+ MD5: [generated at training time]
349
+ Size: 458,700 bytes
350
+ ```
351
+
352
+ ---
353
+
354
+ ## 12. Conclusion
355
+
356
+ This work presents TRE-1, a Vietnamese POS tagger achieving 95.57% accuracy using CRF with underthesea-style feature engineering. The model is publicly available on Hugging Face and can be easily integrated into Vietnamese NLP pipelines.
357
+
358
+ **Key Contributions**:
359
+ 1. High-accuracy Vietnamese POS tagger with open-source code
360
+ 2. Detailed feature engineering documentation
361
+ 3. Public model deployment on Hugging Face
362
+ 4. Comprehensive evaluation and error analysis
363
+
364
+ ---
365
+
366
+ ## References
367
+
368
+ 1. Lafferty, J., McCallum, A., & Pereira, F. (2001). Conditional Random Fields: Probabilistic Models for Segmenting and Labeling Sequence Data. ICML.
369
+
370
+ 2. Nguyen, D. Q., Nguyen, D. Q., Pham, S. B., & Nguyen, P. T. (2014). RDRPOSTagger: A Ripple Down Rules-based Part-Of-Speech Tagger. EACL.
371
+
372
+ 3. Universal Dependencies. https://universaldependencies.org/
373
+
374
+ 4. Underthesea - Vietnamese NLP Toolkit. https://github.com/undertheseanlp/underthesea
375
+
376
+ 5. python-crfsuite. https://github.com/scrapinghub/python-crfsuite
377
+
378
+ ---
379
+
380
+ ## Appendix
381
+
382
+ ### A. Feature Template Syntax
383
+
384
+ | Syntax | Meaning |
385
+ |--------|---------|
386
+ | `T[0]` | Current token |
387
+ | `T[-1]` | Previous token |
388
+ | `T[1]` | Next token |
389
+ | `T[-1,0]` | Bigram of previous and current |
390
+ | `.lower` | Lowercase transformation |
391
+ | `.prefix2` | First 2 characters |
392
+ | `.suffix3` | Last 3 characters |
393
+ | `.is_in_dict` | Dictionary lookup |
394
+
395
+ ### B. Universal POS Tags
396
+
397
+ | Tag | Description | Example |
398
+ |-----|-------------|---------|
399
+ | ADJ | Adjective | đẹp (beautiful) |
400
+ | ADP | Adposition | trong (in) |
401
+ | ADV | Adverb | rất (very) |
402
+ | AUX | Auxiliary | là (is) |
403
+ | CCONJ | Coordinating conjunction | và (and) |
404
+ | DET | Determiner | những (plural marker) |
405
+ | NOUN | Noun | nhà (house) |
406
+ | NUM | Numeral | một (one) |
407
+ | PART | Particle | ạ (politeness marker) |
408
+ | PRON | Pronoun | tôi (I) |
409
+ | PROPN | Proper noun | Việt Nam |
410
+ | PUNCT | Punctuation | . , ? |
411
+ | SCONJ | Subordinating conjunction | nếu (if) |
412
+ | VERB | Verb | đi (go) |
413
+ | X | Other | - |
414
+
415
+ ---
416
+
417
+ *Report generated: January 29, 2025*
418
+ *Model: undertheseanlp/tre-1*
419
+ *Version: 1.0*