Giter Site home page Giter Site logo

rainym00d / llm4rs Goto Github PK

View Code? Open in Web Editor NEW
150.0 4.0 14.0 3.51 MB

the official implementation of the RecSys 2023 paper “Uncovering ChatGPT's Capabilities in Recommender Systems”

Home Page: https://arxiv.org/abs/2305.02182

Python 39.91% Jupyter Notebook 60.09%
chatgpt information-retrieval large-language-model learn-to-rank recommendation recommender-system llm rs

llm4rs's Introduction

Overview

This is the official implementation of RecSys2023 paper "Uncovering ChatGPT's Capabilities in Recommender Systems". [arXiv]

Abstract: The debut of ChatGPT has recently attracted the attention of the natural language processing community and beyond. Existing studies have demonstrated that ChatGPT shows significant improvement in a range of downstream NLP tasks, but the capabilities and limitations of ChatGPT in terms of recommendations remain unclear. In this study, we aim to conduct an empirical analysis of ChatGPT's recommendation ability from an Information Retrieval (IR) perspective, including point-wise, pair-wise, and list-wise ranking. To achieve this goal, we re-formulate the above three recommendation policies into a domain-specific prompt format. Through extensive experiments on four datasets from different domains, we demonstrate that ChatGPT outperforms other large language models across all three ranking policies. Based on the analysis of unit cost improvements, we identify that ChatGPT with list-wise ranking achieves the best trade-off between cost and performance compared to point-wise and pair-wise ranking. Moreover, ChatGPT shows the potential for mitigating the cold start problem and explainable recommendation.

The overall evaluation framework of LLMs for recommendation tasks is depicted as follows:

The main result of different LLMs on four different domain datasets is presented as follows:

Quick Start

  • For details of datasets, please check file data/readme.md.

  • For details of related work & more experimental results, please check file assets/Supplemental_Material.pdf.

  • For details of prompts, please check file assets/prompts.pdf.

  • For details of original results, please download from here

File Structure

.
├── data  # * data path
│   ├── Book
│   ├── Movie
│   ├── Music
│   ├── News
│   └── preprocess  # * folder of jupyter notbooks for pre-processing original dataset
├── result  # * folder to save requests、responses、results、logs
├── script  # * folder to save scripts
└── src  # * source codes
    ├── api  # * codes to access api
    ├── postprocess  # * codes for data post-processing
    └── preprocess  # * codes for data pre-processing

Usage

  1. Clone this repo.

    git clone https://github.com/rainym00d/LLM4RS.git
    
  2. Download pre-processed data from here. And then put them into data folder. (If you want to use your own data, you can check the origin dataset link in data/readme.md and refer to our preprocess code in data/preprocess.)

  3. Edit the parameters in the script/run.py according to your own needs. (This code can be executed in batches, just write the parameters into a list.)

  4. Run python script/run.py in the root directory of the project.

  5. Check the corresponding folder in the result directory and record the experimental results.

Example

git clone https://github.com/rainym00d/LLM4RS.git

cd LLM4RS

# * You should fill in your own api-key in script/run.py before run this command.
python script/run.py 
Parameters in run.py
- model

    - The model name of LLM.

    - Default: "text-davinci-003"

    - Option: ["text-davinci-002", "text-davinci-003", "gpt-3.5-turbo"]

- domain

    - The domain name.

    - Default: "Movie"

    - Option: ["Movie", "Book", "Music", "News"]

- task

    - The task name.

    - Default: "list"

    - Option: ["point", "pair", "list"]

- no_instruction

    - Use instruction or not.

    - Default: False

    - Option: [True, False]

- example_num

    - The number of example given to model.

    - Default: 1

    - Option: [1, 2, 3, 4, 5]

- begin_index

    - The begin index of data.

    - Default: 5

    - Option: the integer bigger than 4 but less than the size of data

- end_index

    - The end index of data.

    - Default: 505

    - Option: the integer bigger than `begin_index` but less than the size of data

- api_key

    - The api-key of openai which depends on your own openai account.

- max_requests_per_minute

    - Max request number per mins.

    - Default: 2000

    - Option: The max value depends on your own openai account.

- max_tokens_per_minute

    - Max token number per mins.

    - Default: 10000

    - Option: The max value depends on your own openai account.

- max_attempts

    - Max attempts per request.

    - Default: 10

- proxy

    - The proxy of your own.

    - Default: None

Dependencies

This repository has the following dependency requirements.

python==3.9
aiohttp==3.8.4
pandas==1.5.3
tiktoken==0.3.0
xpflow==0.8

The required packages can be installed via pip install -r requirements.txt.

Citation

If you find our code or work useful for your research, please cite our work.

@inproceedings{dai2023uncovering,
  title={Uncovering ChatGPT's Capabilities in Recommender Systems},
  author={Dai, Sunhao and Shao, Ninglu and Zhao, Haiyuan and Yu, Weijie and Si, Zihua and Xu, Chen and Sun, Zhongxiang and Zhang, Xiao and Xu, Jun},
  booktitle={Proceedings of the 17th ACM Conference on Recommender Systems},
  year={2023}
}

Contact

If you have any problems, please feel free to contact us via Github issues. Thanks!

llm4rs's People

Contributors

ethan00si avatar kid-22 avatar nekomoyi avatar rainym00d avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

llm4rs's Issues

How much does it usually take to complete?

首先非常感谢大佬您的工作!我按照您在readme上的说明添加了OpenAI的API key:"sk-xxxxxx" 以及将四个Book, News, Music, Movie的数据移到了data文件夹下,最后在LLM4RS目录执行了“python script/run.py”指令,目前程序运行到了打印参数之后过了2个多小时仍然没有complete。请问大佬这是否属于正常情况?一般在有GPU的情况下跑一次需要要多长时间?麻烦大佬了

Object of type InvalidURL is not JSON serializable

when run the code, the requese result can't back successfuly.
what is the reason? thanks
ERROR log:
2023-05-19 14:32:39,969 Starting request #7-0
2023-05-19 14:32:39,970 Request 7-0 failed with Exception None
2023-05-19 14:32:39,971 Request {'model': 'text-davinci-003', 'prompt': 'You are a movie recommender system now.\nInput: Here is the watching history of a user: Gattaca, Armageddon, Big, Babes in Toyland, Gladiator. Based on this history, please rank the following candidate movies: (A) Con Air (B) Mulan (C) Nikita (D) Donnie Brasco (E) Star Wars: Episode I - The Phantom Menace\nOutput: The answer index is D B A C E.\nInput: Here is the watching history of a user: The Adventures of Milo and Otis, The Pelican Brief, Dinosaur, Air Force One, The First Wives Club. Based on this history, please rank the following candidate movies: (A) The Good Bad and The Ugly (B) Robin Hood: Men in Tights (C) Thumbelina (D) George of the Jungle (E) Tom and Huck\nOutput: The answer index is', 'max_tokens': 20, 'temperature': 0, 'top_p': 1, 'frequency_penalty': 0.0, 'presence_penalty': 0.0, 'stop': '\n', 'logprobs': None, 'logit_bias': {}} failed after all attempts. Saving errors: [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

help

Hello, the student has been greatly inspired by reading your article, but cannot find the methods for pop and random in the code. Could you please take the time to provide them to the student? Thank you very much!

Object of type InvalidURL is not JSON serializable

when run the code, the requese result can't back successfuly.
what is the reason? thanks
ERROR log:
2023-05-19 14:32:39,969 Starting request #7-0
2023-05-19 14:32:39,970 Request 7-0 failed with Exception None
2023-05-19 14:32:39,971 Request {'model': 'text-davinci-003', 'prompt': 'You are a movie recommender system now.\nInput: Here is the watching history of a user: Gattaca, Armageddon, Big, Babes in Toyland, Gladiator. Based on this history, please rank the following candidate movies: (A) Con Air (B) Mulan (C) Nikita (D) Donnie Brasco (E) Star Wars: Episode I - The Phantom Menace\nOutput: The answer index is D B A C E.\nInput: Here is the watching history of a user: The Adventures of Milo and Otis, The Pelican Brief, Dinosaur, Air Force One, The First Wives Club. Based on this history, please rank the following candidate movies: (A) The Good Bad and The Ugly (B) Robin Hood: Men in Tights (C) Thumbelina (D) George of the Jungle (E) Tom and Huck\nOutput: The answer index is', 'max_tokens': 20, 'temperature': 0, 'top_p': 1, 'frequency_penalty': 0.0, 'presence_penalty': 0.0, 'stop': '\n', 'logprobs': None, 'logit_bias': {}} failed after all attempts. Saving errors: [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Getting stuck at API call

Hi, running python script/run.py is getting stuck (at (pid, sts) = os.waitpid(self.pid, wait_flags)) for me during the API request, specifically in the below section of src/api/openai.py:

async with session.post(
    url=request_url, headers=request_header, json=self.request_json, proxy=proxy
) as response:
    response = await response.json()

I am using the below arguments.

class MyArgs(Xp):
    model = ["text-davinci-003"]
    domain = ["Book"]
    task = ["list"]
    no_instruction = False
    example_num = [1]
    begin_index = 5
    end_index = 6
    api_key = "MY_API_KEY"
    max_requests_per_minute = 2000
    max_tokens_per_minute = 80000
    max_attempts = 100
    proxy = None

cannot connect to host

I have confirmed that I use the correct api key by successfully using the openAi API to generate sentences in Python.

However, when running the code:

asyncio.run(
process_api_requests_from_file(
requests_filepath=config.request_path,
save_filepath=config.response_path,
request_url = config.api_url,
api_key=config.api_key,
max_requests_per_minute=config.max_requests_per_minute,
max_tokens_per_minute=config.max_tokens_per_minute,
token_encoding_name=config.token_encoding_name,
max_attempts=config.max_attempts,
proxy=config.proxy,
)
)

Some errors just occur in the log file:
failed with Exception Cannot connect to host api.openai.com:443 ssl:default [Connect call failed ('199.96.58.105', 443)]

Is something wrong with my network or the url in the code? I would appreciate it if you can give me a hand to this issue!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.