Sitemap
Allen Wu

Allen Wu

Fast AI — DL 2018 L5 note

2 min readApr 5, 2018

--

Good notes

Topics

  • Create collaborative filtering model MovieLens
  • Detail of Optimize function

MovieLens

Matrix factorization

  • For certain User X certain Movie, presented by cross-tab, can be predict by A . B (dot product) where A and B are 1 rank latent factor

Solve it by Excel solver

  1. Set objective
  2. Set variable cells, i.e. matrix for A . B
  3. Set solving method: GRG Nonliear
  4. No non-linear layer, kind of Shallow learning
  5. Assumption: certain user likes how much [romantic, action, sci-fi] dot Movie contains how much [romantic, action, sci-fi]
  6. But we don’t have this latent matrix …
  7. Latent matrix is kind of embedding matrix

Solve it by Python

  • embedding matrix size = 50
  • data visualization by seaborn

Get Allen Wu’s stories in your inbox

Join Medium for free to get updates from this writer.

Dot product model with PyTorch

  • Customized PyTorch class: EmbeddingDot
  • Dot product of User X Movie
  • Dictionary comprehension: {key: value for value, key in enumerate (ratings.userId.unique())}
  • HE weight init. : uniform dist.
  • …uniform_(0, 0.05) where underscore means no return, it’s “in-replace” version
  • data = ColumnarModelData.from_data_frame…
  • optimizer with weight decay

Improvement — Bias

  • Add bias to embedding matrix: EmbeddingDotBias
  • PyTorch’s fit has no SGDR, differential LR, LR finder …
  • Then start to add some FastAI tech. “manually”
  • LR annealing

Improvement — NN

  • Using NN instead of Dot product of User X Movie
  • Concatenating user, movie embedding together
  • Or concat more: user emb(embedding) + movie emb + genre emb+ timing emb + …

Optimize / Fit by Excel

Stochastic Gradient Descent (SGD)

  • For matrix, use Jacobian, Hessian instead of single element finite difference

Momentum

  • Speed up gradient descent
  • SGD + Momentum

Adam

  • It’s faster, but the final answer is not as good as SGD + Momentum
  • AdamW: Fixing Weight Decay Regularization in Adam

--

--