File size: 3,871 Bytes
a5f57c9
 
99c5625
 
 
 
 
 
 
 
b151839
c1c0a49
a5f57c9
8d4aab4
3a73e35
8d4aab4
 
 
3a73e35
8d4aab4
3a73e35
 
 
8d4aab4
3a73e35
8d4aab4
3a73e35
8d4aab4
3a73e35
 
 
 
 
8d4aab4
e5d9608
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a73e35
8d4aab4
3a73e35
8d4aab4
3a73e35
 
 
 
 
 
 
 
8d4aab4
3a73e35
8d4aab4
2c1f89f
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
---
license: mit
datasets:
- McAuley-Lab/Amazon-Reviews-2023
language:
- en
tags:
- recommendation
- information retrieval
- Amazon Reviews 2023
base_model: FacebookAI/roberta-base
pipeline_tag: sentence-similarity
---

# BLaIR-roberta-base

<!-- Provide a quick summary of what the model is/does. -->

BLaIR, which is short for "**B**ridging **La**nguage and **I**tems for **R**etrieval and **R**ecommendation", is a series of language models pre-trained on Amazon Reviews 2023 dataset.

BLaIR is grounded on pairs of *(item metadata, language context)*, enabling the models to:
* derive strong item text representations, for both recommendation and retrieval;
* predict the most relevant item given simple / complex language context.

[[馃搼 Paper](https://arxiv.org/abs/2403.03952)] 路 [[馃捇 Code](https://github.com/hyp1231/AmazonReviews2023)] 路 [[馃寪 Amazon Reviews 2023 Dataset](https://amazon-reviews-2023.github.io/)] 路 [[馃 Huggingface Datasets](https://huggingface.co/datasets/McAuley-Lab/Amazon-Reviews-2023)] 路 [[馃敩 McAuley Lab](https://cseweb.ucsd.edu/~jmcauley/)]

## Model Details

- **Language(s) (NLP):** English
- **License:** MIT
- **Finetuned from model:** [roberta-base](https://huggingface.co/FacebookAI/roberta-base)
- **Repository:** [https://github.com/hyp1231/AmazonReviews2023](https://github.com/hyp1231/AmazonReviews2023)
- **Paper:** [https://arxiv.org/abs/2403.03952](https://arxiv.org/abs/2403.03952)

## Use with HuggingFace

```python
import torch
from transformers import AutoModel, AutoTokenizer


tokenizer = AutoTokenizer.from_pretrained("hyp1231/blair-roberta-base")
model = AutoModel.from_pretrained("hyp1231/blair-roberta-base")

language_context = 'I need a product that can scoop, measure, and rinse grains without the need for multiple utensils and dishes. It would be great if the product has measurements inside and the ability to rinse and drain all in one. I just have to be careful not to pour too much accidentally.'
item_metadata = [
  'Talisman Designs 2-in-1 Measure Rinse & Strain | Holds up to 2 Cups | Food Strainer | Fruit Washing Basket | Strainer & Colander for Kitchen Sink | Dishwasher Safe - Dark Blue. The Measure Rinse & Strain by Talisman Designs is a 2-in-1 kitchen colander and strainer that will measure and rinse up to two cups. Great for any type of food from rice, grains, beans, fruit, vegetables, pasta and more. After measuring, fill with water and swirl to clean. Strain then pour into your pot, pan, or dish. The convenient size is easy to hold with one hand and is compact to fit into a kitchen cabinet or pantry. Dishwasher safe and food safe.',
  'FREETOO Airsoft Gloves Men Tactical Gloves for Hiking Cycling Climbing Outdoor Camping Sports (Not Support Screen Touch).'
]
texts = [language_context] + item_metadata

inputs = tokenizer(texts, padding=True, truncation=True, max_length=512, return_tensors="pt")

# Get the embeddings
with torch.no_grad():
    embeddings = model(**inputs, return_dict=True).last_hidden_state[:, 0]
    embeddings = embeddings / embeddings.norm(dim=1, keepdim=True)

print(embeddings[0] @ embeddings[1])    # tensor(0.8564)
print(embeddings[0] @ embeddings[2])    # tensor(0.5741)
```

## Citation

If you find Amazon Reviews 2023 dataset, BLaIR checkpoints, Amazon-C4 dataset, or our scripts/code helpful, please cite the following paper.

```bibtex
@article{hou2024bridging,
  title={Bridging Language and Items for Retrieval and Recommendation},
  author={Hou, Yupeng and Li, Jiacheng and He, Zhankui and Yan, An and Chen, Xiusi and McAuley, Julian},
  journal={arXiv preprint arXiv:2403.03952},
  year={2024}
}
```

## Contact

Please let us know if you encounter a bug or have any suggestions/questions by [filling an issue](https://github.com/hyp1231/AmazonReview2023/issues/new) or emailing Yupeng Hou at [yphou@ucsd.edu](mailto:yphou@ucsd.edu).