Ranking
Ranking
Gorse merges recommendation from multiple recommenders and ranks them to produce the final recommendation list.
Configuration
typeis the ranker type. The supported ranker is:nonemeans no ranking is performed.fmuses factorization machines[1] to rank recommended items.llmuses large language models (LLMs) to rank recommended items.
promptis the prompt template used by LLM ranker. This field is required whentypeisllm. The template supports the following variables:feedbackis the user's historical feedback.itemsis a list of recommended items to be ranked.
Type definitions of feedback and items.
The type of feedback is:
type FeedbackItem struct {
FeedbackType string
ItemId string
IsHidden bool
Categories []string
Timestamp time.Time
Labels any
Comment string
}The type of items is:
type Item struct {
ItemId string
IsHidden bool
Categories []string
Timestamp time.Time
Labels any
Comment string
}recommendersare the names of recommenders whose recommendations are merged and ranked. Values should be one of the following:latestuses the latest items recommender.collaborativeuses the collaborative filtering recommender.non-personalized/NAMEuses a non-personalized recommender with nameNAME.item-to-item/NAMEuses an item-to-item recommender with nameNAME.user-to-user/NAMEuses a user-to-user recommender with nameNAME.
early_stopping.patienceis the number of epochs with no improvement after which factoring machine training will be stopped. Defaults to10.
Example
In the demo project GitRec, factorization machines are used to rank recommended items from multiple recommenders:
- Latest repositories from the latest items recommender.
- Collaborative filtering recommendations.
- Most starred repositories in the past week from the non-personalized recommender.
- Similar repositories from the item-to-item recommender.
- Repositories from positive feedback of similar users from the user-to-user recommender.
[recommend.ranker]
type = "fm"
recommenders = ["latest", "collaborative", "non-personalized/most_starred_weekly", "item-to-item/neighbors", "user-to-user/neighbors"]Algorithms
Factorization Machines
Different from the learning algorithms for matrix factorization, negative feedback are used in factorization machine training. The training dataset is constructed by
The dimension of input vectors is the sum of the numbers of items, users, item labels and user labels: . Each element in for a pair is defined by
The prediction output for a input vector is
where the model parameters that have to be estimated are: , , . And is the dot product of two vectors. Parameters are optimized by logit loss with SGD. The loss function is
The gradient for each parameter is
Large Language Models
Recent studies have shown that large language models (LLMs) such as ChatGPT can effectively perform recommendation through prompt engineering[2][3]. Gorse leverages this capability by using LLMs to rank recommended items based on user feedback and item information.
Before using the LLM ranker, OpenAI API must be configured in the [openai] of the configuration file. A prompt template must also be provided in the ranker configuration. An example prompt template for recommending GitHub repositories is as follows:
You are a GitHub repository recommender system. Given a user is interested in the following repositories:
{% for repo in feedback -%}
- {{ repo.Comment }}
{% endfor -%}
Please sort the following repositories by the user's interests:
```csv
item_id,description
{% for repo in items -%}
{{ repo.ItemId }},{{ repo.Comment | replace(",", " ") | replace("\n", " ") }}
{% endfor -%}
```
Return the sorted list of repository IDs in CSV format. For example:
```csv
{% for repo in items[:3] -%}
{{ repo.ItemId }}
{% endfor -%}
```feedback contains the user's recent feedback and items contains the list of recommended items to be ranked. The number of feedback items can be controlled by the recommend.context_size. The LLM ranker renders the prompt template and sends it to the OpenAI API. The response is then parsed to extract the ranked list of item IDs.
Rendle, Steffen. "Factorization machines." 2010 IEEE International conference on data mining. IEEE, 2010. ↩︎
Liu, Junling, et al. "Is chatgpt a good recommender? a preliminary study." arXiv preprint arXiv:2304.10149 (2023). ↩︎
Dai, Sunhao, et al. "Uncovering chatgpt’s capabilities in recommender systems." Proceedings of the 17th ACM Conference on Recommender Systems. 2023. ↩︎
