<<

Build Fast and Accurate Lemmatization for Arabic

Hamdy Mubarak QCRI, Hamad Bin Khalifa University (HBKU), Doha, Qatar [email protected] Abstract In this paper we describe the complexity of building a lemmatizer for Arabic which has a rich and complex , and show some differences between lemmatization and surface stemming, i.e. removing prefixes and suffixes from . We discuss the need for a fast and accurate lammatization to enhance Arabic results. We also introduce a new dataset that can be used to test lemmatization accuracy, and an efficient lemmatization that outperforms state-of-the-art Arabic lemmatization in terms of accuracy and speed. We share the dataset and the code for research purposes.

Keywords: Arabic NLP, Lemmatization, Stemming, Information Retrieval, Diactitization

1. Introduction 2. Background Lemmatization is the process of finding the base form Arabic is the largest Semitic language spoken by almost (or ) of a by considering its inflected forms. 300 million people. It’s one of the six official languages Lemma is also called dictionary form, or citation form, and in the United Nations, and the fifth most widely spoken it refers to all words having the same meaning. language after Chinese, Spanish, English, and Hindi1.

Lemmatization is an important preprocessing step for Arabic has a very rich morphology, both derivational and many applications of and question-answering inflectional. Generally, Arabic words are derived from a systems. Researches in Arabic Information Retrieval (IR) that uses three or more consonants to define a broad systems show the need for representing Arabic words at meaning or concept, and they follow some templatic lemma level for many applications, including keyphrase  morphological patterns ( éJ ¯Qå”Ë@ áK P@ñÖ Ï@). By adding extraction (El-Shishtawy and Al-Sammak, 2009) and vowels, prefixes and suffixes to the root, word inflections (Dichy and Fargaly, 2003). In addi- are generated. For instance, the word  (wsyftH- tion, lemmatization provides a productive way to generate AîEñjJ®J ƒð 2 generic keywords for search engines (SE) or labels for wnhA) “and they will open it” has the triliteral root concept maps (Plisson et al., 2004). iJ¯ (ftH), which has the basic meaning of opening, has prefixes (w+s) “and+will”, suffixes (wn+hA) is that core part of the word that never changes €+ð Aë+ àð “they..it”, stem  (yftH) “open”, and lemma  (ftH) even with morphological inflections; the part that remains iJ®K iJ¯ after prefix and suffix removal. Sometimes the stem of “the concept of opening”. the word is different than its lemma, for example the words: believe, believed, believing, and unbelievable share Arabic verbs have the following grammatical categories: the stem (believ-), and have the normalized word form tense (past, present, imperative, and future), number (sin- (believe) standing for the infinitive of the verb (believe). gular, dual, and plural), person (first, second, and third), mood (indicative, subjunctive, and jussive for present While stemming tries to remove prefixes and suffixes from verbs, given for past verbs, and jussive for imperative words that appear with inflections in free text, lemmatiza- verbs), gender (masculine and feminine) and voice (active tion tries to replace word suffixes with (typically) different and passive). suffix to get its lemma. For languages having complex Typically, lemmatization of a verb is achieved by obtaining derivational and inflectional morphology, like Arabic, its past tense without any prefixes or suffixes, singular lemmatization needs more than just suffix replacement as number, third person, given mood, masculine gender, and will be described in next section. active voice. Mapping between different grammatical values cannot be done in many cases by just stripping This paper is organized as follows: Section 2. gives some word from its prefixes and suffixes but by applying some background about Arabic morphology and shows some complex morphological rules due to the derivational nature complexities in building Arabic lemmatization; Section 3. of Arabic morphology. Table 1 shows some examples. lists IR clustering methods and gives examples to show that lemmatization can enhance search results; Section 4. sur- Arabic nouns and adjectives have the following grammati- veys prior work on Arabic stemming and lemmatization; cal categories: case (nominative, accusative, and genitive), Section 5. introduces the dataset that we created to test number (singular, dual, and plural (proper or broken plu- lemmatization accuracy; Section 6. describes the algorithm of the system that we built. Results and error analysis are 1https://en.wikipedia.org/wiki/Arabic described in section 7.; and Section 8. concludes the paper 2Words are written in Arabic, transliterated using Buckwalter and lists some tasks for future work. transliteration, and translated.

1128 Case Example cases should be considered in addition to stripping words >  >  present- past Èñ®K - ÈA¯ (yqwl, qAl) “said, say” from prefixes and suffixes to get their proper lemmatization. passive->active ¯ñ K ->¯A K (nwq$, nAq$) 3. Lmmatization and IR “was discussed, discussed” IR systems normally cluster words together into groups first->third IÖ ß ->ÐAK (nmt, nAm) according to three main levels: root, stem, or lemma. The “I slept, he slept” root level is considered by many researchers in the IR field plural->singular @ñ“P ->úæ•P (rDwA, rDy) which leads to high recall but low precision due to language complexity. For example words     (yktb, “they satisfy, he satisfies” H. AJ» , éJ.JºÓ ,I. JºK Table 1: Examples of complex verb lemmatization cases mktbp, ktAb) “he writes, library, book” have the same root  (ktb) with the basic meaning of writing. Therefore, I. J» searching for any of these words by root, yields getting the other words which may not be desirable for many users. rals  )), gender (mascu- Q ‚ºJË@ð ÕËA‚Ë@ I KñÖÏ@ð Q»YÖÏ@ ©Ôg. line and feminine) and definiteness (definite and indefi- Other researchers show the importance of using stem level nite). Typically, lemmatization of a noun or an adjective is for improving retrieval precision and recall as they capture achieved by obtaining its nominative case without any pre- between inflected words. However, in fixes or suffixes, singular number, masculine gender, and Arabic, stem patterns may not capture similar words having indefinite form. Mapping between different values is not the same semantic meaning. For example, stem patterns straightforward in many cases as shown in Table 2. for broken plurals are different from their singular patterns, e.g. the stem of the plural word  (AqlAm) “pens” Case Example ÐC¯@  broken plural->singular ÈAg. P ->Ég. P (rjAl, rjl) does not match the stem of its singular form Õί (qlm) “men, man” “pen”. The same applies to many imperfect verbs that proper plural->singular  ->  (snwAt, snp) have different stem patterns than their perfect verbs, e.g. H@ñJƒ éJƒ the verbs   (AstTAE, ystTyE) “he could, he “years, year” ©J ¢‚ ,¨A¢Jƒ@ can” do not match because they have different stems. In- feminine->masculine -> (xDrA’, >xDr) Z@Qå” k Qå” k @ dexing using lemmatization can enhance the performance “green (f), green (m)” of Arabic IR systems as reported in (El-Shishtawy and genitive->nominative -> éKAJK . ZAJK . El-Ghannam, 2012), and in pactice, lemmatization should (bnA}h, bnA’) be very fast and accurate to be used in IR systems. “building-it, building”  >  special cases HAJ ®‚‚Ó - ù®‚‚Ó 4. Related Work (mst$fyAt, mst$fY) A lot of work has been done in word stemming and “hospitals, hospital” lemmatization in different languages, for example the > HAëñK YJ ¯ - ñK YJ ¯ famous Porter stemmer for English, but for Arabic, few (fydywhAt, fydyw) works have been done especially in lemmatization, and “videos, video”... there is no open-source code and new testing data that can Table 2: Examples of complex noun lemmatization cases be used by other researchers for word lemmatization.

Xerox Arabic Morphological Analysis and Generation In addition, according to Arabic morphology and writing (Beesley, 1996) is one of the early Arabic stemmers, and system, attaching pronouns to words in some cases changes it uses morphological rules to obtain stems for nouns and their last letter. This adds an extra complexity when ob- verbs by looking into a table of thousands of roots. taining lemmas. For example, when nouns ending with Taa-Marbouta letter are attached to possessive pronouns, Khoja’s stemmer (Khoja, 1999) and Buckwalter morpho- it will be changed to Taa letter as in è+ èPA ’k -> éKPA ’k logical analyzer (Buckwalter, 2002) are other root-based (hDArp+h, HDArth) “its civilization”. Also, when verbs analyzers and stemmers which use tables of valid combi- ending with Alif-Maqsoura letter are attached to some nations between prefixes and suffixes, prefixes and stems, subject pronouns, it will be changed to Yaa letter as in and stems and suffixes. AK+ øYë ->AJK Yë ( hdY+nA, hdynA) “we guided” or even deleted in some cases as in -> (hdY+wA, Recently, MADAMIRA (Pasha et al., 2014) system has @ð +øYë @ðYë been evaluated using a blind testset of 25K words for Mod- hdwA) “they guided”, and when are attached to object ern Standard Arabic (MSA) selected from Penn Arabic pronouns, it will be changed to Alif letter as in Aë +øYë Tree bank (PATB). They reported an accuracy of 96.2% ->Aë@Yë (hdY+hA, hdAhA) “guides her”, etc. as the percentage of words where the chosen analysis (provided by SAMA morphological analyzer (Graff et al., The mentioned cases are just few examples to show how 2009)) has the correct lemma. complex the Arabic lemmatization is, and reveal that many

1129 In this paper, we present an open-source Java code to ex- in both Machine Translation, and Information Retrieval tract Arabic lemmas, and a new publicly available testset tasks (Abdelali et al., 2016). This work can be considered for lemmatization allowing researches to evaluate using the as an extension to word segmentation. same dataset, and reproduce results. We used a fully diacritized corpus created by a commercial 5. Data Description vendor which contains 9.7 million words with almost 200K To make the annotated data publicly available, we se- unique surface words. About 73% of the corpus is in MSA lected 70 news articles from Arabic WikiNews site and covers variety of genres like politics, economy, sports, https://ar.wikinews.org/wiki. These articles society, etc. and the remaining part is mostly religious cover recent news from year 2013 to year 2015 in multiple texts written in classical Arabic (CA). (Darwish et al., genres (politics, economics, health, science and technol- 2017) used this corpus to build state-of-the-art diacritizer ogy, sports, arts, and culture.) Articles contain 18,300 with word error rates (WER) of 3.29% and 12.76% in words, and they are evenly distributed among these 7 diacritization of stem and grammatical case ending in order. genres with 10 articles per each. From this corpus, we constructed a dictionary of words and Words were white-space and punctuation separated, and their possible diacritizations ordered by number of occur- some spelling errors were corrected (1.33% of the total rences of each diacritized form. For example, the word (wbnwd) “and items” is found 4 times in this corpus words) to have a very clean testset. Lemmatization was XñJK.ð done by an expert Arabic linguist where spelling correc- with two full diacritization forms (wabunudi, XñJK.ð ,X ñJK.ð tions were marked, and lemmas were provided with full wabunudK) “and items, with different grammatical case diacritization. Sample is shown in Figure 1. endings” which appeared 3 times and once respectively. All unique undiacritized words in this corpus were analyzed As MSA is usually written without diacritics and IR sys- using Buckwalter morphological analyzer which gives all tems normally remove them from search queries and also possible word analyses, and for each analysis it provides from indexed data as a basic preprocessing step, so another its diacritization, segmentation, lemma and part-of-speech column for undiacritized lemma was added. This column (POS) as shown in Figure 2. was used to evaluate our lemmatizer and to compare with state-of-the-art systems for lemmatization (MADAMIRA), and segmentation and surface stemming (Farasa).

The raw sentences of the testset can be down- loaded from the link: http://alt.qcri.org/ ˜hmubarak/WikiNews-26-06-2015.txt and the annotation for lemmatization from the link: http://alt.qcri.org/˜hmubarak/ WikiNews-26-06-2015-RefLemma.xlsx Figure 2: Buckwalter analysis (diacritization forms and lemmas are highlighted)

The idea is to take the most frequent diacritized form for words that appear in this corpus, and find the morpho- logical analysis with highest matching score between its diacritized form and the corpus diacritized word. This means that we search for the most common diacritization of words regardless of their surrounding contexts. In the above example, the first solution is preferred and hence its lemma YJK . (banod, bnd after diacritics removal) “item”, and the other less frequent analysis is ignored.

Figure 1: Lemmatization of WikiNews corpus While comparing two diacritized forms from the corpus and Buckwalter analysis, many special cases were applied to solve inconsistencies between the two diacritization schemas, for example while words are fully diacritized in 6. System Description the corpus, Buckwalter analysis gives diacritics without We were inspired by the work done by (Darwish and case ending (i.e. without context), and it removes short Mubarak, 2016) for segmenting Arabic words out of vowels in some cases, for example before long vowels, and context. They achieved an accuracy of almost 99%; after the definite article È@ (Al) “the”, etc. slightly better than state-of-the-art system for segmentation (MADAMIRA) which considers surrounding context and It is worth mentioning that there are many cases in many linguistic features. This system shows enhancements Buckwalter analysis where for input word, there are two

1130 or more identical diacritizations with different lemmas, 7.1. Error Analysis and the analyses in these cases are provided in a random Most errors in our system are due to using only the most  order. For example the word èPAJ ƒ (syArp) “car” has two frequent diacritization of words without considering their morphological analyses with different lemmas; (syAr) contexts. This cannot solve ambiguity in cases like when PAJ ƒ nouns and adjectives share the same diacritization forms, “walker”, and  (syArp) “car” in this order while èPAJ ƒ e.g. the word  (AkAdymyp) can be either noun and the second lemma is the most common one. To solve éJ Öß XA¿@ this problem, all such words were reported and the top its lemma is éJ Öß XA¿@ (AkAdymyp) “academy”, or adjective frequent words were revised to insure that their lemmas are 3 and its lemma is (AkAdymy) “academic”. sorted according to actual usage in a modern large corpus . ù Öß XA¿@ The lemmatization algorithm can be summarized in Figure For MADAMIRA, most errors came from selecting 3, and the code can be tested and downloaded from Farasa incorrect POS tag, hence lemma, for ambiguous words (ex: site: farasa.qcri.org. It can be called from the the word H@Qå •Am × (mHADrAt) “lectures” was mistakenly command line as a Java package (.jar) using the following tagged as adjective Qå•Am × (mHADr) “lecturer” instead of syntax: the correct noun  (mHADrp) “lecture”). Another farasa –lemma -i -o èQå•Am× source of errors is the wrong segmentation of named Figure 4 shows system output for a sample sentence where entities, ex: the word àñ JK AJ.Ë@ (AlbAyvwn) “the+Python” errors are highlighted. which should be segmented as àñ JK AK.+ È@ (Al+bAyvwn) 7. Evaluation “the Python”, i.e. split the definite article È@ (Al) “the”. Lemmatization outputs of MADAMIRA and our system were compared against the undiacritized reference lemma For Farasa segmenter (surface stemmer), errors came from for each word. We evaluated also surface stemming of not supporting complex cases described in Section 2.. Farasa segmenter (Darwish and Mubarak, 2016) (i.e. the 8. Conclusion remaining part after removing prefixes and suffixes) to quantify the improvement in lemmatization accuracy after In this paper, we list some complexities in building applying the suggested algorithm. lemmatization for Arabic due to its rich morphology and complex writing system. We introduce a new testset for For more accurate results, all differences were revised lemmatization and a very fast and accurate algorithm that manually to accept cases that should not be counted as performs better than state-of-the art lemmatization system; errors, for example in different writings for foreign named MADAMIRA. It also outperforms state-of-the-art word entities such as and (hwng kwng, segmenter (surface stemmer); Farasa segmenter. l.'ñ» l.'ñë © Kñ» © Kñë hwnj kwnj) “Hong Kong”. From a large fully diacritized corpus, possible diacritiza- tions of words are extracted, and the algorithm considers Table 3 shows results of testing our system, MADAMIRA only the most frequent diacritized form for words out of and Farasa segmenter as surface stemmer on the WikiNews context. It gets the best similarity matching score between testset (for undiacritized lemmas). Our approach gives +7% this diacritized form and the morphological analysis, pro- and +32% relative gains above MADAMIRA and Farasa vided by Buckwalter morphological analyzer, which con- segmenter respectively in lemmatization task. tains word lemma. Both the testset and the code are pub- System Accuracy licly available for researchers. Farasa segmenter (surface stemmer) 73.68% We plan to study the performance when we consider sour- MADAMIRA 96.61% rouning context, also to provide diacritized lemmas which Our lemmatization System 97.32% can be useful for other applications. In addition, we plan to Table 3: Lemmatization accuracy using WikiNews testset plug the lemmatizer into an IR system (Solr for example), and carry out an extrinsic evaluation to evaluate perfor- mance with lemmatization also versus other systems such In terms of speed, our system was able to lemmatize 7.4M as MADAMIRA and Farasa surface stemmer. words on a personal laptop in 2 minutes compared to 2.5 9. Bibliographical References hours for MADAMIRA which does the full morphological analysis and disambiguation, lemmatization, POS tagging, Abdelali, A., Darwish, K., Durrani, N., and Mubarak, H. named entity recognition, and diacritization. (2016). Farasa: A fast and furious segmenter for arabic. In HLT-NAACL Demos, pages 11–16. The code is written entirely in Java without any external Beesley, K. (1996). Arabic finite-state morphological anal- dependency which makes its integration in other systems ysis and generation. In In COLING-96: Proceedings of quite simple. the 16th international, pages 89–94. Buckwalter, T. (2002). Arabic finite-state 3We used text from www.Aljazeera.net which contains 100M morphological analysis and generation. In words (archive of 10 years) http://members.aol.com/ArabicLexicons/.

1131 Figure 3: Summary of lemmatization algorithm

Figure 4: Lemmatization online demo (part of Farasa Arabic NLP tools)

Darwish, K. and Mubarak, H. (2016). Farasa: A new fast arabic root-based lemmatizer for information retrieval and accurate arabic word segmenter. In LREC. purposes. arXiv preprint arXiv:1203.3584. Darwish, K., Mubarak, H., and Abdelali, A. (2017). Ara- Graff, D., Maamouri, M., Bouziri, B., Krouna, S., Kulick, bic diacritization: Stats, rules, and hacks. In Proceedings S., and Buckwalter, T. (2009). Standard arabic morpho- of the Third Arabic Natural Language Processing Work- logical analyzer (sama) version 3.1. In Linguistic Data shop, pages 9–17. Consortium LDC2009E73. Dichy, J. and Fargaly, A. (2003). Roots and patterns vs. Khoja, S. (1999). Stemming arabic text. In Computing De- stems plus grammar-lexis specifications: on what basis partment, Lancaster University. should a multilingual lexical database centred on ara- Pasha, A., Al-Badrashiny, M., Diab, M., El Kholy, A., Es- bic be built? In Proceedings of the MTSummit, New- kander, R., Habash, N., Pooleery, M., Rambow, O., and Orleans. Roth, R. M. (2014). Madamira: A fast, comprehensive El-Shishtawy, T. and Al-Sammak, A. (2009). Arabic tool for morphological analysis and disambiguation of keyphrase extraction using linguistic knowledge and ma- Arabic. Proc. LREC. chine learning techniques. In Proceedings of the Second Plisson, J., Lavrac, N., and Mladenic, M. (2004). A rule International Conference on Arabic Language Resources based approach to word lemmatization. In research- and Tools, The MEDAR Consortium. gate.net. El-Shishtawy, T. and El-Ghannam, F. (2012). An accurate

1132