Skip to content

Repository files navigation

tkseem (تقسيم) is a tokenization library that encapsulates different approaches for tokenization and preprocessing of Arabic text.

Documentation

Please visit readthedocs for the full documentation.

Installation

pip install tkseem

Usage

Tokenization

importtkseemastktokenizer=tk.WordTokenizer()
tokenizer.train('samples/data.txt')
tokenizer.tokenize("السلام عليكم")
tokenizer.encode("السلام عليكم")
tokenizer.decode([536, 829])

Caching

tokenizer.tokenize(open('data/raw/train.txt').read(), use_cache=True)

Save and Load

importtkseemastktokenizer=tk.WordTokenizer()
tokenizer.train('samples/data.txt')
# save the modeltokenizer.save_model('vocab.pl')
# load the modeltokenizer=tk.WordTokenizer()
tokenizer.load_model('vocab.pl')

Model Agnostic

importtkseemastkimporttimeimportseabornassnsimportpandasaspddefcalc_time(fun):
start_time=time.time()
fun().train()
returntime.time() -start_timerunning_times= {}
running_times['Word'] =calc_time(tk.WordTokenizer)
running_times['SP'] =calc_time(tk.SentencePieceTokenizer)
running_times['Random'] =calc_time(tk.RandomTokenizer)
running_times['Disjoint'] =calc_time(tk.DisjointLetterTokenizer)
running_times['Char'] =calc_time(tk.CharacterTokenizer)

Notebooks

We show how to use tkseem to train some nlp models.

NameDescriptionNotebook
DemoExplain the syntax of all tokenizers.
Sentiment Classification WordTokenizer for processing sentences and then train a classifier for sentiment classification.
Meter ClassificationCharacterTokenizer for meter classification using bidirectional GRUs.
TranslationSeq-to-seq model with attention.
Question AnsweringSequence to Sequence Model

Citation

@misc{tkseem2020,
author = {Zaid Alyafeai and Maged Saeed},
title = {tkseem: A Tokenization Library for Arabic.},
year = {2020},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/ARBML/tkseem}}
}

Contribution

This is an open source project where we encourage contributions from the community.

License

MIT license.

About

Arabic Tokenization Library. It provides many tokenization algorithms.

Topics

Resources

Stars

113 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages