how convert emebadding dimensions to 2d tensorflow

Viewed 48

I'm working on a GMF (generalized matrix factorisation model) and I have two inputs (user_Ids,movie_Ids) ,
in the first the two inputs will encode by One-hot encoder , and then pass on emebadding and in the last flattent them to get two vectors latent . GMF based on the multiplication of these two vectors latent

The problem with the result is that I get two vectors of different dimensions that cannot be multiplied

   Incompatible input shapes: axis values 135990 (at axis 1) != 10065 (at axis 1). Full input 
   shapes: (None, 135990), (None, 10065)

I have 9066 movie_Ids and 671 user_Id

latent dim =15

so shapes of every step is :

inputs shapes : [None, 1]

output of user_Ids by one-hot encoder : [None, 1, 671]

output of movie_Ids by one-hot encoder : [None, 1, 9066]

output of movie_Ids by embedding : [None, 1, 9066, 15]

output of user_Ids by embedding : [None, 1, 671, 15]

output of user_Ids by flattent: [None, 135990]

output of user_Ids by flattent: [None, 10065]

this is my code :

num_users = len(dataset.user_id.unique())
num_movies = len(dataset.movie_id.unique())
train, test = train_test_split(dataset, test_size=0.2)

latent_dim = 15
movie_input = Input(shape=(1),name='movie-input',dtype='int64')
movie_onehot = tf.one_hot(movie_input,num_movies,name='user_onehot')
movie_embedding = Embedding(num_movies + 1, latent_dim, name='movie-embedding')(movie_onehot)    
movie_vec = Flatten(name='movie-flatten')(movie_embedding)

user_input = Input(shape=[1],name='user-input',dtype='int64')
user_onehot = tf.one_hot(user_input,num_users,name='user_onehot')
user_embedding = Embedding(num_users + 1, latent_dim, name='user-embedding')(user_onehot)
user_vec = Flatten(name='user-flatten')(user_embedding)

prod = dot([movie_vec, user_vec], axes=1, normalize=False)
model = Model([user_input, movie_input], prod)
model.compile('adam', 'mean_absolute_error')
0 Answers
Related