Indic Shift 262K

Indic Shift is an Indic-first byte-level BPE tokenizer with exact, reversible script sharing. A small reversible text transform runs before BPE and after decoding: the Brahmic scripts share one set of letter symbols and a marker records the active script, so क, ক, ਕ, ક, କ, க, క, ಕ and ക all become the same symbol and BPE learns word pieces once for several scripts. Decimal digits of every script share ten digit symbols in the same way. Decoding restores the exact original text for every Unicode string, and there are no unknown tokens. It is built for the scheduled languages of India, English and code. This repository holds the 262K tokenizer (262,144 ids).

Install

pip install indic-shift transformers

The tokenizer files ship inside the indic-shift package and are checked against pinned sha256 values when they load. This repository holds the transformers configuration and a small loader file that uses the package.

Usage

With transformers:

from transformers import AutoTokenizer

tok = AutoTokenizer.from_pretrained("chariot-ai/indic-shift-262k", trust_remote_code=True)
ids = tok("আমি বাংলায় কথা বলি")["input_ids"]  # [26162, 211090, 5103, 20496]
tok.decode(ids)  # "আমি বাংলায় কথা বলি"
batch = tok(["नमस्ते दुनिया", "Hello, world"])

To pin the loader code to this release (recommended in production), add revision="v1.0.0": AutoTokenizer.from_pretrained("chariot-ai/indic-shift-262k", trust_remote_code=True, revision="v1.0.0").

trust_remote_code=True is required: without it, loading fails rather than giving a tokenizer with the wrong ids. To load without running code from this repository, use the package's class instead: indic_shift.hf.IndicShiftTokenizer.from_pretrained("chariot-ai/indic-shift-262k"). No BOS, EOS or other special tokens are added. Tokens you add with add_special_tokens get ids after the vocabulary, and the text between them is encoded and decoded run by run. Offsets (return_offsets_mapping) are not supported.

With the indic_shift package directly (same ids):

import indic_shift

tok = indic_shift.load("262k")
ids = tok.encode("আমি বাংলায় কথা বলি")  # [26162, 211090, 5103, 20496]
assert tok.decode(ids) == "আমি বাংলায় কথা বলি"

The leading-space rule

Every encode call is one text run, and the tokenizer adds one space in front of a run that starts with a space or with a letter of a script that separates words with spaces. Encode a document whole, and encode each piece of text between a model's control tokens on its own; see the leading-space rule.

Streaming decode

Decoding is stateful: the active script and the leading space carry over from the start of the run, so slices of ids decoded separately do not join up to the right text. For token-by-token output use StreamDecoder (tok.stream_decoder()); serving stacks with their own windowed detokenizer must decode with its semantics, see streaming decode and SPEC.md.

Two sizes

indic-shift-262k indic-shift-131k
vocabulary 262,144 ids 131,072 ids
suited to larger models small or latency-bound models

The 131K tokenizer is the first part of the 262K: its 131,072 ids are the same tokens in both, its merges are the first merges of the 262K, and both use the same transform. Any 131K id sequence decodes to the same text with either tokenizer.

License

Apache License 2.0 (see LICENSE and NOTICE). The transform tables are derived from the Unicode Character Database and are also covered by the Unicode License V3 (see LICENSE-UNICODE).

Links

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support