Package: elsarec
ELSAThis is an official implementation of our paperScalable Linear Shallow Autoencoder for Collaborative Filtering.RequirementsPyTorch in version >=10.1 (along with compatibleCUDA Toolkit) must be installed in the system. If not, one can installPyTorchwithpip install torch==1.10.2+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113InstalationELSA can be installed frompypiwith:pip install elsarecBasic usagefromelsaimportELSAimporttorchimportnumpyasnpdevice=torch.device("cuda")X_csr=...# load your interaction matrix (scipy.sparse.csr_matrix with users in rows and items in columns)X_test=...# load your test data (scipy.sparse.csr_matrix with users in rows and items in columns)items_cnt=X_csr.shape[1]factors=256num_epochs=5batch_size=128model=ELSA(n_items=items_cnt,device=device,n_dims=factors)model.fit(X_csr,batch_size=batch_size,epochs=num_epochs)# save item embeddings into np arrayA=torch.nn.functional.normalize(model.get_items_embeddings(),dim=-1).cpu().numpy()# get predictions in PyTorchpredictions=model.predict(X_test,batch_size=batch_size)# get predictions in numpypredictions=((X_test@A)@(A.T))-X_test# find related items for a subset of itemsitemids=np.array([id1,id2,...])# id1, id2 are indices of items in the X_csrrelated=model.similar_items(N=100,batch_size=128,sources=itemids)NotesReproducibilityInstructions for reproducing the results from the paper on the MovieLens20M dataset are in the branchreproduce_movielenshttps://github.com/recombee/ELSA/tree/reproduce_movielens.Reproducibility instructions for Netflix and Goodbooks10k datasets will follow soon.Tensorflow usersWe decided to implement ELSA in PyTorch, but implementation in TensorFlow is simple and straightforward. One can, for example, implement ELSA as a Keras layer:classELSA(tf.keras.layers.Layer):def__init__(self,latent,nr_of_items):super(ELSA,self).__init__()w_init=tf.keras.initializers.HeNormal()self.A=tf.Variable(initial_value=w_init(shape=(nr_of_items,latent),dtype="float32"),trainable=True,)defget_items_embeddings(self):A=tf.math.l2_normalize(self.A,axis=-1)returnA.numpy()@tf.functiondefcall(self,x):A=tf.math.l2_normalize(self.A,axis=-1)xA=tf.matmul(x,A,transpose_b=False)xAAT=tf.matmul(xA,A,transpose_b=True)returnxAAT-xLicenceMIT licenceTroubleshootingIf you encounter a problem or have a question about ELSA, do not hesitate to create an issue and ask. In case of an implementation problem, please include the Python, PyTorch and CUDA versions in the description of the issue.Cite usPlease consider citing our paper:@inproceedings{10.1145/3523227.3551482,
author = {Van\v{c}ura, Vojt\v{e}ch and Alves, Rodrigo and Kasalick\'{y}, Petr and Kord\'{\i}k, Pavel},
title = {Scalable Linear Shallow Autoencoder for Collaborative Filtering},
year = {2022},
isbn = {9781450392785},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3523227.3551482},
doi = {10.1145/3523227.3551482},
abstract = {Recently, the RS research community has witnessed a surge in popularity for shallow autoencoder-based CF methods. Due to its straightforward implementation and high accuracy$
booktitle = {Proceedings of the 16th ACM Conference on Recommender Systems},
pages = {604–609},
numpages = {6},
keywords = {Linear models, Shallow autoencoders, Implicit feedback recommendation},
location = {Seattle, WA, USA},
series = {RecSys '22}
}