Package: trankit
Trankit: A Light-Weight Transformer-based Python Toolkit for Multilingual Natural Language ProcessingOur technical paperfor Trankit won the Outstanding Demo Paper Award atEACL 2021. Please cite the paper if you use Trankit in your research.@inproceedings{nguyen2021trankit,title={Trankit: A Light-Weight Transformer-based Toolkit for Multilingual Natural Language Processing},author={Nguyen, Minh Van and Lai, Viet Dac and Veyseh, Amir Pouran Ben and Nguyen, Thien Huu},booktitle="Proceedings of the 16th Conference of the European Chapter of the Association for Computational Linguistics: System Demonstrations",year={2021}}:boom: :boom: :boom: Trankit v1.0.0 is out:90 new pretrained transformer-based pipelines for 56 languages. The new pipelines are trained with XLM-Roberta large, which further boosts the performance significantly over 90 treebanks of the Universal Dependencies v2.5 corpus. Check out the new performancehere. Thispageshows you how to use the new pipelines.Auto Mode for multilingual pipelines. In the Auto Mode, the language of the input will be automatically detected, enabling the multilingual pipelines to process the input without specifying its language. Check out how to turn on the Auto Modehere. Thank youloretoparisifor your suggestion on this.Command-line interfaceis now available to use. This helps users who are not familiar with Python programming language use Trankit easily. Check out the tutorials on thispage.Trankit is alight-weight Transformer-based PythonToolkit for multilingual Natural Language Processing (NLP). It provides a trainable pipeline for fundamental NLP tasks over100 languages, and 90downloadablepretrained pipelines for56 languages.Trankit outperforms the current state-of-the-art multilingual toolkit Stanza (StanfordNLP)in many tasks over90 Universal Dependencies v2.5 treebanks of 56 different languageswhile still being efficient in memory usage and
speed, making itusable for general users.In particular, forEnglish,Trankit is significantly better than Stanzaon sentence segmentation (+9.36%) and dependency parsing (+5.07%for UAS and+5.81%for LAS). ForArabic, our toolkit substantially improves sentence segmentation performance by16.36%whileChineseobserves14.50%and15.00%improvement of UAS and LAS for dependency parsing. Detailed comparison between Trankit, Stanza, and other popular NLP toolkits (i.e., spaCy, UDPipe) in other languages can be foundhereonour documentation page.We also created a Demo Website for Trankit, which is hosted at:http://nlp.uoregon.edu/trankitInstallationTrankit can be easily installed via one of the following methods:Using pippip install trankitThe command would install Trankit and all dependent packages automatically.From sourcegit clone https://github.com/nlp-uoregon/trankit.git
cd trankit
pip install -e .This would first clone our github repo and install Trankit.Fixing the compatibility issue of Trankit with TransformersPrevious versions of Trankit have encountered thecompatibility issuewhen using recent versions oftransformers. To fix this issue, please install the new version of Trankit as follows:pip install trankit==1.1.0If you encounter any other problem with the installation, please raise an issuehereto let us know. Thanks.UsageTrankit can process inputs which are untokenized (raw) or pretokenized strings, at
both sentence and document level. Currently, Trankit supports the following tasks:Sentence segmentation.Tokenization.Multi-word token expansion.Part-of-speech tagging.Morphological feature tagging.Dependency parsing.Named entity recognition.Initialize a pretrained pipelineThe following code shows how to initialize a pretrained pipeline for English; it is instructed to run on GPU, automatically download pretrained models, and store them to the specified cache directory. Trankit will not download pretrained models if they already exist.fromtrankitimportPipeline# initialize a multilingual pipelinep=Pipeline(lang='english',gpu=True,cache_dir='./cache')Perform all tasks on the inputAfter initializing a pretrained pipeline, it can be used to process the input on all tasks as shown below. If the input is a sentence, the tagis_sentmust be set to True.fromtrankitimportPipelinep=Pipeline(lang='english',gpu=True,cache_dir='./cache')######## document-level processing ########untokenized_doc='''Hello! This is Trankit.'''pretokenized_doc=[['Hello','!'],['This','is','Trankit','.']]# perform all tasks on the inputprocessed_doc1=p(untokenized_doc)processed_doc2=p(pretokenized_doc)######## sentence-level processing #######untokenized_sent='''This is Trankit.'''pretokenized_sent=['This','is','Trankit','.']# perform all tasks on the inputprocessed_sent1=p(untokenized_sent,is_sent=True)processed_sent2=p(pretokenized_sent,is_sent=True)Note that, although pretokenized inputs can always be processed, using pretokenized inputs for languages that require multi-word token expansion such as Arabic or French might not be the correct way. Please check out the columnRequires MWT expansion?ofthis tableto see if a particular language requires multi-word token expansion or not.For more detailed examples, please check out ourdocumentation page.Multilingual usageStarting from version v1.0.0, Trankit supports a handyAuto Modein which users do not have to set a particular language active before processing the input. In the Auto Mode, Trankit will automatically detect the language of the input and use the corresponding language-specific models, thus avoiding switching back and forth between languages in a multilingual pipeline.fromtrankitimportPipelinep=Pipeline('auto')# Tokenizing an English inputen_output=p.tokenize('''I figured I would put it out there anyways.''')# POS, Morphological tagging and Dependency parsing a French inputfr_output=p.posdep('''On pourra toujours parler à propos d'Averroès de "décentrement du Sujet".''')# NER tagging a Vietnamese inputvi_output=p.ner('''Cuộc tiêm thử nghiệm tiến hành tại Học viện Quân y, Hà Nội''')In this example, the code name'auto'is used to initialize a multilingual pipeline in the Auto Mode. For more information, please visitthis page. Note that, besides the new Auto Mode, themanual modecan still be used as before.Building a customized pipelineTraining customized pipelines is easy with Trankit via the classTPipeline. Below we show how we can train a token and sentence splitter on customized data.fromtrankitimportTPipelinetp=TPipeline(training_config={'task':'tokenize','save_dir':'./saved_model','train_txt_fpath':'./train.txt','train_conllu_fpath':'./train.conllu','dev_txt_fpath':'./dev.txt','dev_conllu_fpath':'./dev.conllu'})trainer.train()Detailed guidelines for training and loading a customized pipeline can be foundhereSharing your customized pipelinesIn case you want to share your customized pipelines with other users. Please create an issuehereand provide us the following information:Training data that you used to train your models, e.g., data license, data source, and some data statistics (i.e., sizes of training, development, and test data).Performance of your pipelines on your test data using the officialevaluation script.A downloadable link to your trained model files (a Google drive link would be great).
After we receive your request, we will check and test your pipelines. Once everything is done, we would make the pipelines accessible by other users via new language codes.AcknowledgementsThis project has been supported by the Office of the Director of National Intelligence (ODNI), Intelligence Advanced Research Projects Activity (IARPA), via IARPA Contract No. 2019-19051600006 under theBetter Extraction from Text Towards Enhanced Retrieval (BETTER) Program.We useXLM-RobertaandAdaptersas our shared multilingual encoder for different tasks and languages. TheAdapterHubis used to implement our plug-and-play mechanism with Adapters. To speed up the development process, the implementations for the MWT expander and the lemmatizer are adapted fromStanza. To implement the language detection module, we leverage thelangidlibrary.