Rbin commited on
Commit
b452679
โ€ข
1 Parent(s): 8f671aa

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +91 -3
README.md CHANGED
@@ -1,3 +1,91 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ tags:
6
+ - recommendation
7
+ - collaborative filtering
8
+ ---
9
+
10
+ # EasyRec-Small
11
+
12
+ ## Overview
13
+
14
+ - **Description**: EasyRec is a series of language models designed for recommendations, trained to match the textual profiles of users and items with collaborative signals.
15
+ - **Usage**: You can use EasyRec to encode user and item text embeddings based on the textual profiles that reflect their preferences for various recommendation scenarios.
16
+ - **Evaluation**: We evaluate the performance of EasyRec in: (i) Text-based zero-shot recommendation and (ii) Text-enhanced collaborative filtering.
17
+ - **Finetuned from model:** EasyRec is finetuned from [RoBERTa](https://huggingface.co/FacebookAI/roberta-large) within English.
18
+
19
+ For details please refer to our [๐Ÿ’ป[GitHub Code](https://github.com/HKUDS/EasyRec)] and [๐Ÿ“–[Paper]()].
20
+
21
+ ## Get Started
22
+
23
+ ### Environment
24
+
25
+ Please run the following commands to create a conda environment:
26
+
27
+ ```bash
28
+ conda create -y -n easyrec python=3.11
29
+ pip install torch==2.2.1 torchvision==0.17.1 torchaudio==2.2.1
30
+ pip install -U "transformers==4.40.0" --upgrade
31
+ pip install accelerate==0.28.0
32
+ pip install tqdm
33
+ pip install sentencepiece==0.2.0
34
+ pip install scipy==1.9.3
35
+ pip install setproctitle
36
+ pip install sentence_transformers
37
+ ```
38
+
39
+ ### Example Codes
40
+ Please first download the codes.
41
+ ```ssh
42
+ git clone https://github.com/HKUDS/EasyRec.git
43
+ cd EasyRec
44
+ ```
45
+
46
+ Here is an example code snippet to utilize EasyRec for encoding **text embeddings** based on user and item profiles for recommendations.
47
+
48
+ ```Python
49
+ import torch
50
+ from model import Easyrec
51
+ import torch.nn.functional as F
52
+ from transformers import AutoConfig, AutoModel, AutoTokenizer
53
+
54
+ config = AutoConfig.from_pretrained("hkuds/easyrec-roberta-small")
55
+ model = Easyrec.from_pretrained("hkuds/easyrec-roberta-small", config=config,)
56
+ tokenizer = AutoTokenizer.from_pretrained("hkuds/easyrec-roberta-small", use_fast=False,)
57
+
58
+ profiles = [
59
+ 'This user is a basketball fan and likes to play basketball and watch NBA games.', # user
60
+ 'This basketball draws in NBA enthusiasts.', # item 1
61
+ 'This item is nice for swimming lovers.' # item 2
62
+ ]
63
+
64
+ inputs = tokenizer(profiles, padding=True, truncation=True, max_length=512, return_tensors="pt")
65
+ with torch.inference_mode():
66
+ embeddings = model.encode(input_ids=inputs.input_ids, attention_mask=inputs.attention_mask)
67
+ embeddings = F.normalize(embeddings.pooler_output.detach().float(), dim=-1)
68
+
69
+ print(embeddings[0] @ embeddings[1]) # 0.9260
70
+ print(embeddings[0] @ embeddings[2]) # 0.5834
71
+ ```
72
+
73
+ ### Model List
74
+ We release a series of EasyRec checkpoints with varying sizes. You can easily load these models from Hugging Face by replacing the model name.
75
+ | Model | Model Size | Recall@20 on Amazon-Sports |
76
+ |:-------------------------------|:--------:| :--------:|
77
+ | [hkuds/easyrec-roberta-small](https://huggingface.co/hkuds/easyrec-roberta-small) | 82M | 0.0286 |
78
+ | [hkuds/easyrec-roberta-base](https://huggingface.co/hkuds/easyrec-roberta-base) | 125M | 0.0518 |
79
+ | [hkuds/easyrec-roberta-large](https://huggingface.co/hkuds/easyrec-roberta-large) | 355M | 0.0557 |
80
+
81
+ ## ๐ŸŒŸ Citation
82
+ If you find this work is helpful to your research, please consider citing our paper:
83
+ ```bibtex
84
+ @inproceedings{ren2024easyrec,
85
+ title={EasyRec: Simple yet Effective Language Models for Recommendation},
86
+ author={Ren, Xubin and Huang, Chao},
87
+ journal={arXiv preprint},
88
+ year={2024}
89
+ }
90
+ ```
91
+ **Thanks for your interest in our work!**