Downloads · 30 days
72
37% of all-time downloads
mudasir13cs/E-commerce-query-rewriter-gguf
E-commerce-query-rewriter-gguf is a machine learning model from mudasir13cs. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
This repository contains GGUF format models for efficient inference with llama.cpp.
Downloads · 30 days
72
37% of all-time downloads
All-time downloads
196
Public
Repo size
13.6 GB
Likes
1
Public
Click a slice to open those files.
.gguf13.6 GB · 100%
From the Hugging Face model README
This repository contains GGUF format models for efficient inference with llama.cpp.
Note: This is the GGUF (quantized) version of the model. For the full HuggingFace format model, see the merged model repository.
unsloth/Qwen2.5-3B-InstructThe model was fine-tuned on a custom e-commerce dataset containing:
Total: ~10,000 examples from real e-commerce product data (Flipkart, Amazon, Okayhai).
This repository contains multiple quantization levels:
# Clone llama.cpp
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
mkdir build && cd build
cmake .. -DGGML_CUDA=ON
cmake --build . --config Release -j
# Using llama-cli
./llama.cpp/build/bin/llama-cli \
-m path/to/query-rewriter-q4_k_m.gguf \
-p "Context:
Previous search: Smartphones
State: SEARCH_RESULTS
Last command: show_list
Products (6): iPhone 15 Pro, Samsung Galaxy S24, OnePlus 12, Google Pixel 8, Xiaomi 14, Nothing Phone 2
Product count: 6
Query: show me that one"
# Using llama-server (for API access)
./llama.cpp/build/bin/llama-server \
-m path/to/query-rewriter-q4_k_m.gguf \
--port 8080
from llama_cpp import Llama
# Load model
llm = Llama(
model_path="path/to/query-rewriter-q4_k_m.gguf",
n_ctx=2048, # Context window
n_threads=4 # Number of CPU threads
)
# Prepare prompt (ChatML format)
prompt = '<|im_start|>system\nRewrite the ambiguous query using the provided context to make it clear and searchable. Resolve pronouns, ellipsis, ordinals, and other ambiguous references using the context information.<|im_end|>\n<|im_start|>user\nContext:\nPrevious search: Smartphones\nState: SEARCH_RESULTS\nLast command: show_list\nProducts (6): iPhone 15 Pro, Samsung Galaxy S24, OnePlus 12, Google Pixel 8, Xiaomi 14, Nothing Phone 2\nProduct count: 6\n\nQuery: show me that one<|im_end|>\n<|im_start|>assistant\nshow me details of iPhone 15 Pro from Smartphones search<|im_end|>'
# Generate
response = llm(
prompt,
max_tokens=128,
temperature=0.7,
stop=["<|im_end|>", "<|im_start|>"]
)
print(response['choices'][0]['text'])
Option 1: Using Modelfile (Recommended)
Modelfile:FROM ./query-rewriter-q4_k_m.gguf
TEMPLATE '<|im_start|>system\nRewrite the ambiguous query using the provided context to make it clear and searchable. Resolve pronouns, ellipsis, ordinals, and other ambiguous references using the context information.<|im_end|>\n<|im_start|>user\nContext:\nPrevious search: Smartphones\nState: SEARCH_RESULTS\nLast command: show_list\nProducts (6): iPhone 15 Pro, Samsung Galaxy S24, OnePlus 12, Google Pixel 8, Xiaomi 14, Nothing Phone 2\nProduct count: 6\n\nQuery: show me that one<|im_end|>\n<|im_start|>assistant\nshow me details of iPhone 15 Pro from Smartphones search<|im_end|>'
PARAMETER temperature 0.7
PARAMETER num_predict 128
PARAMETER stop "<|im_end|>"
PARAMETER stop "<|im_start|>"
ollama create query-rewriter -f Modelfile
Option 2: Direct Import
# Import GGUF file directly
ollama import query-rewriter-q4_k_m.gguf
# Command line
ollama run query-rewriter "Context:
Previous search: Smartphones
State: SEARCH_RESULTS
Last command: show_list
Products (6): iPhone 15 Pro, Samsung Galaxy S24, OnePlus 12, Google Pixel 8, Xiaomi 14, Nothing Phone 2
Product count: 6
Query: show me that one"
# With context
ollama run query-rewriter "Context: Previous search: Smartphones\nQuery: show me that one"
import requests
# Generate
response = requests.post(
"http://localhost:11434/api/generate",
json={
"model": "query-rewriter",
"prompt": "Context:
Previous search: Smartphones
State: SEARCH_RESULTS
Last command: show_list
Products (6): iPhone 15 Pro, Samsung Galaxy S24, OnePlus 12, Google Pixel 8, Xiaomi 14, Nothing Phone 2
Product count: 6
Query: show me that one",
"stream": False,
"options": {
"temperature": 0.7,
"num_predict": 128,
"stop": ["<|im_end|>", "<|im_start|>"]
}
}
)
print(response.json()["response"])
import requests
response = requests.post(
"http://localhost:11434/api/chat",
json={
"model": "query-rewriter",
"messages": [
{"role": "system", "content": "Rewrite the ambiguous query using the provided context to make it clear and searchable. Resolve pronouns, ellipsis, ordinals, and other ambiguous references using the context information."},
{"role": "user", "content": "Context:
Previous search: Smartphones
State: SEARCH_RESULTS
Last command: show_list
Products (6): iPhone 15 Pro, Samsung Galaxy S24, OnePlus 12, Google Pixel 8, Xiaomi 14, Nothing Phone 2
Product count: 6
Query: show me that one"}
],
"stream": False
}
)
print(response.json()["message"]["content"])
Note: vLLM works best with HuggingFace format models. Use the merged model instead of GGUF.
pip install vllm
from vllm import LLM, SamplingParams
# Load merged model (not GGUF)
llm = LLM(
model="USERNAME/E-commerce-query-rewriter",
trust_remote_code=True,
max_model_len=2048
)
# Prepare prompt
prompt = '<|im_start|>system\nRewrite the ambiguous query using the provided context to make it clear and searchable. Resolve pronouns, ellipsis, ordinals, and other ambiguous references using the context information.<|im_end|>\n<|im_start|>user\nContext:\nPrevious search: Smartphones\nState: SEARCH_RESULTS\nLast command: show_list\nProducts (6): iPhone 15 Pro, Samsung Galaxy S24, OnePlus 12, Google Pixel 8, Xiaomi 14, Nothing Phone 2\nProduct count: 6\n\nQuery: show me that one<|im_end|>\n<|im_start|>assistant\nshow me details of iPhone 15 Pro from Smartphones search<|im_end|>'
# Sampling parameters
sampling_params = SamplingParams(
temperature=0.7,
max_tokens=128,
stop=["<|im_end|>", "<|im_start|>"]
)
# Generate
outputs = llm.generate([prompt], sampling_params)
print(outputs[0].outputs[0].text)
# Start server
python -m vllm.entrypoints.openai.api_server \
--model USERNAME/E-commerce-query-rewriter \
--trust-remote-code \
--port 8000
# Use OpenAI-compatible API
curl http://localhost:8000/v1/completions \
-H "Content-Type: application/json" \
-d '{
"model": "query-rewriter",
"prompt": "Context:
Previous search: Smartphones
State: SEARCH_RESULTS
Last command: show_list
Products (6): iPhone 15 Pro, Samsung Galaxy S24, OnePlus 12, Google Pixel 8, Xiaomi 14, Nothing Phone 2
Product count: 6
Query: show me that one",
"max_tokens": 128,
"temperature": 0.7
}'
Note: TGI works with HuggingFace format models. Use the merged model.
# Using Docker (recommended)
docker pull ghcr.io/huggingface/text-generation-inference:latest
docker run --gpus all \
-p 8080:80 \
-v /path/to/model:/data \
ghcr.io/huggingface/text-generation-inference:latest \
--model-id USERNAME/E-commerce-query-rewriter \
--trust-remote-code
from text_generation import Client
client = Client("http://localhost:8080")
response = client.generate(
prompt='<|im_start|>system\nRewrite the ambiguous query using the provided context to make it clear and searchable. Resolve pronouns, ellipsis, ordinals, and other ambiguous references using the context information.<|im_end|>\n<|im_start|>user\nContext:\nPrevious search: Smartphones\nState: SEARCH_RESULTS\nLast command: show_list\nProducts (6): iPhone 15 Pro, Samsung Galaxy S24, OnePlus 12, Google Pixel 8, Xiaomi 14, Nothing Phone 2\nProduct count: 6\n\nQuery: show me that one<|im_end|>\n<|im_start|>assistant\nshow me details of iPhone 15 Pro from Smartphones search<|im_end|>',
max_new_tokens=128,
temperature=0.7,
stop_sequences=["<|im_end|>", "<|im_start|>"]
)
print(response.generated_text)
Note: Use the merged HuggingFace model for Transformers.
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load merged model
model = AutoModelForCausalLM.from_pretrained(
"USERNAME/E-commerce-query-rewriter",
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(
"USERNAME/E-commerce-query-rewriter",
trust_remote_code=True
)
# Prepare input
messages = [
{"role": "system", "content": "Rewrite the ambiguous query using the provided context to make it clear and searchable. Resolve pronouns, ellipsis, ordinals, and other ambiguous references using the context information."},
{"role": "user", "content": "Context:
Previous search: Smartphones
State: SEARCH_RESULTS
Last command: show_list
Products (6): iPhone 15 Pro, Samsung Galaxy S24, OnePlus 12, Google Pixel 8, Xiaomi 14, Nothing Phone 2
Product count: 6
Query: show me that one"}
]
# Apply chat template
prompt = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
# Generate
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=128,
temperature=0.7,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
# Decode
response = tokenizer.decode(
outputs[0][inputs.input_ids.shape[1]:],
skip_special_tokens=True
)
print(response)
The model uses ChatML format (Qwen2.5's native format):
<|im_start|>system
Rewrite the ambiguous query using the provided context to make it clear and searchable. Resolve pronouns, ellipsis, ordinals, and other ambiguous references using the context information.<|im_end|>
<|im_start|>user
Context:
Previous search: Smartphones
State: SEARCH_RESULTS
Last command: show_list
Products (6): iPhone 15 Pro, Samsung Galaxy S24, OnePlus 12, Google Pixel 8, Xiaomi 14, Nothing Phone 2
Product count: 6
Query: show me that one<|im_end|>
<|im_start|>assistant
show me details of iPhone 15 Pro from Smartphones search<|im_end|>
System Message:
Rewrite the ambiguous query using the provided context to make it clear and searchable. Resolve pronouns, ellipsis, ordinals, and other ambiguous references using the context information.
User Message (Context + Query):
Context:
Previous search: [category]
State: [SEARCH_RESULTS|PRODUCT_DETAIL|INITIAL]
Last command: [show_list|show_item|go_back|close]
Products (N): [product1, product2, ...]
Product count: N
Query: [user query]
Expected Output:
show me details of iPhone 15 Pro from Smartphones search
Example 1: Pronoun Resolution
Context:
Previous search: Smartphones
State: SEARCH_RESULTS
Last command: show_list
Products (6): iPhone 15 Pro, Samsung Galaxy S24, OnePlus 12, Google Pixel 8, Xiaomi 14, Nothing Phone 2
Product count: 6
Query: show me that one
Example 2: Ellipsis Expansion
Context:
Previous search: Laptops
State: SEARCH_RESULTS
Last command: show_list
Products (5): MacBook Pro, Dell XPS, HP Spectre, Lenovo ThinkPad, ASUS ZenBook
Product count: 5
Query: under 50000
Example 3: Ordinal Reference
Context:
Previous search: Headphones
State: SEARCH_RESULTS
Last command: show_list
Products (4): Sony WH-1000XM5, Bose QuietComfort, AirPods Max, Sennheiser Momentum
Product count: 4
Query: show me the second one
| Format | Size | Quality | Use Case |
|---|---|---|---|
| f16 | ~6GB | Best | Maximum quality, sufficient VRAM |
| q8_0 | ~3.5GB | Excellent | High quality, moderate VRAM |
| q5_k_m | ~2.5GB | Very Good | Balanced quality/size |
| q4_k_m | ~2GB | Good | Smallest size, limited VRAM |
Download the desired quantization level:
# Using huggingface-cli
huggingface-cli download USERNAME/E-commerce-query-rewriter-gguf \
query-rewriter-q4_k_m.gguf \
--local-dir ./models
# Or download all formats
huggingface-cli download USERNAME/E-commerce-query-rewriter-gguf \
--local-dir ./models
Merged Model (HuggingFace Format): USERNAME/E-commerce-query-rewriter
Original LoRA Adapter: See merged model repository for LoRA adapter details
| Backend | Format | Best For | Pros | Cons |
|---|---|---|---|---|
| llama.cpp | GGUF | CPU/GPU inference, edge devices | Fast, low memory, cross-platform | Limited to GGUF format |
| Ollama | GGUF | Local development, easy deployment | Simple API, auto-manages models | Requires model import |
| vLLM | HF | High-throughput serving | Very fast, batching support | Requires HF format, more memory |
| TGI | HF | Production serving | Optimized serving, Docker support | Requires HF format |
| Transformers | HF | Research, fine-tuning | Full flexibility, easy integration | Slower inference, more memory |
If you use this model, please cite:
@software{ecommerce_agent_models,
title = {E-commerce Agent Models - Query Rewriter},
author = {Syed Mudasir},
year = {2025},
url = {https://huggingface.co/USERNAME/E-commerce-query-rewriter-gguf}
}
Apache 2.0