Update README.md
Browse files
README.md
CHANGED
@@ -10,3 +10,32 @@ Provides a relevance score for a given search query and a product (with title an
|
|
10 |
Can be used as retriever/ranker for e-commerce search.
|
11 |
|
12 |
Development details coming soon.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
Can be used as retriever/ranker for e-commerce search.
|
11 |
|
12 |
Development details coming soon.
|
13 |
+
|
14 |
+
## How to use the model
|
15 |
+
```python
|
16 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
17 |
+
import torch
|
18 |
+
import torch.nn.functional as F
|
19 |
+
|
20 |
+
|
21 |
+
MODEL_ID = "prhegde/query-product-relevance-model-ecommerce"
|
22 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
23 |
+
model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID)
|
24 |
+
|
25 |
+
query_text = "sofa with ottoman"
|
26 |
+
prod_text = "daryl 82 '' wide reversible sofa & chaise with ottoman"
|
27 |
+
|
28 |
+
tok_output = tokenizer(query_text, prod_text, padding='max_length',
|
29 |
+
max_length=160, truncation=True, return_tensors='pt',
|
30 |
+
return_attention_mask=True)
|
31 |
+
|
32 |
+
input_ids = tok_output.input_ids
|
33 |
+
attention_masks = tok_output.attention_mask
|
34 |
+
token_type_ids = tok_output.token_type_ids
|
35 |
+
|
36 |
+
output = model(input_ids, attention_mask = attention_masks,
|
37 |
+
token_type_ids = token_type_ids)
|
38 |
+
probs = F.softmax(output.logits, dim=-1)
|
39 |
+
score = probs[0][1].item()
|
40 |
+
print(score)
|
41 |
+
|