DictaBERT: A State-of-the-Art BERT Suite for Modern Hebrew

State-of-the-art language model for Hebrew, released here.

This is the fine-tuned model for the lemmatization task.

For the bert-base models for other tasks, see here.

General guidelines for how the lemmatizer works:

Given an input text in Hebrew, it attempts to match up each word with the correct lexeme from within the BERT vocabulary.

  • If the word is split up into multiple wordpieces it doesn't cause a problem, we still predict the lexeme with a high accuracy.

  • If the lexeme of a given token doesn't appear in the vocabulary, the model will attempt to predict a special token [BLANK]. In that case, the word is usually a name of a person or a city, and the lexeme is probably the word after removing prefixes which can be done with the dictabert-seg tool.

  • For verbs the lexeme is the 3rd person past singular form.

This method is purely neural-based, so in rare instances the predicted lexeme may not be lexically related to the input, but rather a synonym selected from the same semantic space. To handle those edge cases one can implement a filter on top of the prediction to look at the top K matches and choose using a specific set of measures, such as edit distance, to choose the prediction that can more reasonably form a lexeme for the input word. Another method is the use_lexicon option described below, built on a full Hebrew lexicon rather than a string-similarity heuristic.

Sample usage:

from transformers import AutoModel, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained('dicta-il/dictabert-lex')
model = AutoModel.from_pretrained('dicta-il/dictabert-lex', trust_remote_code=True)

model.eval()

sentence = 'בשנת 1948 השלים אפרים קישון את לימודיו בפיסול מתכת ובתולדות האמנות והחל לפרסם מאמרים הומוריסטיים'
print(model.predict([sentence], tokenizer))

Output:

[
  [
    [
      "בשנת",
      "שנה"
    ],
    [
      "1948",
      "1948"
    ],
    [
      "השלים",
      "השלים"
    ],
    [
      "אפרים",
      "אפרים"
    ],
    [
      "קישון",
      "קישון"
    ],
    [
      "את",
      "את"
    ],
    [
      "לימודיו",
      "לימוד"
    ],
    [
      "בפיסול",
      "פיסול"
    ],
    [
      "מתכת",
      "מתכת"
    ],
    [
      "ובתולדות",
      "תולדה"
    ],
    [
      "האמנות",
      "אומנות"
    ],
    [
      "והחל",
      "החל"
    ],
    [
      "לפרסם",
      "פרסם"
    ],
    [
      "מאמרים",
      "מאמר"
    ],
    [
      "הומוריסטיים",
      "הומוריסטי"
    ]
  ]
]

Lexicon-constrained lemmatization (beta)

Beta. This option is under active development and its selection algorithm is expected to change. The default behavior of predict is unchanged, and this feature is entirely opt-in.

Licensing: this mode is governed by CC BY-NC 4.0, not the model's CC BY 4.0, because it depends on the dicta-il/wordlist dataset. See License below, including how to request a free commercial licence for small business use.

By default the predicted lexeme is whatever the model ranks highest, which means it can be a word that is not a possible lemma of the input at all. Passing use_lexicon=True restricts the answer to the lemmas that the dicta-il/wordlist lexicon actually lists for that word, using the dataset's own prefix-aware, likelihood-ranked lookup.

For each word:

  • If the lexicon lists exactly one lemma, that lemma is returned.
  • If it lists several, we return the highest-ranked of the model's top topk predictions that the lexicon agrees with.
  • If the word is not in the lexicon, or the model's predictions and the lexicon share nothing, the default (unconstrained) prediction is returned.

Because the lemma no longer has to exist in the BERT vocabulary, this also resolves many [BLANK] predictions.

Requirements and cost

This option needs the datasets package, which is not installed by transformers:

pip install datasets

The first call downloads the lexicon (~90 MB, cached by huggingface_hub) and builds an in-memory index over it, which takes roughly a minute and a couple of GB of RAM. The index is built once per process and reused by every later call, so keep the model object alive rather than reloading it per sentence.

If that memory footprint is a problem, the lookup helper also offers lower-memory modes that keep resident RAM in the tens of MB, trading some query speed. See the "Prefix-aware lookup" section of the dicta-il/wordlist dataset card for low_memory and disk mode. predict does not currently expose them; it always uses the fast in-memory index.

Sample usage

from transformers import AutoModel, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained('dicta-il/dictabert-lex')
model = AutoModel.from_pretrained('dicta-il/dictabert-lex', trust_remote_code=True)

model.eval()

sentence = 'עצי הזית הארוכים בשדה של בנו הניבו פרי'
print(model.predict([sentence], tokenizer, use_lexicon=True))

Output, compared against the default:

word default use_lexicon=True
עצי [BLANK] עץ
הזית זית זית
הארוכים [BLANK] ארוך
בשדה שדה שדה
של של של
בנו בני בן
הניבו הניב הניב
פרי פרי פרי

topk (default 100) controls how many of the model's ranked predictions are considered before falling back to the default prediction.

Known limitations

On a sample of 400 sentences from our development set, the two paths disagreed on 206 words: the lexicon path was right on 113 of them, wrong on 75, and both were wrong on 18. Of the 33 words where the default predicted [BLANK], the lexicon recovered the correct lemma for 28.

Every one of the 75 regressions has the same shape: the expected lemma is not among the lexicon's options for that word at all. None of them are cases where the lexicon offered the right answer and a different one was selected. They are disagreements about what the lemma of a word is, not ranking errors. Roughly two thirds involve present participles; the rest are spelling conventions, numerals and a small number of coverage gaps.

  • Present participles (beinoni). The lexicon lemmatizes a present participle to the finite verb, so מעביר returns העביר, consistent with how it treats verbs generally. The model frequently returns the participle itself. Hebrew lemmatization of beinoni forms is genuinely unsettled and resources differ, so this option makes the choice uniform rather than resolving it. If you depend on beinoni lemmas, check which convention you need. This is the largest single source of disagreement.
  • Lexicalized participles. A few words whose participle form has become a noun or adjective in its own right may return the verbal lemma instead. We are addressing these case by case.
  • Spelling conventions. The lexicon may use a different spelling of the same lemma than you expect, in either direction of ktiv male/haser (כוהן vs כהן, תהילים vs תהלים).
  • Numerals and ordinals. Ordinals keep their own lemma (החמישי to חמישי) rather than mapping to the cardinal.
  • Out-of-lexicon words. Initialisms, many loanwords and many proper names are not in the wordlist, so they fall back to the default prediction, including [BLANK].
  • Modern Hebrew only. Readings flagged as poetic, pre-modern, Aramaic or biblical-only are filtered out, so this option is not currently suitable for rabbinic or classical text.

Citation

If you use DictaBERT-lex in your research, please cite MRL Parsing without Tears: The Case of Hebrew

BibTeX:

@misc{shmidman2024mrl,
      title={MRL Parsing Without Tears: The Case of Hebrew}, 
      author={Shaltiel Shmidman and Avi Shmidman and Moshe Koppel and Reut Tsarfaty},
      year={2024},
      eprint={2403.06970},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}

License

The model itself, and its default behaviour, are licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).

The use_lexicon=True mode is different. It depends on the dicta-il/wordlist dataset, which is released under Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0). Using that mode therefore places your use of it under the non-commercial terms. The default lemmatizer is unaffected and remains CC BY 4.0.

To obtain a free licence for commercial use in the context of a small business initiative, please contact us directly: shmidman@gmail.com.

CC BY 4.0

Downloads last month
823
Safetensors
Model size
0.2B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Spaces using dicta-il/dictabert-lex 3

Collection including dicta-il/dictabert-lex

Paper for dicta-il/dictabert-lex