Description
This model converts words to their basic form. For example, it can convert past and present tense of a word, singular and plural words in a single form, which enables the downstream model to treat both words similarly instead of 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", "ar") \
.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", "ar")
.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('ar.lemma').predict(text, output_level='document')
lemma_df.lemma.values[0]
Results
{'lemma': [Annotation(token, 0, 3, رَفَض, {'sentence': '0'}),
Annotation(token, 5, 8, رَفَض, {'sentence': '0'}),
Annotation(token, 10, 15, رَفَض, {'sentence': '0'}),
Annotation(token, 17, 20, رَفَض, {'sentence': '0'}),
Annotation(token, 22, 25, نرفض, {'sentence': '0'}),
Annotation(token, 27, 29, رَفض, {'sentence': '0'}),
Annotation(token, 31, 35, رَفَض, {'sentence': '0'}),
Annotation(token, 37, 40, رَفَض, {'sentence': '0'}),
Annotation(token, 42, 46, رَفَض, {'sentence': '0'})]}
Model Information
Model Name: | lemma |
Compatibility: | Spark NLP 2.7.0+ |
Edition: | Official |
Input Labels: | [token] |
Output Labels: | [lemma] |
Language: | ar |
Data Source
This model is trained on data obtained from https://universaldependencies.org/