CoolFace
Modelpublic

nickoo004/queryshield-1.5b

sourceHugging Facemitupdated 5mo agoView on Hugging Face
1likes28downloads
Model Card

QueryShield — Multilingual Prompt Optimizer

QueryShield-1.5B is a fine-tuned version of Qwen2.5-1.5B-Instruct trained to rewrite raw, messy user queries into detailed, structured instruction prompts for downstream LLMs — across 5 languages and 30 professional domains.

Given a raw user question → outputs an expert-level optimized prompt telling a downstream LLM how to answer it.

What it does

Most LLMs perform significantly better when given structured, detailed prompts rather than raw user input. QueryShield sits between the user and the LLM — it takes the raw query and rewrites it into a high-quality instruction prompt automatically.

User: "menga diabetni boshqarish uchun ovqat rejimi ayting"
         ↓  QueryShield
Optimized: "As a Medical Expert, the user is asking in Uzbek about dietary
            management for diabetes with high blood sugar. Provide a structured
            3-tier response covering: diabetes basics, dietary assessment, and
            an actionable meal plan. Respond entirely in Uzbek. Avoid jargon..."
         ↓  Downstream LLM
Final answer in Uzbek ✅

Model Details

PropertyValue
Base modelQwen/Qwen2.5-1.5B-Instruct
Training dataQueryShield Multilingual Dataset
Training rows19,530
Epochs3
Train loss0.88 → 0.47
Eval loss0.967 (best checkpoint)
GPUNVIDIA RTX 3090 24GB
Training time~3.7 hours
Parameters1.5B total / 147M trainable (8.7%)
Live demo▶ Kaggle Notebook

Languages

LanguageCodeSupport
Englishen✅ Full
Uzbekuz✅ Full
Russianru✅ Full
Kazakhkk✅ Full
Karakalpakkaa✅ Good

Cross-lingual scenarios supported — user can write in one language and request output in another (e.g., Uzbek input → Russian output).


Quick Start

python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_id = "nickoo004/queryshield-1.5b"

tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True,
)

SYSTEM = (
    "You are QueryShield, a multilingual prompt optimizer. "
    "Given a raw user question, rewrite it into a detailed instruction "
    "prompt for a downstream LLM expert. "
    "User language: {in_lang}. Response language: {out_lang}. "
    "Expert role: {role}."
)

def optimize_prompt(user_question, input_language, output_language, role):
    messages = [
        {"role": "system", "content": SYSTEM.format(
            in_lang=input_language,
            out_lang=output_language,
            role=role,
        )},
        {"role": "user", "content": user_question},
    ]
    text = tokenizer.apply_chat_template(
        messages, tokenize=False, add_generation_prompt=True
    )
    inputs = tokenizer(text, return_tensors="pt").to(model.device)
    with torch.no_grad():
        output = model.generate(
            **inputs,
            max_new_tokens=512,
            temperature=0.7,
            do_sample=True,
            repetition_penalty=1.1,
            pad_token_id=tokenizer.eos_token_id,
        )
    new_tokens = output[0][inputs["input_ids"].shape[1]:]
    return tokenizer.decode(new_tokens, skip_special_tokens=True)


# Example 1 — Uzbek monolingual
result = optimize_prompt(
    user_question="menga diabetni boshqarish uchun eng yaxshi ovqatlanish rejimini ayting",
    input_language="Uzbek",
    output_language="Uzbek",
    role="Medical Expert",
)
print(result)

# Example 2 — Cross-lingual: Kazakh -> Uzbek
result = optimize_prompt(
    user_question="менің фермамда топырақ сапасы нашар, не істеуім керек?",
    input_language="Kazakh",
    output_language="Uzbek",
    role="Agricultural Scientist",
)
print(result)

Live Demo

[▶ Run on Kaggle](https://www.kaggle.com/code/nursultankoshekbaev/queryshield-1-5b) — no setup needed, free GPU included.

Tests all 7 cases: English, Uzbek, Russian, Kazakh, Karakalpak + 2 cross-lingual pairs.


Supported Domains (30 total)

DomainExpert Role
Software EngineeringSenior Software Engineer
Healthcare & MedicineMedical Expert
Finance & BankingFinancial Analyst
Legal & LawLegal Advisor
Data Science & AIData Scientist
CybersecurityCybersecurity Specialist
Aviation & AerospaceAerospace Engineer
AgricultureAgricultural Scientist
Education & TeachingExperienced Educator
AutomotiveAutomotive Engineer
PharmaceuticalsPharmaceutical Researcher
ManufacturingManufacturing Expert
Civil / Mechanical / Electrical EngineeringDomain Engineer
Business & MarketingBusiness Strategist
Creative WritingProfessional Writer
… and 15 more…

Training Details

Dataset

Loss Curve

Epoch 1.0  ->  train: 1.023  |  eval: 0.997
Epoch 2.5  ->  train: 0.731  |  eval: 0.967  <- best checkpoint

Limitations

  • —Karakalpak support is functional but may be less consistent than other languages due to limited training data for this low-resource language
  • —optimized_prompt output is always structured as an English instruction — this is by design
  • —Best results on domains covered in training data; novel domains may produce generic prompts
  • —Not suitable for harmful, illegal, or unethical query optimization

Citation

bibtex
@model{queryshield_1_5b_2026,
  author    = {nickoo004},
  title     = {QueryShield-1.5B: Multilingual Prompt Optimizer},
  year      = {2026},
  publisher = {Hugging Face},
  url       = {https://huggingface.co/nickoo004/queryshield-1.5b}
}

License

This model is released under the MIT License. Base model license: Qwen License