Description
This is a dictionary-based lemmatizer that assigns 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.
Live Demo Open in Colab Download Copy S3 URI
How to use
document_assembler = DocumentAssembler() \
.setInputCol("text") \
.setOutputCol("document")
tokenizer = Tokenizer()\
.setInputCols(["document"]) \
.setOutputCol("token")
lemmatizer = LemmatizerModel.pretrained("lemma", "mt") \
.setInputCols(["token"]) \
.setOutputCol("lemma")
pipeline = Pipeline(stages=[document_assembler, tokenizer, lemmatizer])
example = spark.createDataFrame([["Il- Membru tal- Kumitat Leo Brincat talab li bħala xhud ikun hemm rappreżentant tal- MEPA u kien hemm qbil filwaqt li d- Deputat Laburista Joe Mizzi ta lista ta' persuni oħrajn mill- Korporazzjoni Enemalta u minn WasteServ u ma kienx hemm oġġezzjoni ."]], ["text"])
results = pipeline.fit(example).transform(example)
val document_assembler = DocumentAssembler()
.setInputCol("text")
.setOutputCol("document")
val tokenizer = Tokenizer()
.setInputCols("document")
.setOutputCol("token")
val lemmatizer = LemmatizerModel.pretrained("lemma", "mt")
.setInputCols("token")
.setOutputCol("lemma")
val pipeline = new Pipeline().setStages(Array(document_assembler, tokenizer, lemmatizer))
val data = Seq("Il- Membru tal- Kumitat Leo Brincat talab li bħala xhud ikun hemm rappreżentant tal- MEPA u kien hemm qbil filwaqt li d- Deputat Laburista Joe Mizzi ta lista ta' persuni oħrajn mill- Korporazzjoni Enemalta u minn WasteServ u ma kienx hemm oġġezzjoni .").toDF("text")
val result = pipeline.fit(data).transform(data)
import nlu
text = ["Il- Membru tal- Kumitat Leo Brincat talab li bħala xhud ikun hemm rappreżentant tal- MEPA u kien hemm qbil filwaqt li d- Deputat Laburista Joe Mizzi ta lista ta' persuni oħrajn mill- Korporazzjoni Enemalta u minn WasteServ u ma kienx hemm oġġezzjoni ."]
lemma_df = nlu.load('mt.lemma').predict(text, output_level = "document")
lemma_df.lemma.values[0]
Results
+-------+
| lemma|
+-------+
| Il|
| _|
| _|
| tal|
| _|
| _|
| Leo|
|Brincat|
| _|
| _|
| _|
| _|
| _|
| _|
| _|
| tal|
| _|
| MEPA|
| _|
| _|
+-------+
only showing top 20 rows
Model Information
Model Name: | lemma |
Compatibility: | Spark NLP 2.7.5+ |
License: | Open Source |
Edition: | Official |
Input Labels: | [token] |
Output Labels: | [lemma] |
Language: | mt |
Data Source
The model was trained on the Universal Dependencies version 2.7.
Benchmarking
Precision=0.078, Recall=0.073, F1-score=0.075
PREVIOUSIcelandic Lemmatizer
NEXTTamil Lemmatizer