Hebrew Lemmatizer

Description

This model uses context and language knowledge to assign all forms and inflections of a word to a single root. This enables the pipeline to treat the past and present tense of a verb, for example, as the same word instead of two completely different words. The lemmatizer takes into consideration the context surrounding a word to determine which root is correct when the word form alone is ambiguous.

Open in Colab Download Copy S3 URI

How to use

Use as part of a pipeline after tokenisation.

...
lemmatizer = LemmatizerModel.pretrained("lemma", "he") \
.setInputCols(["token"]) \
.setOutputCol("lemma")
nlp_pipeline = Pipeline(stages=[document_assembler, tokenizer, lemmatizer])
light_pipeline = LightPipeline(nlp_pipeline.fit(spark.createDataFrame([[""]]).toDF("text")))
results = light_pipeline.fullAnnotate(["""להגיש	הגישה	הגיש	הגשתי	יגיש	מגישים	הגישו	תגיש	הגשנו	מגישה"""])

...
val lemmatizer = LemmatizerModel.pretrained("lemma", "he")
.setInputCols(Array("token"))
.setOutputCol("lemma")
val pipeline = new Pipeline().setStages(Array(document_assembler, tokenizer, lemmatizer))
val data = Seq("להגיש	הגישה	הגיש	הגשתי	יגיש	מגישים	הגישו	תגיש	הגשנו	מגישה").toDF("text")
val result = pipeline.fit(data).transform(data)
import nlu

text = ["""להגיש	הגישה	הגיש	הגשתי	יגיש	מגישים	הגישו	תגיש	הגשנו	מגישה"""]
lemma_df = nlu.load('he.lemma').predict(text, output_level='document')
lemma_df.lemma.values[0]

Results

{'lemma': [Annotation(token, 0, 4, הגיש, {'sentence': '0'}),
Annotation(token, 6, 10, הגיש, {'sentence': '0'}),
Annotation(token, 12, 15, הגיש, {'sentence': '0'}),
Annotation(token, 17, 21, הגיש, {'sentence': '0'}),
Annotation(token, 23, 26, הגיש, {'sentence': '0'}),
Annotation(token, 28, 33, הגיש, {'sentence': '0'}),
Annotation(token, 35, 39, הגיש, {'sentence': '0'}),
Annotation(token, 41, 44, הגיש, {'sentence': '0'}),
Annotation(token, 46, 50, הגיש, {'sentence': '0'}),
Annotation(token, 52, 56, הגיש, {'sentence': '0'})]}

Model Information

Model Name: lemma
Compatibility: Spark NLP 2.7.0+
Edition: Official
Input Labels: [tokens]
Output Labels: [lemma]
Language: he

Data Source

This model is trained on data obtained from https://universaldependencies.org/