Instructions to use krogoldAI/QueryRefiner-0.5B-v0.1-GRPO with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use krogoldAI/QueryRefiner-0.5B-v0.1-GRPO with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="krogoldAI/QueryRefiner-0.5B-v0.1-GRPO") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("krogoldAI/QueryRefiner-0.5B-v0.1-GRPO") model = AutoModelForCausalLM.from_pretrained("krogoldAI/QueryRefiner-0.5B-v0.1-GRPO", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use krogoldAI/QueryRefiner-0.5B-v0.1-GRPO with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "krogoldAI/QueryRefiner-0.5B-v0.1-GRPO" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "krogoldAI/QueryRefiner-0.5B-v0.1-GRPO", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/krogoldAI/QueryRefiner-0.5B-v0.1-GRPO
- SGLang
How to use krogoldAI/QueryRefiner-0.5B-v0.1-GRPO with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "krogoldAI/QueryRefiner-0.5B-v0.1-GRPO" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "krogoldAI/QueryRefiner-0.5B-v0.1-GRPO", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "krogoldAI/QueryRefiner-0.5B-v0.1-GRPO" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "krogoldAI/QueryRefiner-0.5B-v0.1-GRPO", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use krogoldAI/QueryRefiner-0.5B-v0.1-GRPO with Docker Model Runner:
docker model run hf.co/krogoldAI/QueryRefiner-0.5B-v0.1-GRPO
Update README.md
Browse files
README.md
CHANGED
|
@@ -19,7 +19,7 @@ base_model:
|
|
| 19 |
|
| 20 |
QueryRefiner-0.5B-v0.1-GRPO is a specialized query analysis and rephrasing model fine-tuned from [Qwen2.5-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct) for Retrieval-Augmented Generation (RAG) systems. The model has been trained to analyze user queries through a structured, ontology-inspired reasoning framework that produces XML outputs with domain classification, intent detection, conceptual analysis, and optimized query reformulations designed to improve document retrieval precision.
|
| 21 |
|
| 22 |
-
This model
|
| 23 |
|
| 24 |
**Note:** This model is currently in an experimental, beta stage. It represents an initial release focused on establishing baseline capabilities. Future iterations may address current limitations, expand domain coverage, or incorporate additional output features based on real-world deployment feedback.
|
| 25 |
|
|
@@ -131,7 +131,9 @@ Typical deployment scenarios include conversational search systems, question-ans
|
|
| 131 |
|
| 132 |
## Training Data
|
| 133 |
|
| 134 |
-
The model was trained on
|
|
|
|
|
|
|
| 135 |
- [rag-datasets/rag-mini-wikipedia](https://huggingface.co/datasets/rag-datasets/rag-mini-wikipedia)
|
| 136 |
- [razbit96/Ambiguity-Handling-in-User-Queries](https://huggingface.co/datasets/razbit96/Ambiguity-Handling-in-User-Queries)
|
| 137 |
- [glaiveai/RAG-v1](https://huggingface.co/datasets/glaiveai/RAG-v1).
|
|
@@ -140,49 +142,37 @@ Approximately 20% of the training examples include queries with systematically i
|
|
| 140 |
|
| 141 |
The training data underwent rigorous quality assurance through a dual evaluation framework. Each example was validated for strict XML schema conformance and semantically evaluated using an LLM-as-a-judge protocol with six quality dimensions. Only examples achieving both perfect structural validity and high semantic quality scores were included in the final dataset, ensuring the model was trained exclusively on gold-standard examples.
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
## Training Procedure
|
| 144 |
|
| 145 |
-
|
| 146 |
|
| 147 |
-
|
|
|
|
| 148 |
|
| 149 |
-
GRPO
|
| 150 |
|
| 151 |
-
|
| 152 |
-
NUM_EPOCHS = 1
|
| 153 |
-
PER_DEVICE_BATCH = 8
|
| 154 |
-
GRADIENT_ACCUMULATION = 1
|
| 155 |
-
LEARNING_RATE = 5e-6 # Low for GRPO stability
|
| 156 |
-
NUM_GENERATIONS = 2 # Number of generations per prompt for GRPO
|
| 157 |
-
MAX_NEW_TOKENS = 512 # Sufficient for XML output
|
| 158 |
-
WARMUP_STEPS = 50
|
| 159 |
-
```
|
| 160 |
|
| 161 |
-
|
| 162 |
|
| 163 |
-
|
| 164 |
-
NUM_EPOCHS = 2
|
| 165 |
-
PER_DEVICE_BATCH = 4
|
| 166 |
-
GRADIENT_ACCUMULATION = 4
|
| 167 |
-
LEARNING_RATE = 2e-5
|
| 168 |
-
WEIGHT_DECAY = 0.01
|
| 169 |
-
WARMUP_STEPS = 100
|
| 170 |
-
```
|
| 171 |
|
| 172 |
-
|
|
|
|
| 173 |
|
| 174 |
-
|
|
|
|
| 175 |
|
| 176 |
-
|
| 177 |
-
NUM_EPOCHS = 3
|
| 178 |
-
PER_DEVICE_BATCH = 4
|
| 179 |
-
GRADIENT_ACCUMULATION = 4
|
| 180 |
-
LEARNING_RATE = 2e-5
|
| 181 |
-
WEIGHT_DECAY = 0.01
|
| 182 |
-
WARMUP_STEPS = 50
|
| 183 |
-
```
|
| 184 |
|
| 185 |
-
(--> Depth)
|
| 186 |
|
| 187 |
## Model Capabilities
|
| 188 |
|
|
@@ -348,7 +338,7 @@ print(analysis)
|
|
| 348 |
|
| 349 |
### Structural Validation
|
| 350 |
|
| 351 |
-
To assess the model's ability to produce correctly formatted outputs, we evaluated structural conformance across 1,000 examples from the test split of [krogoldAI/rag-ambiguous-queries](https://huggingface.co/datasets/krogoldAI/rag-ambiguous-queries), comparing QueryRefiner-0.5B-v0.1 against
|
| 352 |
|
| 353 |
#### Table 1 - Structural validity metrics (% of outputs meeting each requirement)
|
| 354 |
|
|
@@ -399,8 +389,6 @@ Beyond structural correctness, we evaluated the semantic quality of the model's
|
|
| 399 |
|Overall semantic score|96.10 ± 9.74%|96.45 ± 9.52%|**96.81 ± 9.18%**|
|
| 400 |
-->
|
| 401 |
|
| 402 |
-
(Corrected for the SFT + GRPO-SFT models)
|
| 403 |
-
|
| 404 |
All values are reported as mean ± standard deviation (%), computed over test examples. The base model produced too few valid XML samples for meaningful semantic evaluation.
|
| 405 |
|
| 406 |
<details>
|
|
|
|
| 19 |
|
| 20 |
QueryRefiner-0.5B-v0.1-GRPO is a specialized query analysis and rephrasing model fine-tuned from [Qwen2.5-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct) for Retrieval-Augmented Generation (RAG) systems. The model has been trained to analyze user queries through a structured, ontology-inspired reasoning framework that produces XML outputs with domain classification, intent detection, conceptual analysis, and optimized query reformulations designed to improve document retrieval precision.
|
| 21 |
|
| 22 |
+
This model is part of a two-model series addressing a critical challenge in RAG systems: converting ambiguous, vague, or suboptimally-phrased user queries into retrieval-friendly formats through systematic decomposition and analysis. By employing a structured reasoning approach that explicitly identifies domains, intents, concepts, and relationships, the model produces higher-quality rephrasings informed by comprehensive query understanding. <!-- Rather than directly answering questions, the model performs query understanding and transformation, making it an ideal preprocessing component for information retrieval pipelines. -->
|
| 23 |
|
| 24 |
**Note:** This model is currently in an experimental, beta stage. It represents an initial release focused on establishing baseline capabilities. Future iterations may address current limitations, expand domain coverage, or incorporate additional output features based on real-world deployment feedback.
|
| 25 |
|
|
|
|
| 131 |
|
| 132 |
## Training Data
|
| 133 |
|
| 134 |
+
The model was trained on two complementary datasets totaling approximately 10,000 examples.
|
| 135 |
+
|
| 136 |
+
The primary dataset, [krogoldAI/rag-query-analysis](https://huggingface.co/datasets/krogoldAI/rag-query-analysis), contains 7,305 high-quality query-analysis pairs carefully curated from three sources:
|
| 137 |
- [rag-datasets/rag-mini-wikipedia](https://huggingface.co/datasets/rag-datasets/rag-mini-wikipedia)
|
| 138 |
- [razbit96/Ambiguity-Handling-in-User-Queries](https://huggingface.co/datasets/razbit96/Ambiguity-Handling-in-User-Queries)
|
| 139 |
- [glaiveai/RAG-v1](https://huggingface.co/datasets/glaiveai/RAG-v1).
|
|
|
|
| 142 |
|
| 143 |
The training data underwent rigorous quality assurance through a dual evaluation framework. Each example was validated for strict XML schema conformance and semantically evaluated using an LLM-as-a-judge protocol with six quality dimensions. Only examples achieving both perfect structural validity and high semantic quality scores were included in the final dataset, ensuring the model was trained exclusively on gold-standard examples.
|
| 144 |
|
| 145 |
+
Additionally, the model was trained on 3,000 randomly chosen examples of [krogoldAI/rag-ambiguous-queries](https://huggingface.co/datasets/krogoldAI/rag-ambiguous-queries), a dataset of queries derived designed specifically for the GRPO phase. This dataset includes queries distributed across four ambiguity levels:
|
| 146 |
+
- no ambiguity (45%, original well-formed queries),
|
| 147 |
+
- low ambiguity (30%, minor vagueness from removing one specific detail),
|
| 148 |
+
- medium ambiguity (20%, moderate ambiguity with multiple missing references),
|
| 149 |
+
- high ambiguity (5%, heavy ambiguity with extensive pronoun usage).
|
| 150 |
+
|
| 151 |
+
This stratified distribution ensures the model learns to handle the full spectrum of query ambiguity while being trained primarily on realistic, naturally-occurring query patterns.
|
| 152 |
+
|
| 153 |
## Training Procedure
|
| 154 |
|
| 155 |
+
QueryRefiner-0.5B-v0.1-GRPO underwent a sophisticated three-phase training procedure combining reinforcement learning with two-stage supervised fine-tuning, all using full parameter updates (not parameter-efficient methods like LoRA) on [Qwen2.5-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct).
|
| 156 |
|
| 157 |
+
### Phase 1: Reinforcement Learning with GRPO
|
| 158 |
+
The model was first trained using Group Relative Policy Optimization (GRPO) on 3,000 examples from [krogoldAI/rag-ambiguous-queries](https://huggingface.co/datasets/krogoldAI/rag-ambiguous-queries) for 1 epoch with a learning rate of 5e-6 (intentionally low for GRPO stability). This phase focused on learning correct XML structure and formatting before semantic refinement.
|
| 159 |
|
| 160 |
+
The GRPO reward function evaluated outputs through a weighted combination of five components: tag structure (30%), XML validity (25%), element ordering (25%), confidence formatting (18%), and confidence distribution (2%). The structure component verified the presence of all required XML elements, while validity ensured parseability. The ordering component checked that tags appeared in the correct sequence, and the confidence component validated that confidence values were properly formatted and summed to 1.0 for ambiguous cases.
|
| 161 |
|
| 162 |
+
The confidence distribution component used normalized entropy to encourage balanced probability distributions in ambiguous classifications, computed as:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
+
$-\frac{1}{\log n}\sum_{j=1}^n p_j \log p_j$
|
| 165 |
|
| 166 |
+
where \\( (p_j)_{1\leq j\leq n} \\) are the confidence scores, \\( n \\) is the number of confidence scores, and \\( \log n \\) represents the maximum possible entropy. This penalizes overly skewed distributions (e.g., 0.9/0.1 splits) in favor of more balanced confidence allocations when multiple interpretations are plausible. Additional penalties were applied for structural issues (missing attributes) and for outputs that attempted to answer queries rather than analyze them.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
+
### Phase 2: Breadth-Focused Supervised Fine-Tuning
|
| 169 |
+
Following structural learning through GRPO, the model underwent supervised fine-tuning on the complete [krogoldAI/rag-query-analysis](https://huggingface.co/datasets/krogoldAI/rag-query-analysis) dataset (7,305 examples) for 2 epochs with a learning rate of 2e-5. This phase captured broad semantic patterns across diverse query types and domains.
|
| 170 |
|
| 171 |
+
### Phase 3: Depth-Focused Supervised Fine-Tuning
|
| 172 |
+
The final phase focused on precision refinement using only the highest-quality 3,660 examples from [krogoldAI/rag-query-analysis](https://huggingface.co/datasets/krogoldAI/rag-query-analysis), i.e., those examples where the judge LLM assigned perfect scores. This "polish" phase was trained for 3 epochs with a learning rate of 2e-5 to maximize learning from gold-standard examples.
|
| 173 |
|
| 174 |
+
This progressive training approach ensures the model achieves both reliable formatting and nuanced semantic understanding. All training was performed on an NVIDIA A100 SXM GPU.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
|
|
|
| 176 |
|
| 177 |
## Model Capabilities
|
| 178 |
|
|
|
|
| 338 |
|
| 339 |
### Structural Validation
|
| 340 |
|
| 341 |
+
To assess the model's ability to produce correctly formatted outputs, we evaluated structural conformance across 1,000 examples from the test split of [krogoldAI/rag-ambiguous-queries](https://huggingface.co/datasets/krogoldAI/rag-ambiguous-queries), comparing both QueryRefiner-0.5B-v0.1 models against their base model [Qwen2.5-0.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct). The evaluation measured adherence to the required XML schema, including tag presence, well-formedness, element ordering, and confidence score formatting.
|
| 342 |
|
| 343 |
#### Table 1 - Structural validity metrics (% of outputs meeting each requirement)
|
| 344 |
|
|
|
|
| 389 |
|Overall semantic score|96.10 ± 9.74%|96.45 ± 9.52%|**96.81 ± 9.18%**|
|
| 390 |
-->
|
| 391 |
|
|
|
|
|
|
|
| 392 |
All values are reported as mean ± standard deviation (%), computed over test examples. The base model produced too few valid XML samples for meaningful semantic evaluation.
|
| 393 |
|
| 394 |
<details>
|