N9E6Y
← WritingDatasetPersian NLP16 Oct 20266 min read

Turning the Dehkhoda Dictionary into Structured Data

Persian Dehkhoda Dictionary (لغت‌نامهٔ دهخدا) is now an open dataset on Hugging Face and Kaggle.


The Loghatnameh of Ali Akbar Dehkhoda is the largest encyclopedic dictionary of the Persian language. It took a lifetime of work from Dehkhoda and his collaborators, and it holds centuries of Persian vocabulary, poetry, geography, history and science. It is also hard to use in code. Online it's a collection of HTML fragments and PDF files, which is fine for reading one word at a time and awkward for anything else.

I wanted to change that, so I built a cleaned, structured version of the whole dictionary.

What's inside

Entries
343,316
covering 240,810 distinct headwords
Senses
566,654
of which 83,849 belong to compound sub-entries (phrases like از جلو کسی درآمدن under the headword جلو)
Source citations
841,986
drawn from 855 distinct sources
Figure · Where senses live

15% of senses sit inside compound sub-entries.

All 566,654 senses, split by where they live

WhereSenses
Headword senses482,805
Compound sub-entries83,849
Source: the dataset's senses table. Ink = compound sub-entries.

Every entry is a single JSON object with its pronunciation, part of speech, individual senses, compound sub-entries and cited sources nested inside it. Entries are sorted in Persian alphabetical order, and each one also keeps a diacritic-free headword_plain field for search and the original raw_html for reference.

Here's what the structure looks like for a single entry:

entry.json
{
  "headword": "اویزه",
  "pronunciation": "اَ زَ / زِ",
  "pos": "اِ",
  "is_proper_noun": false,
  "senses": [
    {
      "sense_no": 1,
      "text": "شراب انگور و می. (ناظم الاطباء) (برهان).",
      "sources": [
        {"citation": "(ناظم الاطباء)", "source": "ناظم الاطباء"},
        {"citation": "(برهان)", "source": "برهان"}
      ]
    }
  ]
}

How I built it

The starting point was a public raw dump of the dictionary with one HTML fragment per entry. Turning that into something usable took several steps:

  1. Splitting senses on the dictionary's || separators.
  2. Extracting sub-entries, which the dictionary marks with a leading dash followed by phrase؛ definition.
  3. Reading pronunciation and part of speech from the leading [ … ] block and the coloured ( … ) labels.
  4. Cleaning the text: joining the hard line wraps of the print layout, converting Arabic ي and ك to their Persian forms ی and ک, and normalizing footnote markers.
  5. Normalizing citations by stripping volume numbers, page numbers and prefixes, so that the same book always appears under the same name.
  6. Restoring alphabetical order. The website's ids are mostly alphabetical but not entirely. A block of about 3,900 entries starting with م shows up after ی. I re-sorted everything by Persian collation, ignoring diacritics, spaces and ZWNJ, which matches Dehkhoda's own ordering.
Figure · Entry orderSchematic

About 3,900 م entries sat after ی.

Order of entries by first letter · reads right to left · schematic, not to scale

Collation ignores diacritics, spaces and ZWNJ. Signal marks the displaced block.

Limitations

  • 506 entries from the printed dictionary are missing from the source scrape.
  • The website never published the footnotes, so only the markers remain.
  • Joining print line wraps also joins the lines of quoted poetry. raw_html keeps the original breaks if you need them.
  • Sub-entry and source extraction is rule-based, so a small number of entries will be wrong. Sources with fewer than 20 citations aren't listed in sources, though they stay in the text.

Try it

Python
from datasets import load_dataset

ds = load_dataset("n9e6y/persian-dehkhoda-dictionary", split="train")

entry = ds.filter(lambda e: e["headword"] == "جلو")[0]
for sense in entry["senses"]:
    print(sense["sense_no"], sense["subentry"] or "", sense["text"])

What it could be used for

A structured Dehkhoda opens up a lot for Persian NLP: building search and lookup tools, studying how word senses change over time, mining the citation network to see which classical sources the dictionary leans on, creating lexicons for spell-checking or morphology, or training and evaluating language models on a rich, literary Persian corpus.

Get the data

The dataset is available in two formats:

Acknowledgements

All the credit for the content goes to Allameh Ali Akbar Dehkhoda (1879–1956) and his collaborators. My part was only to make their life's work easier to work with. Thanks also to the compiler of the original public dump, which made this project possible.

If you use the dataset, I'd love to hear about it. Feel free to open a discussion on the Hugging Face page or send me a message.

← All writing Back to top ↑
Contact

Let's talk.

Research, code, ideas — Feel free to say Hi.