Downloads · 30 days
39
19% of all-time downloads
timofeyk/roberta-query-router-ecommerce
roberta-query-router-ecommerce is a zero-shot classification model from timofeyk. Use it when you need labels you did not train the model on. It is set up for transformers. The card lists the license as mit.
E-commerce Search Query Router ==============================
Downloads · 30 days
39
19% of all-time downloads
All-time downloads
204
Public
Parameters
125M
499 MB on disk
Likes
3
Public
Click a slice to open those files.
.safetensors499 MB · 99%
From the Hugging Face model README
This model is a classifier fine-tuned from a roberta-base to determine the optimal search strategy for e-commerce queries. It classifies a given query into one of two labels:
lexical_search: Indicates that the query is best handled by a traditional, keyword-based search engine like Lucene using BM25. These are typically specific queries like SKUs, exact product names, or part numbers.
vector_search: Indicates that the query is better suited for a semantic, vector-based search. These are often ambiguous, conceptual, or "long-tail" queries where user intent is more important than specific keywords (e.g., "a gift for my dad who likes fishing").
The model is intended to be used as an intelligent "query router" in a hybrid search system, dynamically weighting the results from lexical and vector search engines to improve relevance.
The primary use case for this model is to power a hybrid search relevance system. The intended workflow is as follows:
lexical_search and vector_search classes.Here's how to use the model with the transformers library pipeline:
from transformers import pipeline
router_pipeline = pipeline(
"text-classification",
model="timofeyk/roberta-query-router-ecommerce",
return_all_scores=True
)
# Example of a conceptual query
conceptual_query = "father day gift"
# Example of a specific query
specific_query = "16x16 pillow cover"
queries = [conceptual_query, specific_query]
for q in queries:
print(f"Predicting label for query: {q}")
results = router_pipeline(q)
print(results[0])
# Expected output might look like:
# [{'label': 'lexical_search', 'score': 0.46258628368377686}, {'label': 'vector_search', 'score': 0.5374137163162231}]
scores = {item['label']: item['score'] for item in results[0]}
w_vector = scores['vector_search']
w_lexical = scores['lexical_search']
print(f"Vector Search Weight: {w_vector:.2f}")
print(f"Lexical Search Weight: {w_lexical:.2f}")
This model was trained on a custom dataset of anonymized, real-world e-commerce queries. The dataset was generated using Amazon ESCI Dataset as a source. The labels were generated programmatically based on search performance, creating a signal for the model to learn from:
lexical_search if Solr achieved a higher nDCG score, and vector_search otherwise.The model was fine-tuned using the Hugging Face Trainer. To account for a potential class imbalance in the training data, a custom Trainer with a weighted CrossEntropyLoss was used, preventing the model from favoring the majority class.
TrainingArguments(
learning_rate=1e-05,
lr_scheduler_type=SchedulerType.COSINE,
max_grad_norm=1.0,
num_train_epochs=3,
optim=OptimizerNames.ADAMW_TORCH_FUSED,
optim_args=None,
per_device_eval_batch_size=128,
per_device_train_batch_size=32,
prediction_loss_only=False,
warmup_ratio=0.05,
weight_decay=0.01,
)
If you use this model in your work, please consider citing it:
@misc{timofeyk_roberta-query-router-ecommerce,
author = {Timofey Klyubin},
title = {E-commerce Search Query Router},
year = {2025},
publisher = {Hugging Face},
journal = {Hugging Face repository},
howpublished = {\url{[https://huggingface.co/timofeyk/roberta-query-router-ecommerce](https://huggingface.co/timofeyk/roberta-query-router-ecommerce)}}
}