我正在使用深度学习构建推荐系统。定义模型时,出现以下错误:
ValueError:层dot_1的调用不是符号张量。收到的类型:。全输入:[,]。该层的所有输入都应为张量。
课程代码
# The constructor for the class
def __init__(self, n_users, m_items, k_factors, **kwargs):
# U is the embedding layer that creates an User by latent factors matrix.
# If the input is a user_id, U returns the latent factor vector for that user.
U = Sequential()
U.add(Embedding(n_users, k_factors, input_length=1))
U.add(Reshape((k_factors,)))
# M is the embedding layer that creates a Movie by latent factors matrix.
# If the input is a movie_id, M returns the latent factor vector for that movie.
M = Sequential()
M.add(Embedding(m_items, k_factors, input_length=1))
M.add(Reshape((k_factors,)))
super(CFModel, self).__init__(**kwargs)
# The dot layer takes the dot product of user and movie latent factor vectors to return the corresponding rating.
self.add(dot([U, M], axes=1))
当我尝试在两个连续模型上执行点积时,发生错误。
self.add(dot([U, M], axes=1))
在较早版本的keras中,我能够使用Merge layer mode ='dot'来执行此操作。我认为最新版本将以相同的方式工作。
有人可以帮助我解决此错误吗?