
Spotlight uses PyTorch to build both deep and shallow recommender models. By providing both a slew of building blocks for loss functions (various pointwise and pairwise ranking losses), representations (shallow factorization representations, deep sequence models), and utilities for fetching (or generating) recommendation datasets, it aims to be a tool for rapid exploration and prototyping of new recommender models.
See the full documentation for details.
condainstall-cmaciejkula-csoumithspotlight=0.1.1To fit an explicit feedback model on the MovieLens dataset:
fromspotlight.cross_validationimportrandom_train_test_splitfromspotlight.datasets.movielensimportget_movielens_datasetfromspotlight.evaluationimportrmse_scorefromspotlight.factorization.explicitimportExplicitFactorizationModeldataset=get_movielens_dataset(variant='100K')
train, test=random_train_test_split(dataset)
model=ExplicitFactorizationModel(n_iter=1)
model.fit(train)
rmse=rmse_score(model, test)To fit an implicit ranking model with a BPR pairwise loss on the MovieLens dataset:
fromspotlight.cross_validationimportrandom_train_test_splitfromspotlight.datasets.movielensimportget_movielens_datasetfromspotlight.evaluationimportmrr_scorefromspotlight.factorization.implicitimportImplicitFactorizationModeldataset=get_movielens_dataset(variant='100K')
train, test=random_train_test_split(dataset)
model=ImplicitFactorizationModel(n_iter=3,
loss='bpr')
model.fit(train)
mrr=mrr_score(model, test)Recommendations can be seen as a sequence prediction task: given the items a user has interacted with in the past, what will be the next item they will interact with? Spotlight provides a range of models and utilities for fitting next item recommendation models, including
- pooling models, as in YouTube recommendations,
- LSTM models, as in Session-based recommendations..., and
- causal convolution models, as in WaveNet.
fromspotlight.cross_validationimportuser_based_train_test_splitfromspotlight.datasets.syntheticimportgenerate_sequentialfromspotlight.evaluationimportsequence_mrr_scorefromspotlight.sequence.implicitimportImplicitSequenceModeldataset=generate_sequential(num_users=100,
num_items=1000,
num_interactions=10000,
concentration_parameter=0.01,
order=3)
train, test=user_based_train_test_split(dataset)
train=train.to_sequence()
test=test.to_sequence()
model=ImplicitSequenceModel(n_iter=3,
representation='cnn',
loss='bpr')
model.fit(train)
mrr=sequence_mrr_score(model, test)Spotlight offers a slew of popular datasets, including Movielens 100K, 1M, 10M, and 20M. It also incorporates utilities for creating synthetic datasets. For example, generate_sequential generates a Markov-chain-derived interaction dataset, where the next item a user chooses is a function of their previous interactions:
fromspotlight.datasets.syntheticimportgenerate_sequential# Concentration parameter governs how predictable the chain is;# order determins the order of the Markov chain.dataset=generate_sequential(num_users=100,
num_items=1000,
num_interactions=10000,
concentration_parameter=0.01,
order=3)Spotlight is meant to be extensible: pull requests are welcome. Development progress is tracked on Trello: have a look at the outstanding tickets to get an idea of what would be a useful contribution.
We accept implementations of new recommendation models into the Spotlight model zoo: if you've just published a paper describing your new model, or have an implementation of a model from the literature, make a PR!
