Skip to content

Instantly share code, notes, and snippets.

@micaleel
Forked from groverpr/pmf
Created November 13, 2018 17:12
Show Gist options
  • Save micaleel/1d34f8f2ba4435c33339f1e1fcddf9cf to your computer and use it in GitHub Desktop.
Save micaleel/1d34f8f2ba4435c33339f1e1fcddf9cf to your computer and use it in GitHub Desktop.
pmf neural net fastai
ratings = pd.read_csv('ratings_small.csv') # loading data from csv
"""
ratings_small.csv has 4 columns - userId, movieId, ratings, and timestammp
it is most generic data format for CF related data
"""
val_indx = get_cv_idxs(len(ratings)) # index for validation set
wd = 2e-4 # weight decay
n_factors = 50 # n_factors - dimension of embedding matrix (D)
# data loader
cf = CollabFilterDataset.from_csv(path, 'ratings_small.csv', 'userId', 'movieId', 'rating')
# learner initializes model object
learn = cf.get_learner(n_factors, val_indx, bs=64, opt_fn=optim.Adam)
# fitting model with 1e-2 learning rate, 2 epochs,
# (1 cycle length and 2 cycle multiple for learning rate scheduling)
learn.fit(1e-2,2, wds = wd, cycle_len=1, cycle_mult=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment