Monday, 22 April 2019

keras: figuring out calculation inside source for weight to input multiplication

Intuition:

I have created an Autoencoder although it is for Rating Matrix for Users against Movies. I'm trying to recreate the output on prediction using Collaborative filtering (CF).

The Dataset:

The dataset below is how the input goes in. I've converted into a Pivot matrix here: Call this as A_set

MovieId 1    2    3    4    5    6    7  ...
UserId
0       5.0  0.0  0.0  0.0  2.0  0.0  0.0  ...
1       0.0  0.0  0.0  2.0  2.0  0.0  0.0  ...
2       5.0  0.0  1.0  0.0  0.0  0.0  0.0  ...
3       1.0  0.0  0.0  0.0  3.0  0.0  3.0  ... 

Just Transpose of this is also created, where MovieIds are in rows and UserIds in Columns. Call this as B_set.

The Questionnaire:

Over this, I have foll. queries:

  • What set (A/B) can be called as Collaborative filtering (CF) on giving Input to Auto-encoder (made using Keras) in Neural Network?
  • I'm trying to get a distinction on what part is User Based CF and Item Based CF
  • Now I know internally, how below formula works mathematically. I'm just not sure if it works same way in Code of Keras (or TF) as well. Which one (set A/B) should I consider as my CF?

Y = Theta(Transpose) . Input(X) + C

  • Theta being the weight matrix, I need to see if source code Transposes the Theta matrix and then solves the equation or is it already transposed and the input I give needs to be set_B to do justice to CF.

I tried giving input as set_A and then I also checked the weights after the input was trained / modeled. Check the Snippet:

w1 = model.get_weights()
train_set.shape # (5436, 3706)
w1[0].shape     # (3706, 529)
w1[0].T.shape   # (529, 3706)
w1[1].T.shape   # (529,)
w1[2].T.shape   # (264, 529)
w1[3].T.shape   # (264,)
w1[4].T.shape   # (132, 264)
w1[5].T.shape   # (132,)
w1[6].T.shape   # (264, 132)
w1[7].T.shape   # (264,)
w1[8].T.shape   # (529, 264)
w1[9].T.shape   # (529,)
w1[10].T.shape  # (3706, 529)
w1[11].T.shape  # (3706,)

Now it makes kind of sense, that this is probably being Transpose somewhere inside the Source code of Keras (please point me where!), else the Matrix multiplication would be impossible. Yet the question remains open as to which (set A/B) can be called as CF?



from keras: figuring out calculation inside source for weight to input multiplication

No comments:

Post a Comment