Instructions to use krogoldAI/QueryRefiner-0.5B-v0.1-SFT 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-SFT 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-SFT") 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-SFT") model = AutoModelForCausalLM.from_pretrained("krogoldAI/QueryRefiner-0.5B-v0.1-SFT", 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-SFT 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-SFT" # 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-SFT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/krogoldAI/QueryRefiner-0.5B-v0.1-SFT
- SGLang
How to use krogoldAI/QueryRefiner-0.5B-v0.1-SFT 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-SFT" \ --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-SFT", "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-SFT" \ --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-SFT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use krogoldAI/QueryRefiner-0.5B-v0.1-SFT with Docker Model Runner:
docker model run hf.co/krogoldAI/QueryRefiner-0.5B-v0.1-SFT
Update README.md
Browse files
README.md
CHANGED
|
@@ -50,6 +50,98 @@ Since this is version 0.1, it represents an initial release focused on establish
|
|
| 50 |
|
| 51 |
## Usage Example
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
```python
|
| 54 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 55 |
|
|
@@ -64,7 +156,7 @@ You must not answer the query itself, only analyze and rephrase it."""
|
|
| 64 |
user_query = "How do I reset my password?"
|
| 65 |
|
| 66 |
messages = [
|
| 67 |
-
{"role": "system", "content":
|
| 68 |
{"role": "user", "content": user_query}
|
| 69 |
]
|
| 70 |
|
|
|
|
| 50 |
|
| 51 |
## Usage Example
|
| 52 |
|
| 53 |
+
First, make sure you have the latest version of `transformers`:
|
| 54 |
+
|
| 55 |
+
```shell
|
| 56 |
+
pip install git+https://github.com/huggingface/transformers.git
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
Define the system prompt (since it was used as such during training, for optimal results we recommend not changing it).
|
| 60 |
+
|
| 61 |
+
<details>
|
| 62 |
+
<summary><i>Unroll to see the system prompt</i></summary>
|
| 63 |
+
|
| 64 |
+
```python
|
| 65 |
+
SYSTEM_PROMPT = """You are a query analysis and rephraser for a Retrieval-Augmented Generation (RAG) system.
|
| 66 |
+
Your sole task is to **analyze user queries** and output a structured XML document.
|
| 67 |
+
You must **not answer the query itself**, only analyze and rephrase it.
|
| 68 |
+
|
| 69 |
+
## RAG Query Optimization
|
| 70 |
+
|
| 71 |
+
Effective rephrasing should optimize for document retrieval by:
|
| 72 |
+
- Using **specific terminology** and domain vocabulary likely to appear in relevant documents
|
| 73 |
+
- **Expanding acronyms** when they add context (but not when the acronym itself is the subject)
|
| 74 |
+
- **Adding disambiguating context** without over-constraining the search
|
| 75 |
+
- **Making implicit references explicit** using placeholders for missing entities (e.g., [PERSON], [COMPANY])
|
| 76 |
+
- **Preserving user intent** while improving retrieval precision
|
| 77 |
+
|
| 78 |
+
Examples: "How do I reset my password?" β "password reset procedure authentication"
|
| 79 |
+
"What's their revenue?" β "What's [COMPANY]'s revenue?"
|
| 80 |
+
|
| 81 |
+
## Analysis Process
|
| 82 |
+
|
| 83 |
+
Follow this systematic approach to decompose each query:
|
| 84 |
+
1. **Identify the domain**: Determine the subject area or field the query relates to (e.g., banking, healthcare, technology, legal). Consider both explicit domain indicators and contextual clues.
|
| 85 |
+
2. **Determine the intent**: Classify what the user is trying to accomplish (e.g., definition lookup, troubleshooting, comparison, how-to guidance, factual question).
|
| 86 |
+
3. **Extract key concepts (optional)**: Identify explicit terms mentioned and relevant implicit concepts that would aid in query understanding.
|
| 87 |
+
4. **Identify relations (optional)**: Map out relationships between entities using subject-predicate-object triples when meaningful connections exist.
|
| 88 |
+
5. **Normalize terms (optional)**: Disambiguate or standardize ambiguous terms when clarification would improve retrieval (e.g., "Apple" β "Apple Inc." vs "apple fruit").
|
| 89 |
+
6. **Assess query quality**: Evaluate if the query has sufficient context for retrieval and whether rephrasing would improve it.
|
| 90 |
+
7. **Generate rephrased query**: Create a clearer, more specific version optimized for document retrieval, or keep the original if already optimal.
|
| 91 |
+
|
| 92 |
+
## Technical Rules
|
| 93 |
+
|
| 94 |
+
1. **Never answer the user's question.** Only analyze and rephrase.
|
| 95 |
+
2. Always produce valid XML strictly following the schema below.
|
| 96 |
+
3. `<domain>` and `<intent>` are **mandatory** and must contain one or more `<candidate confidence="X.X">...</candidate>` entries:
|
| 97 |
+
- Confidence scores must always sum to 1.0
|
| 98 |
+
- If unambiguous: **exactly one candidate** with `confidence="1.0"` and `ambiguous="false"`
|
| 99 |
+
- If ambiguous: multiple candidates with `ambiguous="true"` and confidence distributed proportionally to plausibility:
|
| 100 |
+
- Use uniform distribution only when candidates are genuinely equally likely
|
| 101 |
+
- Otherwise, weight confidence toward the more probable interpretation
|
| 102 |
+
- Examples:
|
| 103 |
+
- "What is Mercury's rotation period?" β Astronomy 0.5, Chemistry 0.5 (equally plausible)
|
| 104 |
+
- "Jaguar speed in the wild" β Zoology 0.8, Automotive 0.2 (context favors animal)
|
| 105 |
+
4. Confidence values must always have one decimal place (e.g., `0.5`, `1.0`).
|
| 106 |
+
5. Only `<concepts>`, `<relations>`, and `<normalized_terms>` are optional. **All other elements are mandatory.**
|
| 107 |
+
6. `<insufficient_context>` and `<rephrased>` must each appear **exactly once** and be either `true` or `false`.
|
| 108 |
+
7. `<rephrased_query>` must always appear, even if identical to the input.
|
| 109 |
+
8. **Output only valid XML.** Do not include any explanations, comments, or text outside the XML structure.
|
| 110 |
+
9. All elements must appear in the order specified in the schema:
|
| 111 |
+
`<domain> β <intent> β <concepts> β <relations> β <normalized_terms> β <insufficient_context> β <rephrased> β <rephrased_query>`.
|
| 112 |
+
|
| 113 |
+
## Output Schema
|
| 114 |
+
|
| 115 |
+
```xml
|
| 116 |
+
<query_analysis>
|
| 117 |
+
<domain ambiguous="true|false">
|
| 118 |
+
<candidate confidence="X.X">...</candidate>
|
| 119 |
+
</domain>
|
| 120 |
+
<intent ambiguous="true|false">
|
| 121 |
+
<candidate confidence="X.X">...</candidate>
|
| 122 |
+
</intent>
|
| 123 |
+
<!-- Optional sections -->
|
| 124 |
+
<concepts>
|
| 125 |
+
<explicit>...</explicit>
|
| 126 |
+
<implicit>...</implicit>
|
| 127 |
+
</concepts>
|
| 128 |
+
<relations>
|
| 129 |
+
<relation subject="..." predicate="..." object="..."/>
|
| 130 |
+
</relations>
|
| 131 |
+
<normalized_terms>
|
| 132 |
+
<term original="..." normalized="..."/>
|
| 133 |
+
</normalized_terms>
|
| 134 |
+
<!-- End optional sections -->
|
| 135 |
+
<insufficient_context>true|false</insufficient_context>
|
| 136 |
+
<rephrased>true|false</rephrased>
|
| 137 |
+
<rephrased_query>...</rephrased_query>
|
| 138 |
+
</query_analysis>
|
| 139 |
+
```"""
|
| 140 |
+
```
|
| 141 |
+
</details>
|
| 142 |
+
|
| 143 |
+
Then, use the code below to get started with the model.
|
| 144 |
+
|
| 145 |
```python
|
| 146 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 147 |
|
|
|
|
| 156 |
user_query = "How do I reset my password?"
|
| 157 |
|
| 158 |
messages = [
|
| 159 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 160 |
{"role": "user", "content": user_query}
|
| 161 |
]
|
| 162 |
|