Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TensorFlow推荐程序:InvalidArgumentInteror:索引[0,1]=66521不在[012976]中[Op:ResourceGather]_Python_Tensorflow_Deep Learning_Recommendation Engine - Fatal编程技术网

Python TensorFlow推荐程序:InvalidArgumentInteror:索引[0,1]=66521不在[012976]中[Op:ResourceGather]

Python TensorFlow推荐程序:InvalidArgumentInteror:索引[0,1]=66521不在[012976]中[Op:ResourceGather],python,tensorflow,deep-learning,recommendation-engine,Python,Tensorflow,Deep Learning,Recommendation Engine,我正在尝试使用TensorFlow Recommenders(TFR)构建一个推荐系统,在推断经过训练的模型时,我遇到了一个问题。我已经创建了查询和候选塔,并将嵌入维度设置为我的数据集中唯一电影的长度。用户功能已经标准化 class UserModel(tf.keras.Model): def __init__(self, users_vocab, embedding_dimension = 128): super().__init__() self.us

我正在尝试使用TensorFlow Recommenders(TFR)构建一个推荐系统,在推断经过训练的模型时,我遇到了一个问题。我已经创建了查询和候选塔,并将嵌入维度设置为我的数据集中唯一电影的长度。用户功能已经标准化

class UserModel(tf.keras.Model):
    def __init__(self, users_vocab, embedding_dimension = 128):
        super().__init__()
        self.user_model = tf.keras.Sequential([
            tf.keras.layers.experimental.preprocessing.IntegerLookup(vocabulary=users_vocab),
            tf.keras.layers.Embedding(len(users_vocab) + 2, embedding_dimension)
        ])

    def call(self, inputs):
        # Take the input dictionary, pass it through each input layer,
        # and concatenate the result.
        ret = tf.concat([
            self.user_model(inputs["USER_ID"]),
            tf.reshape(inputs["USER_FEATURE"], [-1, 1])
        ], axis=1)
        print(tf.shape(ret))
        return ret
经过培训后,我尝试通过使用BruteForce层创建索引来获得建议,d是包含UserId和用户特性的字典

index = tfrs.layers.factorized_top_k.BruteForce(model.query_model)
index.index(movie_features.batch(16192).map(model.candidate_model), movies)
_, titles = index(d, k=1)
我的模型推荐嵌入向量空间中不存在的电影,当我尝试获得k>1的推荐时,会抛出此错误

InvalidArgumentError: indices[0,1] = 66521 is not in [0, 12976) [Op:ResourceGather]
而当我通过k=1时,模型会给我一个电影ID

recommendations for user [2471]: [Movie ID]
我如何解决这个问题

谢谢!:)

编辑1:为了增加上述问题,当我传递没有标识符的候选功能时
index.index(movie_features.batch(16192).map(model.candidate_model))
则我的模型正确返回索引,但这些索引值大于movies变量的长度

电影功能:

电影:长度为83349的唯一电影id的列表
movies=training\u data.movie\u id.unique()