YellowMIST-Switch-1.0-AR

YellowMIST Switch tells you the language of every word in mixed-language text, such as a message that moves between a local language and English or French mid-sentence. It is a tiny on-device model, one per script or region group. This one covers Arabic-script languages: 23 languages, plus other for numbers, punctuation and symbols.

  • Built on olaverse/YellowMIST-Encoder-15M-AR, a 15M-parameter character encoder, fine-tuned with one label per character and averaged per word.
  • Works on any spelling: it reads characters, so slang, missing tone marks and typos do not break a tokenizer.

Results

Synthetic mixed text (held-out documents)

Mixed text built the same way as the training examples (runs of words and dropped-in words from two languages), from documents never used in training.

  • Word accuracy: 89.9%
  • Switch-point F1 (finding where the language changes): 0.881

Hand-labelled messages

11 short messages written the way people mix languages in chat, mostly a local language with English words dropped in, and a few in one language only. Languages named: the app tells the model which languages the user writes. No hint: any language of the group.

word accuracy switch-point F1 whole message right
languages named 71.2% 0.364 45.5%
no hint 55.8% 0.588 45.5%

The set is small, so treat a few points either way as noise. It is used only as a test.

Real code-switched text (LinCE validation sets)

Word accuracy. Pair-restricted: the answer is limited to the two languages of the pair. Open: any language of the group. The baseline is our LID-608 language identifier run on each word alone.

Pair this model, pair LID-608, pair this model, open LID-608, open
MSA–Egyptian Arabic 77.2% 76.6% 54.8% 50.6%

Training

  • 6,000 steps of 64 examples built from the YellowMIST corpus. Half of the mixed examples are main-language text with one- or two-word islands of another language, mostly Arabic, the commonest real pattern. The rest alternate runs of words between two languages, and 30% of examples are in one language only.
  • Languages are drawn in proportion to the size of their text (to the power 0.3), so very small languages are not guessed as often as large ones.
  • Chat-style noise in training: no punctuation, and lower case where the script has case.
  • All training text comes from the YellowMIST corpus. The LinCE sets are used only as tests and are not stored here.

Use

With the yellowmist library (recommended)

pip install yellowmist        # or: npm install yellowmist
import yellowmist as ym
for w in ym.switch("your mixed text", langs=["arb_Arab", "acm_Arab"], sensitivity=0.5):
    print(w.text, w.lang, round(w.score, 2))
import * as ym from "yellowmist";
await ym.switch("your mixed text", { langs: ["arb_Arab", "acm_Arab"] });
yellowmist switch "your mixed text" --langs arb_Arab,acm_Arab

The library downloads this model the first time it is needed, picks the right region for each language, and runs it with ONNX Runtime on the CPU. Name the languages your user writes (langs): it is far more accurate than choosing among every language of the region. sensitivity (0-1) catches more or fewer switches.

Without the library (ONNX Runtime)

import json, unicodedata, numpy as np, onnxruntime as ort
from huggingface_hub import snapshot_download

d = snapshot_download("olaverse/YellowMIST-Switch-1.0-AR", allow_patterns=["onnx.json", "vocab.json", "model.int8.onnx"])
meta, v = json.load(open(f"{d}/onnx.json")), json.load(open(f"{d}/vocab.json"))
ids = {t: i for i, t in enumerate(v["vocab"])}
labels = meta.get("classes") or v["labels"] + ["other"]          # one output per language, then "other"
sess = ort.InferenceSession(f"{d}/model.int8.onnx")

langs = ["arb_Arab", "acm_Arab"]                                       # the languages this user writes
words = unicodedata.normalize("NFC", "your mixed text").split()    # up to ~250 characters per call
seq, owner = [ids["<eot>"]], [-1]
for k, w in enumerate(words):
    if k: seq.append(ids[" "]); owner.append(-1)
    seq += [ids.get(c, 1) for c in w]; owner += [k] * len(w)
x = np.zeros((1, meta["length"]), np.int64); m = np.zeros((1, meta["length"]), np.float32)
x[0, :len(seq)] = seq; m[0, :len(seq)] = 1
logits = sess.run(None, {"ids": x, "mask": m})[0][0, :len(seq)]
allowed = np.array([0.0 if l in langs or l == "other" else -np.inf for l in labels])
owner = np.array(owner)
for k, w in enumerate(words):
    s = logits[owner == k].mean(0) + allowed
    print(w, labels[int(s.argmax())])

Fine-tune your own

The fine-tuning notebook (open in Colab) walks through continuing pretraining on your own text, fine-tuning a task, exporting to ONNX and sharing it. In short:

from yellowmist import train
import yellowmist as ym

enc = train.Encoder.load("AR")                       # this region's base encoder
model = train.finetune_switch(enc, {"arb_Arab": paragraphs_a, "acm_Arab": paragraphs_b})
model.save("my-model")                           # weights + ONNX, ready for the library
ym.register("switch", "my-model")                        # your model now serves its languages

pip install "yellowmist[train]" for training (PyTorch and Dew).

More: documentation · GitHub · playground · fine-tuning notebook

Limits

  • Real code-switching is messier than spliced text: switches inside a word, borrowed words, and languages outside the group. Expect lower accuracy than the synthetic score.
  • A word that is spelled the same in two languages is ambiguous on its own; context helps, but not always.

Licence

Apache-2.0.

Downloads last month
4
Safetensors
Model size
15M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including olaverse/YellowMIST-Switch-1.0-AR