Text Ranking
Transformers
Safetensors
English
ProductSearch
File size: 4,419 Bytes
e24382e
 
 
 
77abf4f
b3845f0
e24382e
 
 
 
 
 
 
 
 
 
0d43276
d1092f9
 
 
 
 
 
0d43276
d1092f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
license: cc-by-4.0
datasets:
- J-MADRAL/AmazonESCI
- J-MADRAL/TREC_Product_Search_2023
- J-MADRAL/TrainingData
language:
- en
metrics:
- recall
- trec_eval
base_model:
- google-bert/bert-base-uncased
pipeline_tag: text-ranking
tags:
- ProductSearch
library_name: transformers
---


**P-BiBERT** is a BERT-sized dense retriever initialized from [BERT](https://huggingface.co/google-bert/bert-base-uncased) public checkpoint, 
further pre-trained on e-commerce product data, and fine-tuned on product search retrieval task on the 
[Amazon ESCI](https://huggingface.co/datasets/J-MADRAL/AmazonESCI) dataset. 
It uses a symmetric encoder architecture, with a single shared encoder for both queries and products.
The similarity function is *dot product*.


## Paper and Repository ##

P-BiBERT has been described in the *Multi-Aspect Joint Retrieval for E-Commerce: Bridging Product Catalogs and Customer Reviews* paper. 
The associated GitHub repository is available at [https://anonymous.4open.science/r/J-MADRAL-C4CC](https://anonymous.4open.science/r/J-MADRAL-C4CC).


## Usage (HuggingFace Transformers) ##

Using the model directly in HuggingFace transformers requires additional code available in the [repository](https://anonymous.4open.science/r/J-MADRAL-C4CC).

```python
import modeling
import torch
import transformers

# We use a training query from Amazon ESCI as an example.
queries = [
    "iphone 11 pro max case"
]
products = [
    "OtterBox Symmetry Series Case for iPhone 11 Pro Max - Black [...]",
    "Camera Lens Protector for iPhone 11 Pro/Pro Max, Tempered Glass 9H Hardness Anti-Scratch Camera Screen Protective [...]"
]

# Load the tokenizer and model.
tokenizer = transformers.AutoTokenizer.from_pretrained("J-MADRAL/P-BiBERT")
model = modeling.BiEncoderModel.from_pretrained("J-MADRAL/P-BiBERT")

# Tokenize the input data.
q_input = tokenizer(queries,
                    add_special_tokens=True,
                    truncation=True,
                    padding=True,
                    max_length=128,
                    return_tensors="pt")
p_input = tokenizer(products,
                    add_special_tokens=True,
                    truncation=True,
                    padding=True,
                    max_length=128,
                    return_tensors="pt")

# Compute embeddings: take the "pooled_output".
q_emb = model(**q_input).pooled_output
p_emb = model(**p_input).pooled_output

# Compute similarity scores, using dot product similarity.
scores = torch.matmul(q_emb, p_emb.transpose(0, 1))
```


## Training Hyperparameters ##

Training Stage | Num. Epochs | Learning Rate | AP Scaling Factor | Max Num Tokens | Batch Size | Num Negatives
|---|---|---|---|---|---|---
Pre-training | 20 | 1e-4 | 0.10 | 128 | 64 | ---
Fine-tuning | 20 | 5e-6 | 0.05 | 128 | 64 | 7

The data used for fine-tuning is available at [https://huggingface.co/datasets/J-MADRAL/TrainingData](https://huggingface.co/datasets/J-MADRAL/TrainingData).


## Evaluation Results ##

#### [Amazon ESCI](https://huggingface.co/datasets/J-MADRAL/AmazonESCI) ####

Model | R@100 | R@500 | MRR | nDCG@10 | nDCG@50
|---|---|---|---|---|---
BM25 | 0.4949 | 0.6603 | 0.4056 | 0.2599 | 0.3160
[DRAGON](https://huggingface.co/facebook/dragon-plus-context-encoder) | 0.5490 | 0.7155 | 0.4541 | 0.2929 | 0.3540
**P-BiBERT** | 0.6018 | 0.7640 | 0.4939 | 0.3276 | 0.3967
[P-MADRAL](https://huggingface.co/J-MADRAL/P-MADRAL) | **0.6235** | **0.7806** | **0.5060** | **0.3382** | **0.4104**
[J-BiBERT](https://huggingface.co/J-MADRAL/J-BiBERT) | 0.5889 | 0.7556 | 0.4808 | 0.3195 | 0.3858
[J-MADRAL](https://huggingface.co/J-MADRAL/J-MADRAL) | *0.6083* | *0.7729* | *0.4988* | *0.3330* | *0.4028*

#### [TREC Product Search 2023](https://huggingface.co/datasets/J-MADRAL/TREC_Product_Search_2023) ####

Model | R@100 | R@500 | MRR | nDCG@10 | nDCG@50
|---|---|---|---|---|---
BM25 | 0.7252 | 0.8650 | 0.7746 | 0.6231 | 0.5988
[DRAGON](https://huggingface.co/facebook/dragon-plus-context-encoder) | 0.7373 | 0.8692 | 0.8135 | 0.6526 | 0.6293
**P-BiBERT** | 0.7432 | 0.8757 | 0.8256 | 0.6612 | 0.6287
[P-MADRAL](https://huggingface.co/J-MADRAL/P-MADRAL) | **0.7547** | *0.8840* | **0.8337** | **0.6719** | **0.6480**
[J-BiBERT](https://huggingface.co/J-MADRAL/J-BiBERT) | 0.7432 | 0.8684 | 0.8114 | 0.6487 | 0.6213
[J-MADRAL](https://huggingface.co/J-MADRAL/J-MADRAL) | *0.7527* | **0.8888** | *0.8333* | *0.6702* | *0.6411*