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:query_templateis the query template used by LLM-based reranker. This field is required whentypeisllm. The template supports the following variables:feedbackis the user's historical feedback.
document_templateis the document template used by LLM-based reranker. This field is required whentypeisllm. The template supports the following variables: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
LLM-based Rerankers
Recent studies have shown that large language models (LLMs) such as ChatGPT can effectively perform recommendation through prompt engineering[3][4]. Gorse leverages this capability by using LLM-based rerankers[2:1] to rank recommended items based on user feedback and item information.
Before using the LLM-based reranker, reranker API must be configured in the [recommend.ranker.reranker_api] of the configuration file. Query template and document Template must also be provided in the ranker configuration. An example for recommending GitHub repositories is as follows:
- Query Template
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 repositories by the user's interests.- Document Template
{{ item.Comment | replace(",", " ") | replace("\n", " ") }}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-based reranker renders the query template and document templates, then sends them to the reranker 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. ↩︎
Nogueira, Rodrigo, et al. "Document ranking with a pretrained sequence-to-sequence model." Findings of the association for computational linguistics: EMNLP 2020. 2020. ↩︎ ↩︎
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. ↩︎
