Views
No views yet
Qwen/Qwen3.5-2B + LoRA adapter, merged via peft.merge_and_unload()) that identifies which programming languages are embedded in a user prompt across 25 languages and configuration formats. This is a self-contained checkpoint — load it directly (no PEFT step) and serve it on vLLM (v0.21.0+). Trained on a combined dataset of Rosetta Code snippets and curated config-language samples (Dockerfile, YAML, Terraform, Makefile, SQL).
The model is fine-tuned to emit a strict JSON object describing the languages found:{"is_valid": true, "category": {"Python": true, "Bash": true}}is_valid is true when at least one code/config snippet is present and false for natural-language-only prompts. category contains only the detected languages, each mapped to true; if no code is present category is {}.Text-only model. The baseQwen/Qwen3.5-2Bdeclares the multimodalQwen3_5ForConditionalGenerationarchitecture (it carries a vision tower in its weights), but this is a text-in / text-out language guard — it never consumes images and only emits the JSON verdict. Send only text prompts; vLLM auto-detects text-only mode and printsAll limits of multimodal modalities ... set to 0, running in text-only modeat startup. (language_model_only=Truewould in theory skip loading the vision-tower weights, but on vLLM v0.21.0 it crashesQwen3_5ForCausalLM.__init__with avision_configattribute error — leave it off until a later vLLM release fixes that path.)
1from vllm import LLM, SamplingParams
2from transformers import AutoTokenizer
3import json, re
4
5MODEL = "Accuknoxtechnologies/CodeLanguage-Qwen3.5-2B-v8"
6SYSTEM_MSG = """You are a code language identifier. For the given user prompt, decide whether it contains any embedded source code (program source or recognizable code-like configuration). Output exactly one JSON object and nothing else: {"is_valid": <true|false>, "category": {"<Lang>": true, ...}}.
7No preamble. No explanation. No <think> tags. No markdown code fences. No trailing prose.
8Rules:
9 - is_valid is TRUE when the prompt contains at least one code/config snippet, FALSE when the prompt is plain natural-language only.
10 - category contains ONLY the languages that appear, each mapped to true. If no code is present, category is the empty object {}.
11 - When multiple languages appear, list every distinct one (still only true).
12Allowed language keys (use these exact spellings):
13 Python, JavaScript, Java, C, C++, C#, Go, Rust, Kotlin, Swift, Ruby, R, Scala, Perl, Lua, Bash, PowerShell, Batch, SQL, Dockerfile, YAML, Makefile, Terraform, AWK, jq"""
14
15llm = LLM(
16 model=MODEL,
17 trust_remote_code=True,
18 dtype="bfloat16",
19 max_model_len=4096,
20 # vLLM auto-detects text-only when no multimodal inputs are sent.
21 # Do NOT pass language_model_only=True here — see the note above.
22)
23tokenizer = AutoTokenizer.from_pretrained(MODEL, trust_remote_code=True)
24sampling = SamplingParams(temperature=0.0, max_tokens=220, stop=["\n\n\n"])
25
26def langid(prompt: str) -> dict:
27 chat = tokenizer.apply_chat_template(
28 [{"role":"system","content":SYSTEM_MSG},
29 {"role":"user","content":prompt}],
30 tokenize=False, add_generation_prompt=True, enable_thinking=False)
31 out = llm.generate([chat], sampling)
32 text = out[0].outputs[0].text
33 return json.loads(re.search(r'\{.*\}', text, re.DOTALL).group(0))1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch, json, re
3
4MODEL = "Accuknoxtechnologies/CodeLanguage-Qwen3.5-2B-v8"
5SYSTEM_MSG = """You are a code language identifier. For the given user prompt, decide whether it contains any embedded source code (program source or recognizable code-like configuration). Output exactly one JSON object and nothing else: {"is_valid": <true|false>, "category": {"<Lang>": true, ...}}.
6No preamble. No explanation. No <think> tags. No markdown code fences. No trailing prose.
7Rules:
8 - is_valid is TRUE when the prompt contains at least one code/config snippet, FALSE when the prompt is plain natural-language only.
9 - category contains ONLY the languages that appear, each mapped to true. If no code is present, category is the empty object {}.
10 - When multiple languages appear, list every distinct one (still only true).
11Allowed language keys (use these exact spellings):
12 Python, JavaScript, Java, C, C++, C#, Go, Rust, Kotlin, Swift, Ruby, R, Scala, Perl, Lua, Bash, PowerShell, Batch, SQL, Dockerfile, YAML, Makefile, Terraform, AWK, jq"""
13
14tokenizer = AutoTokenizer.from_pretrained(MODEL, trust_remote_code=True)
15model = AutoModelForCausalLM.from_pretrained(
16 MODEL, torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True,
17).eval()
18
19def langid(prompt: str) -> dict:
20 chat = tokenizer.apply_chat_template(
21 [{"role":"system","content":SYSTEM_MSG},
22 {"role":"user","content":prompt}],
23 tokenize=False, add_generation_prompt=True, enable_thinking=False)
24 inputs = tokenizer(chat, return_tensors="pt").to(model.device)
25 out = model.generate(**inputs, max_new_tokens=220, do_sample=False)
26 text = tokenizer.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True)
27 return json.loads(re.search(r'\{.*\}', text, re.DOTALL).group(0))1You are a code language identifier. For the given user prompt, decide whether it contains any embedded source code (program source or recognizable code-like configuration). Output exactly one JSON object and nothing else: {"is_valid": <true|false>, "category": {"<Lang>": true, ...}}.
2No preamble. No explanation. No <think> tags. No markdown code fences. No trailing prose.
3Rules:
4 - is_valid is TRUE when the prompt contains at least one code/config snippet, FALSE when the prompt is plain natural-language only.
5 - category contains ONLY the languages that appear, each mapped to true. If no code is present, category is the empty object {}.
6 - When multiple languages appear, list every distinct one (still only true).
7Allowed language keys (use these exact spellings):
8 Python, JavaScript, Java, C, C++, C#, Go, Rust, Kotlin, Swift, Ruby, R, Scala, Perl, Lua, Bash, PowerShell, Batch, SQL, Dockerfile, YAML, Makefile, Terraform, AWK, jqtest_dataset_langid.csv (same single + multi + benign composition as training).2026-05-24 12:53 UTCNVIDIA A10GAccuknoxtechnologies/CodeLanguage-Qwen3.5-2B-v80/200 (0.0%)| Metric | Value |
|---|---|
is_valid accuracy | 1.0000 |
| Language-set exact match | 0.9650 |
| Binary F1 (positive = contains code) | 1.0000 |
| Binary precision | 1.0000 |
| Binary recall | 1.0000 |
| Macro F1 across languages | 0.9701 |
is_valid decisionis_valid=True).| predicted contains-code | predicted no-code | |
|---|---|---|
| actual contains-code | TP = 181 | FN = 0 |
| actual no-code | FP = 0 | TN = 19 |
| Language | support | precision | recall | F1 |
|---|---|---|---|---|
Python | 14 | 1.000 | 1.000 | 1.000 |
Terraform | 14 | 1.000 | 1.000 | 1.000 |
Java | 12 | 1.000 | 0.917 | 0.957 |
C | 12 | 0.857 | 1.000 | 0.923 |
Rust | 12 | 1.000 | 1.000 | 1.000 |
AWK | 12 | 1.000 | 0.917 | 0.957 |
Ruby | 11 | 1.000 | 1.000 | 1.000 |
R | 11 | 0.846 | 1.000 | 0.917 |
Go | 10 | 1.000 | 1.000 | 1.000 |
Swift | 10 | 1.000 | 1.000 | 1.000 |
Scala | 10 | 1.000 | 0.800 | 0.889 |
SQL | 10 | 1.000 | 1.000 | 1.000 |
jq | 10 | 0.909 | 1.000 | 0.952 |
JavaScript | 9 | 0.900 | 1.000 | 0.947 |
Kotlin | 9 | 1.000 | 1.000 | 1.000 |
Perl | 9 | 1.000 | 1.000 | 1.000 |
PowerShell | 9 | 1.000 | 1.000 | 1.000 |
Batch | 9 | 1.000 | 1.000 | 1.000 |
YAML | 9 | 1.000 | 0.889 | 0.941 |
C++ | 7 | 1.000 | 0.857 | 0.923 |
C# | 7 | 1.000 | 1.000 | 1.000 |
Lua | 7 | 1.000 | 0.857 | 0.923 |
Bash | 7 | 1.000 | 1.000 | 1.000 |
Dockerfile | 6 | 0.857 | 1.000 | 0.923 |
Makefile | 6 | 1.000 | 1.000 | 1.000 |
Qwen/Qwen3.5-2B (loaded in full precision (bf16 / fp16, no bitsandbytes quantization))category map of its JSON output:Python, JavaScript, Java, C, C++, C#, Go, Rust, Kotlin, Swift, Ruby, R, Scala, Perl, Lua, Bash, PowerShell, Batch, SQL, Dockerfile, YAML, Makefile, Terraform, AWK, jq0.21.0's native Qwen3.5/Mamba runner instead of the transformers .generate() loop above. Only text prompts are sent; vLLM auto-detects text-only mode. This reflects production serving accuracy + latency.0.21.0, text-only (auto (limit_mm_per_prompt=0)), dtype bf16, greedy decodingNVIDIA A10G0/500 (0.0%)| Metric | Value |
|---|---|
is_valid accuracy | 1.0000 |
| Language-set exact match | 0.9700 |
| Binary F1 (positive = contains code) | 1.0000 |
| Binary precision | 1.0000 |
| Binary recall | 1.0000 |
| Macro F1 across languages | 0.9771 |
is_valid (vLLM)| predicted contains-code | predicted no-code | |
|---|---|---|
| actual contains-code | TP = 450 | FN = 0 |
| actual no-code | FP = 0 | TN = 50 |
| Stat | ms / prompt |
|---|---|
| Mean | 200.0 |
| Median | 186.2 |
| p95 | 278.9 |
| p99 | 343.7 |
| Max | 1990.9 |
| Under 1 s | 99.6% |
eval_and_push_card.py on 2026-05-24 12:53 UTC.