yacht's picture
OpenThai2.0-NLP-Core-Benchmark 1.1: test sets, scorers and system outputs for six Thai tasks.
0e6d825
|
Raw History Blame Contribute Delete
9.2 kB

Thai named entity recognition benchmark

Part of OpenThai2.0-NLP-Core-Benchmark. Benchmark version 1.1.

A fixed test for Thai named entity recognition from raw text: the test split of ThaiNER v2.2, one scorer, and the stored outputs of every system in the table below, so every published number can be recomputed. The test texts are not in this repository. The first run downloads them from their source at a pinned revision.

Quick start

pip install -U huggingface_hub
hf download iapp/OpenThai2.0-NLP-Core-Benchmark --repo-type dataset --include "ner/*" --local-dir nlp-core-bench
cd nlp-core-bench/ner && pip install -r requirements.txt
from benchmark import evaluate

evaluate(my_ner, name="my-ner")   # my_ner(text) -> [(start, end, type), ...] for one text

This runs your function on the 1,472 test texts, one text per call, as a user passes it. It prints entity F1 in the three views of the table, next to the published systems, and saves outputs/my-ner/ and results-my-ner.json. From the command line: python benchmark.py --module my_package:ner --name my-ner, or python benchmark.py --predictions FILE --name my-ner for outputs you already have.

Why the first run downloads a file. ThaiNER v2.2 states CC BY 3.0 on its card, and the card says that the lists of its sources are lost. So this repository does not copy its text. build_testsets.py downloads the test split from its source at the revision in sources.json, checks it and builds the set, about 1 MB.

Test set

Set Source Texts Entities Types Licence In this repository
thainer22-test ThaiNER v2.2 test split, revision e516176 1,472 3,816 16 CC BY 3.0 (its card) no: built on the first run

The 16 types are ORGANIZATION, LOCATION, PERSON, DATE, TIME, FACILITY, MONEY, LAW, PERCENT, AGO, PHONE, URL, LEN, ZIP, TEMPERATURE and EMAIL, from the most to the least frequent. The table has three views of the set, one a column:

  • All texts: every text, with all 16 types.
  • Not in train: the 1,385 texts that share no text with ThaiNER v2.2 train. For each of the other 87, a text of train equals it, contains it, or holds 80% of its character 5-grams, so the systems that learnt ThaiNER train have seen it. Their ids are in data/views.json.
  • Three types: every text, with the gold and the outputs kept to PERSON, ORGANIZATION and LOCATION (2,769 entities).

Results

Entity F1 (%):

System Input All texts Not in train Three types
OpenThai2.0-NLP-Core-Lite text 84.7 84.8 86.3
PyThaiNLP 5.4.0 phayathaibert newmm words, first piece 85.7 85.4 87.5
PyThaiNLP 5.4.0 thainer-v2 newmm words, first piece 82.8 82.8 85.1
Porameht/wangchanberta-thainer-corpus-v2-2 newmm words, first piece 82.8 82.7 84.8
Porameht/wangchanberta-thainer-corpus-v2-2 as PyThaiNLP calls it 61.5 61.9 70.7
PyThaiNLP 5.4.0 thainer-v2 as PyThaiNLP calls it 61.3 61.6 71.0
PyThaiNLP 5.4.0 tltk (TLTK 1.11) as PyThaiNLP calls it 38.0 37.8 46.2
PyThaiNLP 5.4.0 phayathaibert as PyThaiNLP calls it 20.3 20.2 14.2
PyThaiNLP 5.4.0 thainer (CRF) as PyThaiNLP calls it (74.2) (74.0) (75.4)
PyThaiNLP 5.4.0 wangchanberta as PyThaiNLP calls it (61.6) (61.5) (68.1)
PyThaiNLP 5.4.0 phayathaibert (reference) ThaiNER words 88.2 88.0 89.7
PyThaiNLP 5.4.0 thainer-v2 (reference) ThaiNER words 85.2 85.1 86.9
Porameht/wangchanberta-thainer-corpus-v2-2 (reference) ThaiNER words 84.9 84.7 86.5

Bold: the best value of each column. Rows in parentheses and reference rows are left out of the comparison (see below).

OpenThai2.0-NLP-Core-Lite is our model. It learnt no text of ThaiNER. This test set was opened for it once, on 2026-11-29, following a plan written in advance. Nothing of the model changed after that.

Each other system gets every text as written, one text per call:

  • thainer-v2, the model of Porameht and the engine phayathaibert are encoders tuned on ThaiNER 2: pythainlp/thainer-corpus-v2-base-model and Porameht/wangchanberta-thainer-corpus-v2-2 (WangchanBERTa), and Pavarissy/phayathaibert-thainer (PhayaThaiBERT), all run through the NER code of PyThaiNLP 5.4.0. As PyThaiNLP calls them, the first two cut the text with newmm and tag every subword piece, and the third tags the pieces of the uncut text. Yet the first two learnt only the first piece of each word, and all three score far higher when each newmm word is tagged by its first piece. So each has a row with that call, and these rows are the ones in the comparison. The two rows of phayathaibert on given words, those of newmm and those of ThaiNER, were added on 2026-12-01.
  • Their reference rows tag the gold words of ThaiNER, a setting that favours them and that a user does not have. The card of thainer-v2 reports this setting. The card of phayathaibert reports 86.7 F1 on its own evaluation set.
  • The CRF and wangchanberta of PyThaiNLP learnt ThaiNER 1.3, which holds most of the text of 1,294 of the 1,317 test texts of 20 characters or more. Their scores are in parentheses and take no part in the comparison.
  • tltk tags three types only. TLTK learnt entity data that ThaiNER also drew on, and the overlap was not measured.

Our model minus each of the three systems closest to it, with the 95% interval of a paired bootstrap over texts. An interval that holds 0 is a tie:

NLP Core minus All texts Not in train Three types
phayathaibert, newmm words, first piece −0.99 [−2.25, +0.28] −0.62 [−1.89, +0.64] −1.16 [−2.45, +0.12]
thainer-v2, newmm words, first piece +1.84 [+0.55, +3.12] +2.00 [+0.76, +3.29] +1.21 [−0.16, +2.51]
Porameht/wangchanberta-thainer-corpus-v2-2, newmm words, first piece +1.84 [+0.57, +3.12] +2.14 [+0.84, +3.42] +1.52 [+0.14, +2.85]

Every system, view and interval is in results/expected.json, and every output is in predictions/.

How scores are computed

  • Entity F1: an entity is correct when its span and its type both match a gold entity (strict). Precision, recall and F1 are micro, over all entities of a view.
  • Spans: character offsets into the text, end exclusive. Whitespace and zero-width characters at the edges of an output entity are trimmed first, as they were in the gold.
  • The gold comes from the BIO tags of ThaiNER: an I- tag after O or after another type starts an entity, as seqeval does by default.
  • Intervals: a paired bootstrap over texts, 10,000 resamples, seed 0, 95%.
  • Rounding: half to even (Python's round), once, from the unrounded score: two decimals in results/expected.json, one here.

Add a system

python benchmark.py --module my_package:ner --name my-ner     # writes outputs/my-ner/
python add_system.py my-ner --from outputs/my-ner/thainer22-test.jsonl --display "My NER 1.0"

add_system.py checks the file, copies it to predictions/, scores it with the same scorer, and adds the row to results/expected.json and to the table above, with its interval against our model. python score.py check recomputes every published number from the stored outputs.

Data format

An output file, predictions/SYSTEM/thainer22-test.jsonl, holds one line per test text: its id and its entities as character offsets with a type, no text.

{"id": "test-00000", "entities": [[0, 10, "ORGANIZATION"], [82, 95, "DATE"]]}

The test set that the first run builds, data/thainer22-test.jsonl, has the same lines with the text of each record added ("text"): the words of ThaiNER joined, in the order of its test split.

Reproduce

python build_testsets.py    # the set from ThaiNER v2.2 at the revision in sources.json, checked against checksums.json
python score.py check       # every published number recomputed from predictions/ and checked

Licences

  • Test set: not in this repository. ThaiNER v2.2 keeps its licence, CC BY 3.0 on its card. NOTICE gives its attribution.
  • Predictions and the other files we made (predictions/, data/views.json, results/, sources.json, checksums.json): ids, character offsets, types and scores, no text. Apache-2.0, as the code.
  • Code (*.py, scoring/): Apache-2.0 (LICENSE).

Citation

Please cite the test set:

@dataset{wannaphong_phatthiyaphaibun_2024_10795907,
  author    = {Wannaphong Phatthiyaphaibun},
  title     = {Thai NER 2.2},
  month     = mar,
  year      = 2024,
  publisher = {Zenodo},
  version   = {2.2},
  doi       = {10.5281/zenodo.10795907},
  url       = {https://doi.org/10.5281/zenodo.10795907}
}