Skip to main content

A Transformer-based Natural Language Processing Pipeline for Greek

Project description

gr-nlp-toolkit

A Transformer-based natural language processing toolkit for (modern) Greek. The toolkit has state-of-the-art performance in Greek and supports:

  1. Named Entity Recognition (NER)
  2. Part-of-Speech Tagging (POS Tagging)
  3. Morphological tagging
  4. Dependency parsing
  5. Greeklish to Greek transliteration

Installation

We support Python 3.9+.

You can install the toolkit from PyPI by executing the following in the command line:

pip install gr-nlp-toolkit

Usage

Available Processors

To use the toolkit, first initialize a Pipeline specifying which processors you need. Each processor annotates the text with a specific task's annotations.

  • To obtain Part-of-Speech and Morphological Tagging annotations, add the pos processor
  • To obtain Named Entity Recognition annotations, add the ner processor
  • To obtain Dependency Parsing annotations, add the dp processor
  • To enable the transliteration from Greeklish to Greek, add the g2g processor or the g2g_lite processor for a lighter but less accurate model (Greeklish to Greek transliteration example: "thessalonikh" -> "θεσσαλονίκη")

Example Usage Scenarios

  • DP, POS, NER processors (input text in Greek)

    nlp = Pipeline("pos,ner,dp")  # Instantiate the Pipeline with the DP, POS and NER processors
    doc = nlp("Η Ιταλία κέρδισε την Αγγλία στον τελικό του Euro 2020.") # Apply the pipeline to a sentence in Greek
    

    A Document object is created and is annotated. The original text is tokenized and split to tokens

    # Iterate over the generated tokens
    for token in doc.tokens:
      print(token.text) # the text of the token
    
      print(token.ner) # the named entity label in IOBES encoding : str
    
      print(token.upos) # the UPOS tag of the token
      print(token.feats) # the morphological features for the token
    
      print(token.head) # the head of the token
      print(token.deprel) # the dependency relation between the current token and its head
    

    token.ner is set by the ner processor, token.upos and token.feats are set by the pos processor and token.head and token.deprel are set by the dp processor.

    A small detail is that to get the Token object that is the head of another token you need to access doc.tokens[head-1]. The reason for this is that the enumeration of the tokens starts from 1 and when the field token.head is set to 0, that means the token is the root of the word.

  • Greeklish to Greek Conversion (input text in Greeklish)

    from gr_nlp_toolkit import Pipeline
    nlp  = Pipeline("g2g")  # Instantiate the pipeline with the g2g processor
    
    doc = nlp("O Volos kai h Larisa einai sth Thessalia") # Apply the pipeline to a sentence in Greeklish
    print(doc.text) # Access the transliterated text, which is "ο Βόλος και η Λάρισα είναι στη Θεσσαλία"
    
  • Use all the processors together (input text in Greeklish)

    nlp = Pipeline("pos,ner,dp,g2g")  # Instantiate the Pipeline with the G2G, DP, POS and NER processors
    
    doc = nlp("O Volos kai h Larisa einai sthn Thessalia") # Apply the pipeline to a sentence in Greeklish
    
    print(doc.text) # Print the transliterated text
    
    # Iterate over the generated tokens
    for token in doc.tokens:
      print(token.text) # the text of the token
    
      print(token.ner) # the named entity label in IOBES encoding : str
    
      print(token.upos) # the UPOS tag of the token
      print(token.feats) # the morphological features for the token
    
      print(token.head) # the head of the token
      print(token.deprel) # the dependency relation between the current token and its head
    

Notes:

  • The first time you use a processor, the models are downloaded from Hugging Face and stored into the .cache folder. The NER, DP and POS processors are each about 500 MB, while the G2G processor is about 1.2 GB in size.
  • If the input text is already in Greek, the G2G (Greeklish-to-Greek) processor is skipped.
  • If your machine has an accelerator but you want to run the process on the CPU, you can pass the flag use_cpu=True to the Pipeline object. By default, use_cpu is set to False.

Hugging Face related repositories

References

C. Dikonimaki, "A Transformer-based natural language processing toolkit for Greek -- Part of speech tagging and dependency parsing", BSc thesis, Department of Informatics, Athens University of Economics and Business, 2021. http://nlp.cs.aueb.gr/theses/dikonimaki_bsc_thesis.pdf

N. Smyrnioudis, "A Transformer-based natural language processing toolkit for Greek -- Named entity recognition and multi-task learning", BSc thesis, Department of Informatics, Athens University of Economics and Business, 2021. http://nlp.cs.aueb.gr/theses/smyrnioudis_bsc_thesis.pdf

Toumazatos, A., Pavlopoulos, J., Androutsopoulos, I., & Vassos, S. (2024). Still All Greeklish to Me: Greeklish to Greek Transliteration. In Proceedings of the 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation (LREC-COLING 2024) (pp. 15309–15319).

https://aclanthology.org/2024.lrec-main.1330/

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

gr_nlp_toolkit-0.1.5.tar.gz (4.4 MB view details)

Uploaded Source

Built Distribution

gr_nlp_toolkit-0.1.5-py3-none-any.whl (4.4 MB view details)

Uploaded Python 3

File details

Details for the file gr_nlp_toolkit-0.1.5.tar.gz.

File metadata

  • Download URL: gr_nlp_toolkit-0.1.5.tar.gz
  • Upload date:
  • Size: 4.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for gr_nlp_toolkit-0.1.5.tar.gz
Algorithm Hash digest
SHA256 63a11c4248034aa55146218d3a56476ff156f28d71e69975cf553f4ccf27f61e
MD5 9d3830da2bab7b052e5a246751823375
BLAKE2b-256 c1ac50c5c93cff243b85e63642629d2c3aba9e48049a4c173ade1740cb1ad0dc

See more details on using hashes here.

File details

Details for the file gr_nlp_toolkit-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for gr_nlp_toolkit-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 decd89d8ef5d3a9c60f2571bed48415c56f2f66680a83487ac033a4f28cc6daa
MD5 854ca967825257eae0a15f17b59642f1
BLAKE2b-256 cf308f38e16bdf797a0467d4a6b9471852e75ed143b46edc99d8f4697182eb39

See more details on using hashes here.

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