Matrix Factorization

Github Repo

Problem description:

 涼宮春日的憂鬱4月是你的謊言科學超電磁砲
大木博士5N/A4
小智N/A3N/A
小茂2N/A2
吸盤魔偶42N/A

Matrix Factorization

where $R$ is a sparse matrix with $n$ users and $m$ movies

$U$: a $(n\times d)$ dimension matirx

$V^T$: a $(d\times m)$ dimension matrix

\[L=\sum_{i,j}(R_{ij}-U_i\cdot V_j)^2\]\[r_{ij}=U_i\cdot V_j+b_i^{user}+b_j^{movie}\]

Functions in Keras

  1. keras.layers.Embedding: the user matrix and item matrix can be viewed as two embedding matrix
  2. keras.layers.Flatten: the output tensor shape of the embedding layer would be [batch_size,1,embedding_dim], you need this function to reshape the tensor to [batch_size,embedding_dim]
  3. keras.layers.Dot: if applied to two tensors a and b of shape (batch_size, n), the output will be a tensor of shape (batch_size, 1) where each entry i will be the dot product between a[i] and b[i].
  4. keras.layers.Add: add all tensors
  5. keras.layers.Concatenate: concatenate two tensors

Hello!

Result