Output from tf.tensordot(x,y,2)

I try to understand the collaborative filter recommender

One particular part is about tf.tensordot(x,y,2) in the following code:

    def call(self, inputs):
        user_vector = self.user_embedding(inputs[:, 0])
        user_bias = self.user_bias(inputs[:, 0])
        movie_vector = self.movie_embedding(inputs[:, 1])
        movie_bias = self.movie_bias(inputs[:, 1])
        dot_user_movie = tf.tensordot(user_vector, movie_vector, 2)
        # Add all the components (including bias)
        x = dot_user_movie + user_bias + movie_bias
        # The sigmoid activation forces the rating to between 0 and 1
        return tf.nn.sigmoid(x)

dot_user_movie.shape is () but x.shape is (None, 1). Why? I expect dot_user_movie.shape be (None, 1) as well.

What I really want to do is to remove bias terms. But it will give me some error if I do the following:

x = dot_user_movie
return tf.nn.sigmoid(x)

Hi @superamethyst ,

Welcome to Tensorflow forum.

Here in the attached tutorial dot_user_movie is dot product of user_vector and movie_vector are of same shape and hence the dot product will be a scalar whose shape is ( ).

‘x’ is sum of 3 tensors where the scalar tensor i.e. dot_user_movie will be broadcasted to the common broadcastable shape based on shapes of user_bias or movie_bias. In matrix operations broadcasting will plays a role and if the matrices are not broadcastable to same shape then error will be given. A scalar can be broadcasted to any shape and here other two are of same shape which is (64,1) and hence scalar value also will be broadcasted to (64,1) .

Note.Here batch_size is 64 and model won’t print batch_size and hence you will get shape of (None,1) where None represents batch_size.

Please refer attached gist.