Instructions to use altslate/indic-chat-wordlid-small with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use altslate/indic-chat-wordlid-small with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="altslate/indic-chat-wordlid-small")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForTokenClassification tokenizer = AutoTokenizer.from_pretrained("altslate/indic-chat-wordlid-small") model = AutoModelForTokenClassification.from_pretrained("altslate/indic-chat-wordlid-small", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Indic Chat Word-level Language ID (small)
Labels every word of a chat message with its language: Hindi, Bengali, Tamil, Telugu, Marathi, Gujarati, Kannada, Malayalam, Punjabi, Urdu, Sindhi, Sinhala, English or other (numbers, punctuation, other languages). It works on native script and on romanized text ("kal mere interview tha"), and on messages that mix languages, including two Indian languages in one message:
repu/te chinemaki/te velli/te akkada/te minverva/te mein/hi coffee/hi peene/hi jaate/hi hain/hi → Telugu 50%, Hindi 50%
मुझे/hi कल/hi office/en जाना/hi है,/hi meeting/en cancel/en हो/hi गई/hi → Hindi 67%, English 33%
ente/ml phone/en charge/en theernnu,/ml call/en cheyyam/ml later/en → English 57%, Malayalam 43%
(real model output; English loanwords like office, phone are labelled en, as the human annotators of COMI-LINGUA do)
Try it in your browser: altslate/indic-chat-lid, tick "Per word" (runs locally with transformers.js).
If you only need one label per message, altslate/indic-chat-lid-small is faster; this model is for code-mixed text, where a single label is wrong by construction.
Results
Two tests; no test sentence was used for training or for choosing settings.
1. COMI-LINGUA (human labels, Hindi-English). The LID test split of COMI-LINGUA (4,995 Hinglish sentences from news and social media; gold label = majority of its 3 annotators). The score was fixed before any result: accuracy on Latin-script words whose gold is hi or en (romanized Hindi vs English, the hard part; 32,838 words), and on all hi/en words (97,900). Our labels other than hi/en count as wrong.
| Latin-script hi/en words | all hi/en words | |
|---|---|---|
| PhysicsWallahAI/muril-hinglish-lid (Hindi-English only) | 0.875 | 0.888 |
| this model | 0.904 | 0.899 |
Caveat: this model was trained on COMI-LINGUA's train split (we removed every train sentence that also appears in the test split: about 7,500, so the dataset's own splits overlap); muril-hinglish-lid was not. Without that data (our v1), this model scored only 0.395, because COMI labels English words written next to Devanagari as English, which our other data did not teach.
2. Mixed messages in 12 languages (exact labels). 3,000 messages built only from held-out data: Dakshina's test split (native sentences and human romanizations), held-out English and other-language sentences. Segments are joined into single-language messages, Indian language + English, two Indian languages, and three-way mixes.
| messages | word accuracy | language set of the message exactly right |
|---|---|---|
| all (3,000) | 0.953 | 0.875 |
| with 2 or more languages (1,793) | 0.947–0.964 by mix type | 0.851 |
| two Indian languages | 0.947 | – |
The language set counts languages with at least 20% of a message's words. Word accuracy by language: bn .96, en .98, gu .94, hi .88, kn .97, ml .96, mr .93, pa .94, sd .94, si .97, ta .97, te .94, ur .90, other .99 (Hindi and Urdu are lowest because romanized Hindi and Urdu share most words; see Limitations).
No other open model labels words across these 12 languages or mixes of two Indian languages, so test 2 has no baseline.
Usage
import collections, torch
from transformers import AutoModelForTokenClassification, AutoTokenizer
tok = AutoTokenizer.from_pretrained("altslate/indic-chat-wordlid-small")
model = AutoModelForTokenClassification.from_pretrained("altslate/indic-chat-wordlid-small").eval()
def word_lid(text):
words = text.split()
enc = tok(words, is_split_into_words=True, truncation=True, max_length=512, return_tensors="pt")
with torch.no_grad():
pred = model(**enc).logits[0].argmax(-1).tolist()
labels, prev = {}, None
for pos, wid in enumerate(enc.word_ids()): # one label per word, from its first sub-token
if wid is not None and wid != prev:
labels[wid] = model.config.id2label[pred[pos]]
prev = wid
return [(w, labels[i]) for i, w in enumerate(words)]
def summary(tagged):
# romanized Hindi and Urdu are usually the same words; report them together (see Limitations)
c = collections.Counter("hi/ur" if l in ("hi", "ur") and w.isascii() else l for w, l in tagged if l != "other")
n = sum(c.values()) or 1
return {k: round(v / n, 2) for k, v in c.most_common()}
tagged = word_lid("repu chinemaki velli akkada minverva mein coffee peene jaate hain")
print(tagged, summary(tagged))
Words are split on spaces; feed messages of up to about 100 words (split longer text).
ONNX (onnxruntime, transformers.js)
onnx/model.onnx (fp32, 563 MB) gives the same label as PyTorch for every word we checked (10,737 test-mix words, 19,700 COMI words). onnx/model_quantized.onnx (per-channel dynamic int8, 142 MB) is as accurate on romanized and mixed messages (test-mix word accuracy 0.956 vs 0.957) but loses about 6 points on COMI-LINGUA's Devanagari-heavy news text (0.846 vs 0.900 on the first 1,000 sentences). Other int8 variants (fp32 classifier head, fp32 embeddings) did not help. Use fp32 if your text looks like COMI's.
In transformers.js (tested with 4.3.2 in Node; dtype: "fp32" for the fp32 file):
import { AutoTokenizer, AutoModelForTokenClassification } from "@huggingface/transformers";
const id = "altslate/indic-chat-wordlid-small";
const tok = await AutoTokenizer.from_pretrained(id);
const model = await AutoModelForTokenClassification.from_pretrained(id, { dtype: "q8" });
async function wordLid(text) {
const enc = await tok(text);
const { logits } = await model(enc);
const toks = ["<bos>", ...tok.tokenize(text), "<eos>"]; // a word starts at a token beginning with ▁
const [, T, C] = logits.dims; const out = [];
for (let t = 1; t < T - 1; t++) {
if (toks[t].startsWith("▁") || out.length === 0) {
let best = 0;
for (let c = 1; c < C; c++) if (logits.data[t * C + c] > logits.data[t * C + best]) best = c;
out.push({ word: toks[t].replace(/^▁/, ""), label: model.config.id2label[best] });
} else out[out.length - 1].word += toks[t];
}
return out;
}
console.log(await wordLid("repu chinemaki velli akkada minverva mein coffee peene jaate hain"));
Training
Training and evaluation code: github.com/AltSlate-Labs/indic-chat-toolkit (src/wordlid/, jobs wordlid-*).
- Base: jhu-clsp/mmBERT-small (140M), token classification, label on each word's first sub-token; 2 epochs on 221k messages, batch 32, lr 5e-5, about 25 minutes on one NVIDIA GB10 (DGX Spark).
- Data: messages assembled from labelled segments, so every word's language is known:
- Dakshina (Google, CC BY-SA 4.0): native Wikipedia sentences (train split), human romanizations (dev split), and word-by-word romanizations from the train lexicons;
- romanized chat messages written by Ornith-1.5-35B-A3B (MIT) and Hinglish-Everyday-Conversations-1M (MIT);
- English: wikimedia/wikipedia (CC BY-SA 4.0) and short English commands (Apache-2.0);
other: Wikipedia in 27 other Latin-script languages; - the train split of COMI-LINGUA LID (CC BY 4.0, human hi/en labels), with every sentence that also appears in its test split removed.
- Mixes: 25% single-language, 25% English words inserted into an Indian-language message (half native script, half romanized), 25% two Indian languages, the rest Indian + English segments, three-way mixes, English or other.
- English inside romanized text: a Latin-script word inside a romanized Indian-language segment is labelled
enif it is a common English word that is much more frequent in English Wikipedia than in romanized Indian text, or an English loanword that COMI-LINGUA's annotators labelen(phone, office, meeting, exam). The test labels follow the same rule.
Known limitations
- Romanized Hindi and Urdu are usually written with the same words ("kal mere interview tha"), and the model's choice between them is close to a coin toss on short chat; it often says Urdu for Hinglish. Treat
hianduron Latin-script words as one class (thesummaryabove does). In native script they are separate scripts and reliable. - Loanwords: where a word is English or the Indian language is partly convention. Common loanwords are
en, but some (bike, puncture, coffee) are still labelled with the surrounding language. - Names have no label of their own: they get the language of a nearby word or, in Hindi-English text, often
en(COMI-LINGUA's annotators label Latin-script namesen, and the model learned that from its training split). - Mixed test messages are built by joining segments from different sentences; real code-switching is smoother. Indian-language pairs other than Hindi-English have no human-labelled test here.
- Not checked by native speakers. Not covered: Odia, Assamese, Nepali, Konkani and other Indian languages (labelled as a neighbour or
other).
License
Apache-2.0. Training data licenses as listed above.
- Downloads last month
- 46
Model tree for altslate/indic-chat-wordlid-small
Base model
jhu-clsp/mmBERT-small