Skip to main content

PyPI - Version PyPI - Status PyPI - Format PyPI - Types Pepy Total Downloads PyPI - License GitHub commit activity

SLTK: A Comprehensive Tokenizer for Sinhala Language

Welcome to the GitHub repository for SLTK, a powerful tokenizer designed to enhance Sinhala Natural Language Processing (NLP) tasks. SLTK implements Grapheme Pair Encoding for tokenizing. Although our first SLTK version was implemented using our own research, this is implemented inspired by the research paper by Velayuthan et al. (2024).

[!NOTE] Read more about SLTK here>>>

Installation

To install SLTK, run following command:

pip install sltkpy

Usage

You can train the tokenizer on a custom dataset to create your own vabulary and use it to tokenize your text data. First, import SLTK:

from sltkpy import GPETokenizer

Now initialize the tokenizer:

tokenizer = GPETokenizer()

Train new vocab

To train a new vocab, provide corpus to the train method. Additionally you can provide the maximum size of vocab to vocab_size and the minimum frequency for a pair to be qualified as a vocab by setting min_freq.

vocab = tokenizer.train(corpus=corpus, vocab_size=3000)

Note: Default value of min_freq is 3.

Once the training is finished, the method will return the vocab as a dictionary. You can save it as a JSON file to use it in future.

Load vocab

There are two ways to load vocab to the tokenizer. Either you can use your own vocab or you can load the pre-trained vocab available within the SLTK library. It is trained on Wikipedia Sinhala Dataset on Huggingface Datasets.

  1. Load pre-trained vocab:
tokenizer.pre_load()
  1. Load your own trained vocab:
tokenizer.load_vocab('<path_to_your_vocab>.json')

Tokenize text

Once you have loaded vocab using any method above, you can tokenize your text as follows:

tokens = tokenizer.tokenize('ශ්‍රී ලංකාව සිලෝන් ලෙස ද හැඳින් වේ.')

Encode tokens

To encode tokens, use following method:

encoded_tokens = tokenizer.encode(tokens)

Decode tokens

To decode tokens, use the following method:

decoded_text = tokenizer.decode(encoded_tokens)

Metadata

Release files for sltkpy 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sltkpy 1.0.0
File Size Uploaded
sltkpy-1.0.0.tar.gz 101.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sltkpy 1.0.0
File Interpreter ABI Platform
sltkpy-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 294.3 kB

Release files / sltkpy-1.0.0.tar.gz

Download URL sltkpy-1.0.0.tar.gz
Size 101.7 kB
Tags Source
SHA-256 checksum
How to use checksums
47528a7e5c7779b6dd1a2733a8608824ae82c5fae08f89ebdc57061bee8a61d8
BLAKE2b-256 checksum
How to use checksums
2c7d2e230fddb316874f48f0bd1ff3669492de890485b5cf46bccb2fa61f6aeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release files / sltkpy-1.0.0-py3-none-any.whl

Download URL sltkpy-1.0.0-py3-none-any.whl
Size 192.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
73752eea7861e886b847d6e2da00bb402b32b1e1863821581d83fff7e4e0f445
BLAKE2b-256 checksum
How to use checksums
cdcc95faa2fad0fb61646909d77b2cf4729341897d5ef364d89cbcdabb180779
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.1

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page