hyp1231 commited on
Commit
e5d9608
1 Parent(s): cf90b29

Update use example

Browse files
Files changed (1) hide show
  1. README.md +28 -0
README.md CHANGED
@@ -31,6 +31,34 @@ BLaIR is grounded on pairs of *(item metadata, language context)*, enabling the
31
  - **Repository:** [https://github.com/hyp1231/AmazonReviews2023](https://github.com/hyp1231/AmazonReviews2023)
32
  - **Paper:** [https://arxiv.org/abs/2403.03952](https://arxiv.org/abs/2403.03952)
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  ## Citation
35
 
36
  If you find Amazon Reviews 2023 dataset, BLaIR checkpoints, Amazon-C4 dataset, or our scripts/code helpful, please cite the following paper.
 
31
  - **Repository:** [https://github.com/hyp1231/AmazonReviews2023](https://github.com/hyp1231/AmazonReviews2023)
32
  - **Paper:** [https://arxiv.org/abs/2403.03952](https://arxiv.org/abs/2403.03952)
33
 
34
+ ## Use with HuggingFace
35
+
36
+ ```python
37
+ import torch
38
+ from transformers import AutoModel, AutoTokenizer
39
+
40
+
41
+ tokenizer = AutoTokenizer.from_pretrained("hyp1231/blair-roberta-base")
42
+ model = AutoModel.from_pretrained("hyp1231/blair-roberta-base")
43
+
44
+ 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.'
45
+ item_metadata = [
46
+ '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.',
47
+ 'FREETOO Airsoft Gloves Men Tactical Gloves for Hiking Cycling Climbing Outdoor Camping Sports (Not Support Screen Touch).'
48
+ ]
49
+ texts = [language_context] + item_metadata
50
+
51
+ inputs = tokenizer(texts, padding=True, truncation=True, max_length=512, return_tensors="pt")
52
+
53
+ # Get the embeddings
54
+ with torch.no_grad():
55
+ embeddings = model(**inputs, return_dict=True).last_hidden_state[:, 0]
56
+ embeddings = embeddings / embeddings.norm(dim=1, keepdim=True)
57
+
58
+ print(embeddings[0] @ embeddings[1]) # tensor(0.8564)
59
+ print(embeddings[0] @ embeddings[2]) # tensor(0.5741)
60
+ ```
61
+
62
  ## Citation
63
 
64
  If you find Amazon Reviews 2023 dataset, BLaIR checkpoints, Amazon-C4 dataset, or our scripts/code helpful, please cite the following paper.