Documentation
¶
Overview ¶
Package birdland provides algorithms to recommend music. It is also the name of a legendary Jazz Club.
Bird ¶
Most recommenders are based on collaborative filtering. Traditionally, algorithms compute a factorization of the user-item matrix into low-dimension, latent vectors for items and users. Recommendations are based on a proximity measure between these vectors.
Bird (from Charlie "Bird" Parker) is a recommendation algorithm that is based on random walks on the user-item graph. It relies on a (currently unweighted) user-item graph which represents interactions of any kind between each user and some of the items, and on a list of item weights. To initialize Bird with sensible defaults, you can write:
charlie, err := NewBird(NewBirdCfg(), itemWeights, usersToItems) if err !=
nil { log.Errorf("failed to initialize Bird") }
Bird draws `Draws` items from the input query which are starting points for random walks of depth `Depth`. It is possible to specify the values of these variables with
cfg := NewBirdCfg() cfg.Draws = 10000 cfg.Depth = 5
charlie := NewBird(cfg, itemWeights, usersToItems) if err != nil {
log.Errorf("failed to initialize Bird") }
Once Bird initialized you can process a query (a slice of `QueryItem`) with
visitedItems, referrers, err := charlie.Process(query)
the visitedItems and referrers are then used to produce recommendations. Note that Bird does not support empty queries.
It is possible (although not desirable) that an item in the query refers to an item no one has interacted with. We ignore said item for the rest of the calculations.
Use cases are recommendations based on a item/container bipartite graph. For instance: - Recommend new artists/songs based on user-item relationships; - Recommend users based on the same data; - Recommend new songs for a playlist/radio; - Recommend playlists/radio
Emu ¶
The emu is the heaviest bird there is out there. Although Bird is very efficient, it considers that all user-item interactions are created equal. However, users are likely to listen to certain artists more. Liking songs from an artist once is more meaningful than listening to one of their songs once. It is important to take these differences into account in the recommender.
The only difference between Emu and Bird is that Emu relies on a weighted user-item graph. Typically, the weights will be a combination of the number of plays, of shares, and likes. We still need to input a global list of weights for the items. To initialize Emu with sensible defaults you can write:
mingus, err := NewEmu(NewBirdCfg(), itemWeights, usersToItems) if err !=
nil { log.Errorf("failed to initialize Bird") }
where `usersToItems` is now of type `[]map[int]float64`. `mingus` is now of type `*Bird`. The only technical difference between Bird and Emu in the code is the way we initialize samplers for each users; Bird and Emu share everything else.
Index ¶
- func RecommendConsensus(items, referrers []int) []int
- func RecommendItems(items, referrers []int) []int
- func RecommendMostVisited(items []int) []int
- func RecommendTrust(items, referrers []int) []int
- func RecommendUsers(items, referrers []int) []int
- type Bird
- type BirdCfg
- type Pair
- type PairList
- type QueryItem
- type Weaver
- type WeaverCfg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RecommendConsensus ¶
RecommendConsensus recommends the item by descending order of the number of unique referrers. With the data currently available, it is only possible to recommend items this way.
func RecommendItems ¶
RecommendItems and RecommendUsers contain the current methods that should be used to recommend items and users in production. Used as an interface so backend developpers do not need to worry about the zoology of recommending methods.
func RecommendMostVisited ¶
RecommendMostVisited recommends the items in descending order of the number of visits by the processing algorithm. It is a very naive approach and probably should not be used in production. Works indifferently to recommend users or items.
func RecommendTrust ¶
RecommendTrust recommends items based on how much we can trust their referrers. The algorithm begins with attributing a weight to the refferers proportional to the number of times it traversed them. The tracks are recommended by descending order of the cumulated weights.
func RecommendUsers ¶
Types ¶
type Bird ¶
type Bird struct {
Cfg *BirdCfg
ItemWeights []float64 // global weight attributed to items
UsersToItems [][]int // user-item adjacency matrix
ItemsToUsers [][]int // item-user adjacency matrix
UserItemsSamplers []sampler.AliasSampler // samplers to randomly draw items from a user's collection
RandSource *rand.Rand
}
Bird is a recommendation engine that performs random walks on the user-item bipartite graph.
type BirdCfg ¶
func NewBirdCfg ¶
func NewBirdCfg() *BirdCfg
type Weaver ¶
Weaver is a combination of a Bird, and a list of maps that represents a weighted user-user matrix. To avoid storing the full social graph, a mostly empty matrix, we store for each user a map that associates each connection to a weight. Each user that is not connected is attributed a DefaultWeight.
func NewWeaver ¶
func NewWeaver(cfg *WeaverCfg, itemWeights []float64, usersToItems [][]int, socialGraph []map[int]float64) (*Weaver, error)
NewWeaver creates a new recommender from input data. Unlike Bird, users related to an item are not sampled uniformly, but according to socialCoef[user], making the recommendation dependent on both the query and the user being served.