Skip to content

Your own models

Use a model you fine-tuned, or a different published one, for any task.

For one call

Pass model= with a Hub repo id or a local folder (Python), or a Hub repo id or a base URL (JavaScript):

ym.punct("e kaaro bawo ni", "yor_Latn", model="you/yellowmist-punct-yor")
ym.switch("Mo fẹ́ go to the market", model="./my-switch", langs=["yor_Latn", "eng_Latn"])
await ym.punct("e kaaro bawo ni", "yor_Latn", { model: "you/yellowmist-punct-yor" });
await ym.switch("Mo fẹ́ go to the market", { model: "https://cdn.example.com/my-switch", langs: ["yor_Latn", "eng_Latn"] });

revision= pins a branch, tag or commit of a Hub repo.

For a set of languages

register makes a model serve its languages from then on, ahead of the built-in models. The languages are read from the model's own files:

ym.register("switch", "./my-switch")
ym.switch("Mo fẹ́ go to the market", langs=["yor_Latn", "eng_Latn"])   # uses ./my-switch
await ym.register("switch", "you/yellowmist-switch-yor-eng");

Fine-tune on your text

pip install "yellowmist[train]"
from yellowmist import train as T

enc = T.Encoder.load("WA")                                  # a region's encoder
enc.add_languages({"xyz_Latn": my_texts})                   # only for a language it has not seen
T.continue_pretraining(enc, {"yor_Latn": yo, "eng_Latn": en}, steps=2000)
sw = T.finetune_switch(enc, {"yor_Latn": yo, "eng_Latn": en}, steps=3000)
sw.save("my-switch")                                        # weights + ONNX export, ready for ym.register
T.push_to_hub("my-switch", "you/yellowmist-switch-yor-eng")

T.finetune_punct(enc, {"yor_Latn": texts}) trains punctuation and capitals the same way. Texts are {language label: [paragraphs]}.

The fine-tuning notebook (open in Colab) walks through the whole thing on a free Colab GPU in about 20 minutes.

More text helps most

Going from 2M to 20M characters per language lifted one of our punctuation models by 7 points on average, and up to 15 for some languages.

Keeping your model private

Your model does not have to be public, or on Hugging Face at all. T.push_to_hub(...) creates a private repo by default; pass private=False only when you want anyone to be able to use it.

Where your code runs How to load a private model
Python (server, desktop, notebook) A private Hub repo id works as is: the library uses your Hugging Face login (huggingface-cli login or the HF_TOKEN environment variable).
Python, no Hugging Face Save the model and point at the folder: ym.register("punct", "./my-punct"). Nothing is uploaded.
Node (server) A private Hub repo id with HF_TOKEN set, or ym.configure({ hfToken }).
Browser or mobile app Host the model's files yourself and pass their base URL (below).

Never put a Hugging Face token in a web page or app

Anyone can read a token shipped to a browser or inside an app, and use it to read, or with a write token change, everything in your account. For code that runs on users' devices, host the files instead.

Hosting the files yourself. Upload the folder model.save(...) wrote, with its file names unchanged, to any web server, CDN or storage bucket, and use its address:

await ym.register("punct", "https://cdn.example.com/my-punct");   // loads https://cdn.example.com/my-punct/<file>

The server must send the files with cross-origin access allowed (CORS, e.g. Access-Control-Allow-Origin for your site), as browsers block downloads from another site otherwise.

To keep the files behind your own sign-in, give the library a fetch that adds your app's credentials for users who are already signed in, for example a short-lived token from your backend:

ym.configure({
  fetch: (url, init) => fetch(url, { ...init, headers: { ...init?.headers, Authorization: `Bearer ${sessionToken}` } }),
});