Skip to main content

A simple multilingual lemmatizer for Python.

Project description

Python package License Python versions Travis build status

Lemmatization is the process of grouping together the inflected forms of a word so they can be analysed as a single item, identified by the word’s lemma, or dictionary form. Unlike stemming, lemmatization outputs word units that are still valid linguistic forms.

In modern natural language processing (NLP), this task is often indirectly tackled by more complex systems encompassing a whole processing pipeline. However, it appears that there is no straightforward way to address lemmatization in Python although this task is useful in information retrieval and natural language processing.

Simplemma provides a simple and multilingual approach (currently 22 languages, see list below) to look for base forms or lemmata. It may not be as powerful as full-fledged solutions but it is generic, easy to install and straightforward to use. By design it should be reasonably fast and work in a large majority of cases, without being perfect. With its comparatively small footprint it is especially useful when speed and simplicity matter, for educational purposes or as a baseline system for lemmatization and morphological analysis.

Installation

The current library is written in pure Python with no dependencies:

pip install simplemma (or pip3 where applicable)

Usage

Simplemma is used by selecting a language of interest and then applying the data on a list of words.

>>> import simplemma
# decide which language data to load
>>> langdata = simplemma.load_data('de')
# apply it on a word form
>>> simplemma.lemmatize(myword, langdata)
# grab a list of tokens
>>> mytokens = ['Hier', 'sind', 'Tokens']
>>> for token in mytokens:
>>>     simplemma.lemmatize(token, langdata)
'hier'
'sein'
'tokens'
# list comprehensions can be faster
>>> [simplemma.lemmatize(t, langdata) for t in mytokens]
['hier', 'sein', 'tokens']

Chaining several languages can improve coverage:

>>> langdata = simplemma.load_data('de', 'en')
>>> simplemma.lemmatize('Tokens', langdata)
'token'
>>> langdata = simplemma.load_data('en')
>>> simplemma.lemmatize('spaghetti', langdata)
'spaghetti'
>>> langdata = simplemma.load_data('en', 'it')
>>> simplemma.lemmatize('spaghetti', langdata)
'spaghetto'

There are cases for which a greedier algorithm is better. It is activated by default:

>>> langdata = simplemma.load_data('de')
>>> simplemma.lemmatize('angekündigten', langdata)
'ankündigen' # infinitive verb
>>> simplemma.lemmatize('angekündigten', langdata, greedy=False)
'angekündigt' # past participle

Caveats:

# don't expect too much though
>>> langdata = simplemma.load_data('it')
# this diminutive form isn't in the model data
>>> simplemma.lemmatize('spaghettini', langdata)
'spaghettini' # should read 'spaghettino'

Supported languages

The following languages are available using their ISO 639-1 code:

  • bg: Bulgarian (low coverage)

  • ca: Catalan

  • cs: Czech (low coverage)

  • cy: Welsh

  • de: German (see also this list)

  • en: English (alternative: LemmInflect)

  • es: Spanish

  • fa: Persian (low coverage)

  • fr: French

  • ga: Irish

  • gd. Gaelic

  • gl: Galician

  • gv: Manx

  • hu: Hungarian (low coverage)

  • it: Italian

  • pt: Portuguese

  • ro: Romanian

  • ru: Russian (alternative: pymorphy2)

  • sk: Slovak

  • sl: Slovenian (low coverage)

  • sv: Swedish (alternative: lemmy)

  • uk: Ukranian (alternative: pymorphy2)

Low coverage mentions means you’d probably be better off with a language-specific library, but simplemma will work to a limited extent. Open-source alternatives for Python are referenced if available.

Roadmap

  • [ ] Integrate further lemmatization lists

  • [ ] Function as a meta-package?

  • [ ] Integrate optional, more complex models?

Credits

The current version basically acts as a wrapper for lemmatization lists by Michal Měchura (Open Database License). This rule-based approach based on flexion and lemmatizations dictionaries is to this day an approach used in popular libraries such as spacy.

Contributions

Feel free to contribute, notably by filing issues for feedback, bug reports, or links to further lemmatization lists, rules and tests.

You can also contribute to this lemmatization list repository.

Other solutions

See lists: German-NLP and other awesome-NLP lists.

For a more complex but universal approach in Python see universal-lemmatizer.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simplemma-0.1.0.tar.gz (6.7 kB view hashes)

Uploaded Source

Built Distribution

simplemma-0.1.0-py3-none-any.whl (39.5 MB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page