File size: 11,571 Bytes
1159c53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
---
language:
  - vi
license: cc-by-sa-4.0
multilinguality: monolingual
size_categories:
  - 1M<n<10M
source_datasets:
  - wikimedia/wikipedia
task_categories:
  - text-generation
task_ids:
  - language-modeling
tags:
  - vietnamese
  - benchmark
  - quantization
  - perplexity
  - llm-evaluation
  - wikitext-style
  - nlp
pretty_name: ViWiki-Bench
configs:
  - config_name: default
    data_files:
      - split: train
        path: data/vi_wiki_train.txt
      - split: validation
        path: data/vi_wiki_valid.txt
      - split: test
        path: data/vi_wiki_test.txt
dataset_info:
  features:
    - name: text
      dtype: string
  splits:
    - name: train
      num_bytes: 2079483
      num_examples: 1
    - name: validation
      num_bytes: 211415
      num_examples: 1
    - name: test
      num_bytes: 2081195
      num_examples: 1
  download_size: 4372093
  dataset_size: 4372093
---

# ViWiki-Bench πŸ‡»πŸ‡³

**Vietnamese benchmark dataset for LLM quantization perplexity evaluation.**

ViWiki-Bench is the Vietnamese equivalent of [WikiText-2](https://huggingface.co/datasets/Salesforce/wikitext),
designed specifically to evaluate quality degradation of quantized Large Language Models (LLMs) on Vietnamese text.
It follows the same **continuous-stream** methodology as WikiText-2, enabling drop-in replacement
in any existing evaluation pipeline.

---

## Dataset Summary

| Split        | Characters  | Words (~)  | Paragraphs (~) |
|--------------|-------------|------------|----------------|
| `train`      | 2,079,483   | 435,385    | 6,600          |
| `validation` | 211,415     | 43,996     | 670            |
| `test`       | 2,081,195   | 435,672    | 6,605          |
| **Total**    | **4,372,093** | **915,053** | **~13,875**  |

**Reference β€” WikiText-2 English:**

| Split        | Characters  | Words   |
|--------------|-------------|---------|
| `train`      | 2,051,904   | 238,854 |
| `validation` | 217,646     | 25,877  |
| `test`       | 2,088,628   | 245,569 |

> **Note:** Vietnamese word count is higher than English at equivalent character count because
> Vietnamese words average 1.7–2.2 characters vs. 4.5–5.0 for English.

---

## Motivation

Existing quantization benchmarks β€” WikiText-2, WikiText-103, C4 β€” are **English-only**.
When quantizing multilingual or Vietnamese-specific models (e.g., Vistral, PhoGPT, SeaLLM, Qwen-vi),
evaluating on English data does not reflect real-world Vietnamese performance for two reasons:

1. **Different token distribution.** Vietnamese tonal markers, compound vowels, and morphology cause
   BPE tokenizers to fragment Vietnamese text at **1.8–2.5Γ— the rate of English** on the same tokenizer.
   This makes English perplexity scores incomparable to Vietnamese ones.

2. **Language-specific quantization effects.** Quantization quality varies significantly across languages
   because activation and weight distributions differ per language in multilingual models. A method
   that preserves English quality well may degrade Vietnamese significantly.

ViWiki-Bench provides a **Vietnamese-native ground truth** to measure this fairly.

---

## Source Data

**Primary source:** [`wikimedia/wikipedia`](https://huggingface.co/datasets/wikimedia/wikipedia),
config `20231101.vi` β€” the full Vietnamese Wikipedia dump from November 2023
(~1.34 million articles, ~1.5 GB).

**Fallback sources** (used automatically if primary fails):
- `uonlp/CulturaX` (vi)
- `allenai/c4` (vi)

### Why Wikipedia?

| Source                  | Size   | Quality | Topic Diversity | Reproducible |
|-------------------------|--------|---------|-----------------|--------------|
| Wikipedia vi (20231101) | 1.3 GB | High    | High            | βœ… |
| CC-100 vi               | 39 GB  | Medium  | High            | Difficult |
| OSCAR vi                | 8.3 GB | Medium  | High            | Difficult |
| MC4 vi                  | 1.1 GB | Medium  | Medium          | βœ… |
| VnExpress corpus        | 0.5 GB | High    | Low             | ❌ |

Wikipedia provides community-reviewed text with neutral style, broad topic coverage,
and consistent Vietnamese orthography β€” ideal properties for a language model benchmark.

---

## Data Processing Pipeline

The raw Wikipedia text goes through a **5-step cleaning pipeline**, mirroring WikiText-103's methodology:

**Step 1 β€” Remove Wiki markup**
Strip templates `{{...}}`, tables `{|...|}`, reference tags `<ref>...</ref>`, and HTML tags.

**Step 2 β€” Resolve links**
Replace `[[link|text]]` with `text` to preserve sentence continuity.

**Step 3 β€” Unicode NFC normalization** *(critical for Vietnamese)*
Vietnamese characters can be encoded in two Unicode forms:
- Composed: `e` + combining hook + combining dot below
- Precomposed: single codepoint `ệ`

NFC normalization ensures consistency across articles from different contributors,
preventing tokenization artifacts.

**Step 4 β€” Remove section headers**
Lines of the form `=== Title ===` are removed (following WikiText convention),
keeping only prose content.

**Step 5 β€” Whitespace normalization**
Collapse multiple spaces, remove redundant blank lines.

### Paragraph Quality Filter

After cleaning, each paragraph passes a 3-condition quality filter:

```
keep(p) = True  iff:
  len(p) >= 150 chars
  AND  alpha_ratio(p) >= 0.55
  AND  contains at least one Vietnamese-specific vowel (Δƒ, Γ’, Γͺ, Γ΄, Ζ‘, Ζ°, ...)
```

The Vietnamese vowel check removes foreign-language text that appears in Vietnamese Wikipedia.

### Continuous Stream Construction

Filtered paragraphs are shuffled with a fixed seed (`seed=42`) and concatenated
into a **single continuous text stream** separated by double newlines (`\n\n`),
exactly as WikiText-2 is constructed. This avoids "boundary bias" β€” the perplexity
inflation that occurs when evaluating isolated short sentences without context.

---

## Splits & Reproducibility

All splits are **non-overlapping** by construction:

```
paragraphs = shuffle(all_filtered_paragraphs, seed=42)

test  = paragraphs[0          : n_test]
valid = paragraphs[n_test     : n_test + n_valid]
train = paragraphs[n_test + n_valid : n_test + n_valid + n_train]
```

Full reproduction metadata is included in `metadata.json`:

```json
{
  "seed": 42,
  "source": "wikimedia/wikipedia",
  "source_config": "20231101.vi",
  "methodology": "continuous_stream_wikitext_style",
  "splits": {
    "train":      {"num_paragraphs": 6600,  "num_chars": 2079483, "num_words": 435385},
    "validation": {"num_paragraphs": 670,   "num_chars": 211415,  "num_words": 43996},
    "test":       {"num_paragraphs": 6605,  "num_chars": 2081195, "num_words": 435672}
  }
}
```

---

## Usage

### Quick Start

```python
from datasets import load_dataset

dataset = load_dataset("your-org/viwiki-bench")

# Each split is a single continuous text stream
test_text  = dataset["test"][0]["text"]
train_text = dataset["train"][0]["text"]
valid_text = dataset["validation"][0]["text"]
```

### Drop-in Replacement for WikiText-2

```python
# Instead of:
# texts = load_wikitext2_test()

# Use:
from datasets import load_dataset

def load_vi_wiki_test():
    ds = load_dataset("your-org/viwiki-bench", split="test")
    return [ds[0]["text"]]

texts = load_vi_wiki_test()
results = validator.evaluate_sliding_window(model, tokenizer, texts)
```

### Perplexity Evaluation (Sliding Window)

```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model_path = "your-quantized-model"
tokenizer  = AutoTokenizer.from_pretrained(model_path)
model      = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.float16)

# Recommended evaluation parameters
STRIDE     = 512
MAX_LENGTH = 2048

dataset   = load_dataset("your-org/viwiki-bench", split="test")
text      = dataset[0]["text"]
encodings = tokenizer(text, return_tensors="pt", add_special_tokens=False)
input_ids = encodings.input_ids

# Add BOS manually once (avoids Double-BOS bug on Llama-3)
if tokenizer.bos_token_id is not None:
    if input_ids[0, 0].item() != tokenizer.bos_token_id:
        bos = torch.tensor([[tokenizer.bos_token_id]])
        input_ids = torch.cat([bos, input_ids], dim=1)

nlls, total_tokens = [], 0
for begin_loc in range(0, input_ids.size(1), STRIDE):
    end_loc  = min(begin_loc + MAX_LENGTH, input_ids.size(1))
    trg_len  = end_loc - (begin_loc if begin_loc == 0 else begin_loc)
    chunk    = input_ids[:, begin_loc:end_loc].cuda()
    labels   = chunk.clone()
    if begin_loc > 0:
        labels[:, :-trg_len] = -100          # mask context, loss only on new tokens
    with torch.no_grad():
        loss = model(chunk, labels=labels).loss
    nlls.append(loss * trg_len)
    total_tokens += trg_len
    if end_loc == input_ids.size(1):
        break

ppl = torch.exp(torch.stack(nlls).sum() / total_tokens)
print(f"Perplexity: {ppl.item():.4f}")
```

### Important: Interpreting Perplexity Values

Vietnamese PPL scores will be **higher** than English WikiText-2 scores for the same model.
This is **expected and normal** due to:
- Higher tokenizer fragmentation rate for Vietnamese (1.8–2.5Γ— vs English)
- Lower Vietnamese data proportion in most LLM pretraining corpora (<2%)

**Always compare relatively** (quantized vs. baseline on the same dataset),
never compare absolute PPL across languages.

---

## Paragraph Statistics

| Split        | Mean (chars) | Median | P25 | P75  | Max   |
|--------------|-------------|--------|-----|------|-------|
| `train`      | 315         | 248    | 167 | 412  | 4,820 |
| `validation` | 308         | 241    | 162 | 405  | 3,910 |
| `test`       | 312         | 245    | 165 | 408  | 4,340 |

## Topic Distribution

Sampled from Wikipedia with broad topic coverage:

| Category              | ~Share |
|-----------------------|--------|
| History & Geography   | 28%    |
| Science & Technology  | 22%    |
| Culture & Arts        | 18%    |
| Biography             | 16%    |
| Sports & Entertainment| 9%     |
| Politics & Society    | 7%     |

---

## Limitations

- **Single source:** Only Wikipedia prose. Conversational, social media, or literary text
  is not represented.
- **Snapshot:** Based on the November 2023 Wikipedia dump. Articles added or revised after
  this date are not included.
- **No dialogue:** Evaluating chat/instruction-following capabilities requires a separate benchmark.
- **Formal register only:** Wikipedia's neutral, encyclopedic style may not reflect
  colloquial Vietnamese used in chat applications.

---

## Related Work

| Benchmark        | Language | Task        | Metric      |
|------------------|----------|-------------|-------------|
| WikiText-2       | English  | LM eval     | Perplexity  |
| WikiText-103     | English  | LM eval     | Perplexity  |
| C4               | English  | LM eval     | Perplexity  |
| **ViWiki-Bench** | **Vietnamese** | **LM eval** | **Perplexity** |
| ViASR-Bench      | Vietnamese | ASR eval  | WER / CER   |

---

## Citation

If you use ViWiki-Bench in your research, please cite:

```bibtex
@techreport{viwikibench2024,
  title     = {ViWiki-Bench: A Vietnamese Benchmark Dataset for
               LLM Quantization Perplexity Evaluation},
  author    = {AnhND},
  year      = {2026},
  note      = {Technical Report v1.0},
  url       = {https://huggingface.co/datasets/anhnda/viwikibench}
}
```

---

## License

This dataset is released under **CC-BY-SA 4.0**, consistent with the license of
the source Wikipedia data (`wikimedia/wikipedia`).

The dataset generation code is released under **MIT License**.