Upload folder using huggingface_hub
Browse files- README.md +121 -3
- config.json +34 -0
- merges.txt +0 -0
- model.safetensors +3 -0
- special_tokens_map.json +15 -0
- tokenizer.json +0 -0
- tokenizer_config.json +58 -0
- vocab.json +0 -0
README.md
CHANGED
|
@@ -1,3 +1,121 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
tags:
|
| 6 |
+
- roberta
|
| 7 |
+
- ecommerce
|
| 8 |
+
- classification
|
| 9 |
+
datasets:
|
| 10 |
+
- "amazon-esci"
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
E-commerce Search Query Router
|
| 14 |
+
==============================
|
| 15 |
+
|
| 16 |
+
Model Description
|
| 17 |
+
-----------------
|
| 18 |
+
|
| 19 |
+
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:
|
| 20 |
+
|
| 21 |
+
- **`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.
|
| 22 |
+
|
| 23 |
+
- **`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").
|
| 24 |
+
|
| 25 |
+
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.
|
| 26 |
+
|
| 27 |
+
Intended Use & Use Case
|
| 28 |
+
-----------------------
|
| 29 |
+
|
| 30 |
+
The primary use case for this model is to power a hybrid search relevance system. The intended workflow is as follows:
|
| 31 |
+
|
| 32 |
+
1. A user enters a search query.
|
| 33 |
+
2. The query is sent to this classifier model.
|
| 34 |
+
3. The model returns probabilities for the `lexical_search` and `vector_search` classes.
|
| 35 |
+
4. These probabilities are used as weights to blend the relevance scores from two separate search backends (e.g., Solr and Qdrant).
|
| 36 |
+
5. The final, blended scores are used to rank the products shown to the user.
|
| 37 |
+
|
| 38 |
+
### How to Use
|
| 39 |
+
|
| 40 |
+
Here's how to use the model with the `transformers` library `pipeline`:
|
| 41 |
+
|
| 42 |
+
```python
|
| 43 |
+
from transformers import pipeline
|
| 44 |
+
|
| 45 |
+
router_pipeline = pipeline(
|
| 46 |
+
"text-classification",
|
| 47 |
+
model="timofeyk/roberta-query-router-ecommerce",
|
| 48 |
+
return_all_scores=True
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# Example of a conceptual query
|
| 52 |
+
conceptual_query = "father day gift"
|
| 53 |
+
# Example of a specific query
|
| 54 |
+
specific_query = "16x16 pillow cover"
|
| 55 |
+
|
| 56 |
+
queries = [conceptual_query, specific_query]
|
| 57 |
+
|
| 58 |
+
for q in queries:
|
| 59 |
+
print(f"Predicting label for query: {q}")
|
| 60 |
+
results = router_pipeline(q)
|
| 61 |
+
print(results[0])
|
| 62 |
+
# Expected output might look like:
|
| 63 |
+
# [{'label': 'lexical_search', 'score': 0.46258628368377686}, {'label': 'vector_search', 'score': 0.5374137163162231}]
|
| 64 |
+
|
| 65 |
+
scores = {item['label']: item['score'] for item in results[0]}
|
| 66 |
+
w_vector = scores['vector_search']
|
| 67 |
+
w_lexical = scores['lexical_search']
|
| 68 |
+
|
| 69 |
+
print(f"Vector Search Weight: {w_vector:.2f}")
|
| 70 |
+
print(f"Lexical Search Weight: {w_lexical:.2f}")
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
Training Data
|
| 76 |
+
-------------
|
| 77 |
+
|
| 78 |
+
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:
|
| 79 |
+
|
| 80 |
+
1. A large set of user queries and their corresponding ground-truth "ideal" product results (based on user engagement) were collected.
|
| 81 |
+
2. Each query was executed against both a Solr (lexical) and a Qdrant (vector) search engine.
|
| 82 |
+
3. The **nDCG** relevance score was calculated for both result sets against the ground truth.
|
| 83 |
+
4. The query was labeled `lexical_search` if Solr achieved a higher nDCG score, and `vector_search` otherwise.
|
| 84 |
+
|
| 85 |
+
Training Procedure
|
| 86 |
+
------------------
|
| 87 |
+
|
| 88 |
+
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.
|
| 89 |
+
|
| 90 |
+
### Training params
|
| 91 |
+
```
|
| 92 |
+
TrainingArguments(
|
| 93 |
+
learning_rate=1e-05,
|
| 94 |
+
lr_scheduler_type=SchedulerType.COSINE,
|
| 95 |
+
max_grad_norm=1.0,
|
| 96 |
+
num_train_epochs=3,
|
| 97 |
+
optim=OptimizerNames.ADAMW_TORCH_FUSED,
|
| 98 |
+
optim_args=None,
|
| 99 |
+
per_device_eval_batch_size=128,
|
| 100 |
+
per_device_train_batch_size=32,
|
| 101 |
+
prediction_loss_only=False,
|
| 102 |
+
warmup_ratio=0.05,
|
| 103 |
+
weight_decay=0.01,
|
| 104 |
+
)
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
Citation
|
| 108 |
+
--------
|
| 109 |
+
|
| 110 |
+
If you use this model in your work, please consider citing it:
|
| 111 |
+
|
| 112 |
+
```
|
| 113 |
+
@misc{timofeyk_roberta-query-router-ecommerce,
|
| 114 |
+
author = {Timofey Klyubin},
|
| 115 |
+
title = {E-commerce Search Query Router},
|
| 116 |
+
year = {2025},
|
| 117 |
+
publisher = {Hugging Face},
|
| 118 |
+
journal = {Hugging Face repository},
|
| 119 |
+
howpublished = {\url{[https://huggingface.co/](https://huggingface.co/)timofeyk/roberta-query-router-ecommerce}}
|
| 120 |
+
}
|
| 121 |
+
```
|
config.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"RobertaForSequenceClassification"
|
| 4 |
+
],
|
| 5 |
+
"attention_probs_dropout_prob": 0.1,
|
| 6 |
+
"bos_token_id": 0,
|
| 7 |
+
"classifier_dropout": null,
|
| 8 |
+
"eos_token_id": 2,
|
| 9 |
+
"hidden_act": "gelu",
|
| 10 |
+
"hidden_dropout_prob": 0.1,
|
| 11 |
+
"hidden_size": 768,
|
| 12 |
+
"id2label": {
|
| 13 |
+
"0": "lexical_search",
|
| 14 |
+
"1": "vector_search"
|
| 15 |
+
},
|
| 16 |
+
"initializer_range": 0.02,
|
| 17 |
+
"intermediate_size": 3072,
|
| 18 |
+
"label2id": {
|
| 19 |
+
"lexical_search": 0,
|
| 20 |
+
"vector_search": 1
|
| 21 |
+
},
|
| 22 |
+
"layer_norm_eps": 1e-05,
|
| 23 |
+
"max_position_embeddings": 514,
|
| 24 |
+
"model_type": "roberta",
|
| 25 |
+
"num_attention_heads": 12,
|
| 26 |
+
"num_hidden_layers": 12,
|
| 27 |
+
"pad_token_id": 1,
|
| 28 |
+
"position_embedding_type": "absolute",
|
| 29 |
+
"torch_dtype": "float32",
|
| 30 |
+
"transformers_version": "4.55.2",
|
| 31 |
+
"type_vocab_size": 1,
|
| 32 |
+
"use_cache": true,
|
| 33 |
+
"vocab_size": 50265
|
| 34 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b62fd473c727dfa9b249b4868d55728e0c3594a3377a31ca2a26f4a7c47daed8
|
| 3 |
+
size 498612824
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "<s>",
|
| 3 |
+
"cls_token": "<s>",
|
| 4 |
+
"eos_token": "</s>",
|
| 5 |
+
"mask_token": {
|
| 6 |
+
"content": "<mask>",
|
| 7 |
+
"lstrip": true,
|
| 8 |
+
"normalized": false,
|
| 9 |
+
"rstrip": false,
|
| 10 |
+
"single_word": false
|
| 11 |
+
},
|
| 12 |
+
"pad_token": "<pad>",
|
| 13 |
+
"sep_token": "</s>",
|
| 14 |
+
"unk_token": "<unk>"
|
| 15 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"added_tokens_decoder": {
|
| 4 |
+
"0": {
|
| 5 |
+
"content": "<s>",
|
| 6 |
+
"lstrip": false,
|
| 7 |
+
"normalized": true,
|
| 8 |
+
"rstrip": false,
|
| 9 |
+
"single_word": false,
|
| 10 |
+
"special": true
|
| 11 |
+
},
|
| 12 |
+
"1": {
|
| 13 |
+
"content": "<pad>",
|
| 14 |
+
"lstrip": false,
|
| 15 |
+
"normalized": true,
|
| 16 |
+
"rstrip": false,
|
| 17 |
+
"single_word": false,
|
| 18 |
+
"special": true
|
| 19 |
+
},
|
| 20 |
+
"2": {
|
| 21 |
+
"content": "</s>",
|
| 22 |
+
"lstrip": false,
|
| 23 |
+
"normalized": true,
|
| 24 |
+
"rstrip": false,
|
| 25 |
+
"single_word": false,
|
| 26 |
+
"special": true
|
| 27 |
+
},
|
| 28 |
+
"3": {
|
| 29 |
+
"content": "<unk>",
|
| 30 |
+
"lstrip": false,
|
| 31 |
+
"normalized": true,
|
| 32 |
+
"rstrip": false,
|
| 33 |
+
"single_word": false,
|
| 34 |
+
"special": true
|
| 35 |
+
},
|
| 36 |
+
"50264": {
|
| 37 |
+
"content": "<mask>",
|
| 38 |
+
"lstrip": true,
|
| 39 |
+
"normalized": false,
|
| 40 |
+
"rstrip": false,
|
| 41 |
+
"single_word": false,
|
| 42 |
+
"special": true
|
| 43 |
+
}
|
| 44 |
+
},
|
| 45 |
+
"bos_token": "<s>",
|
| 46 |
+
"clean_up_tokenization_spaces": false,
|
| 47 |
+
"cls_token": "<s>",
|
| 48 |
+
"eos_token": "</s>",
|
| 49 |
+
"errors": "replace",
|
| 50 |
+
"extra_special_tokens": {},
|
| 51 |
+
"mask_token": "<mask>",
|
| 52 |
+
"model_max_length": 512,
|
| 53 |
+
"pad_token": "<pad>",
|
| 54 |
+
"sep_token": "</s>",
|
| 55 |
+
"tokenizer_class": "RobertaTokenizer",
|
| 56 |
+
"trim_offsets": true,
|
| 57 |
+
"unk_token": "<unk>"
|
| 58 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|