โ† All models

fill-mask ยท code ยท WASM ยท ~85 MB

CodeBERTa โ€” predict the missing code token

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.

At a glance

Modelonnx-community/CodeBERTa-small-v1-ONNX (ONNX of huggingface/CodeBERTa-small-v1)
Task / pipelinefill-mask โ€” masked language modelling, loaded via AutoModelForMaskedLM for raw logits
Trained onCodeSearchNet โ€” Go, Java, JavaScript, PHP, Python, Ruby
OutputA probability over the whole 52,000-token code vocabulary at each <mask>
ArchitectureRoBERTa (6 layers, ~84M params), byte-level BPE tokenizer trained on code
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~85 MB, cached after first load
LicenseNo explicit license on the card (Hugging Face CodeBERTa; CodeSearchNet data is MIT). Weights are public and ungated.
Web APIsWebAssembly, Web Workers โ€” all Baseline widely available

Run it โ€” mask a code token

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.

See inside โ€” how code tokenizes, and the logits

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):

Why it matters

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.

Use cases

Basics

One mask, ranked code-token predictions with probabilities and the raw logits behind them.

Practical

Code completion hints and API-name suggestion across Python, JavaScript, Java, and more.

Wild

Mask obscure syntax and operators, and watch confidence collapse where the model is unsure.

Multi-model

Fill the mask, then use code embeddings to find the most similar snippet in a corpus.

How the API works

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.

References