text-classification · code · WASM · ~84 MB
Paste or type a code snippet and the model names its programming language across six classes (Go, Java, JavaScript, PHP, Python, Ruby), showing the full confidence ranking. It reads the syntax, not a file extension. Everything runs on your device — the code never leaves the tab.
| Model | onnx-community/CodeBERTa-language-id-ONNX (ONNX build of huggingface/CodeBERTa-language-id) |
|---|---|
| Task / pipeline | text-classification |
| Languages | 6: Go, Java, JavaScript, PHP, Python, Ruby (CodeSearchNet) |
| Architecture | CodeBERTa — a RoBERTa pre-trained on code, fine-tuned for language ID |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~84 MB, cached after first load |
| License | Apache-2.0 |
Type or paste code. The language is scored a moment after you stop typing — or load a sample below.
Detecting a snippet's language — from the code itself, not a filename — is the quiet machinery behind syntax highlighting, gist tagging and code search. Doing it on-device means an editor or docs site can highlight a pasted snippet without shipping the code anywhere.
It knows the six CodeSearchNet languages (Go, Java, JavaScript, PHP, Python, Ruby) and reads syntax, so a very short or ambiguous snippet — a one-liner, or code that looks alike across languages — can be misread (a bare Go one-liner may score as JavaScript). The confidence bars make that visible, and a few real lines are usually all it needs. It will always pick the closest of its six classes, even for a language it doesn't know.
It's one text-classification call on the snippet:
import { pipeline } from "@huggingface/transformers";
const id = await pipeline("text-classification",
"onnx-community/CodeBERTa-language-id-ONNX");
const out = await id(codeSnippet, { top_k: 6 });
// → [{ label: "python", score: 0.99 }, … ]
CodeBERTa tokenises the code with a byte-level BPE trained on source and scores the six languages. It runs in a Web Worker so typing stays smooth.