← All models

text-classification · code · WASM · ~84 MB

Code language ID — which language is this snippet?

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.

At a glance

Modelonnx-community/CodeBERTa-language-id-ONNX (ONNX build of huggingface/CodeBERTa-language-id)
Task / pipelinetext-classification
Languages6: Go, Java, JavaScript, PHP, Python, Ruby (CodeSearchNet)
ArchitectureCodeBERTa — a RoBERTa pre-trained on code, fine-tuned for language ID
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~84 MB, cached after first load
LicenseApache-2.0

Run it

Type or paste code. The language is scored a moment after you stop typing — or load a sample below.

Why it matters

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.

How the API works

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.

References