← All posts

· Casimiro Ferreira & Claude· 5 min read

From Unit Tests to Datasets

  • datasets
  • testing
  • numtag
  • chronologia
  • orthography2ipa

A test for a language library is a sentence and the answer that the library must give. numtag must read “duas dúzias” as 24. chronologia must read “next Tuesday” as one exact date. orthography2ipa must turn “O peixe está fresco” into u ˈpɐjʃɨ ʃˈta ˈfɾɛʃku.

One test per sentence works for tens of sentences. Our libraries have tens of thousands of sentences in many languages. At that size, test files cause problems:

  • The rows are inside a code repository, so nobody outside the project finds them or uses them.
  • Each repository keeps its own copy of shared rows, and the copies drift apart.
  • A pass or fail per sentence does not show the general effect of a change. One rule fix can repair 40 sentences and break 3, and a list of 43 test results hides that balance.

So we moved the rows out of the test files and into public datasets.

How a test reads a dataset

Each set is a dataset on Hugging Face, with one file per language. A test does not read the latest version of the set. It reads one exact commit, by its full hash. The numtag test suite keeps the hash in a small JSON file:

{
  "repo": "TigreGotico/numtag-benchmark",
  "revision": "b8295e58588483d87fe54d588fc003d8c80cd429",
  "floors": {
    "read da cardinal gold": 1.0,
    "read bn cardinal gold": 0.968
  }
}

The test downloads that revision once and puts it in a cache. It then scores the library on each group of rows. For reading, a group is one language, one kind of number and one tier of source. For spelling numbers back in words, a group is one language, one kind of number and the canonical or variant form. Each group has a floor, and a score below the floor fails the test.

The pinned hash makes the test repeatable. A change to the dataset cannot make a test fail without a change in the repository. To use a new version of the set, a developer changes the hash, measures the floors again and reads the difference. That difference is the point of the method. It shows, group by group, what the new rows teach about the library.

What the four sets hold

DatasetRowsLanguage tagsWhat one row is
numtag-benchmark3,510 at revision b8295e512a sentence with one number in words, its value, kind and position
chronologia-benchmark96,45755a sentence, a reference instant and the date it gives, or no date
o2i-words-benchmark10,134,169380a word and its pronunciation in IPA
o2i-sentences-benchmark5,060176a sentence and its pronunciation, with the rules that work across word boundaries

The rows come from different places:

  • numtag and chronologia. A language model wrote the sentences, apart from 1,049 chronologia rows that come from its own corpus tests. The answers do not come from a model or from a parser. For dates, the answer is calendar arithmetic from a fixed reference instant. For numtag, a second pass of the model checked each sentence. Some rows also match the words of a cited source, such as the CLDR number rules, and those rows are marked gold.
  • orthography2ipa. Each row comes from one named source, and the tier column gives the class of that source. The classes go from pronunciations that phonologists and dialectologists published, through lexicons and Wiktionary, to rows that a model corrected, and to machine output. The sentence set has 874 expert rows and 4,186 rows that a model corrected.

What they are not

These four datasets are regression sets. They are not benchmarks of accuracy.

Our libraries are tuned on these rows. A rule is written because a row failed, and then the row passes. A score on a set that shaped the library says how well the library fits the set. It does not say how well the library reads text that it never saw. Model-written sentences are also cleaner and more regular than real text.

So each dataset card starts with that warning, and we use the sets for one job only: to see what a change does between two versions. For claims of accuracy, we use data that the libraries never saw, such as the NeMo text-normalisation test cases or the NTREX translation set.

The orthography2ipa sets carry one more tool for honest use. The tuned_on column marks rows that the rules were tuned on, and the split column puts those rows in dev. Calibrate a threshold on dev, measure on test, and give each tier its own score.

What you can do with them

Load a language with the datasets library:

from datasets import load_dataset

rows = load_dataset("TigreGotico/o2i-sentences-benchmark", "pt-PT-x-porto", split="test")
print(rows[1]["text"], rows[1]["ipa"])
Viva a vida vivida ˈbibɐ ɐ ˈbidɐ biˈbidɐ

The Porto rows show the merger of /v/ and /b/ in northern Portugal, one of the 38 Portuguese lects in the sentence set.

Some uses:

  • Test your own library. Pin a revision, score your parser or phonemizer per group, and see the effect of each change.
  • Compare dialects. The o2i sets hold separate configs for regional lects, such as 55 lects of Spanish in the Americas and Spain.
  • Find our errors. A row where the library fails shows a defect. A row that is itself wrong shows a defect in the data. Both are useful reports.

numtag-benchmark and chronologia-benchmark are under Apache-2.0. The o2i sets give the licence per row, in the licence column. A few rows of the word set carry a non-commercial licence: filter on that column when you need commercial rights.