fill-mask ยท code ยท WASM ยท ~85 MB
BERT learned English by filling in masked words. CodeBERTa โ Hugging Face's
CodeBERT-family model โ learned the same trick on source code: it was pre-trained on
millions of functions across six languages (Go, Java, JavaScript, PHP, Python, Ruby).
Put a <mask> where a token is missing โ a function name, a keyword, an operator โ and
it ranks what belongs there, with the exact logits it computed. Everything runs on your device.
| Model | onnx-community/CodeBERTa-small-v1-ONNX (ONNX of huggingface/CodeBERTa-small-v1) |
|---|---|
| Task / pipeline | fill-mask โ masked language modelling, loaded via AutoModelForMaskedLM for raw logits |
| Trained on | CodeSearchNet โ Go, Java, JavaScript, PHP, Python, Ruby |
| Output | A probability over the whole 52,000-token code vocabulary at each <mask> |
| Architecture | RoBERTa (6 layers, ~84M params), byte-level BPE tokenizer trained on code |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~85 MB, cached after first load |
| License | No explicit license on the card (Hugging Face CodeBERTa; CodeSearchNet data is MIT). Weights are public and ungated. |
| Web APIs | WebAssembly, Web Workers โ all Baseline widely available |
Write code with a <mask> where a token is missing (use the button if unsure).
CodeBERTa predicts the token. Pick a language starter to see it across syntaxes.
Two things make a code language model different. First, the tokenizer: it's a
byte-level BPE trained on code, so self, (), and __init__ are
common single tokens, and a leading space is its own marker (shown as โฃ). Second, the
logits: at the mask, the model produces a raw score for every one of its 52,000 tokens;
we softmax those into the probabilities above. The โ below is the top-k entropy โ
low means CodeBERTa is sure, high means it's hedging between several plausible tokens.
Your snippet, tokenized (โฃ = leading space, dashed = special token):
top-k entropy: โ bits ยท top-1 carries โ of the shown mass
A model that scores every token in code context โ locally, with no prompt and no API bill โ is a surprisingly practical building block. It reads code bidirectionally (both sides of the mask), which is exactly what you want for filling a gap rather than only continuing from the left.
arr.<mask>() and see the calls the model associates with the receiver.One mask, ranked code-token predictions with probabilities and the raw logits behind them.
Code completion hints and API-name suggestion across Python, JavaScript, Java, and more.
Mask obscure syntax and operators, and watch confidence collapse where the model is unsure.
Fill the mask, then use code embeddings to find the most similar snippet in a corpus.
The one-liner uses the fill-mask pipeline:
import { pipeline } from "@huggingface/transformers";
const unmask = await pipeline("fill-mask", "onnx-community/CodeBERTa-small-v1-ONNX");
const out = await unmask("def <mask>(numbers):\n return sum(numbers) / len(numbers)");
// โ [{ token_str: " average", score: 0.09, โฆ }, { token_str: " mean", โฆ }]
For the "see inside" surface we go one level lower โ AutoModelForMaskedLM โ so we can read
the exact logits tensor ([1, sequence, 52000]), slice the row at the
<mask> position, and softmax it ourselves. That's the only way to show the real logit
values, not just the pipeline's rounded scores. All of it runs in a Web Worker so the page never janks.