MovieLen数据集的深度学习

时间:2018-06-26 21:59:51

标签: machine-learning keras

我为推荐系统构建了深度学习:

class EmbeddingNet():
    def __init__(self, n_users, n_item, k = 30):
        model1_in = Input(shape=(1,))
        model1_out = Embedding(input_dim = n_users+1, output_dim = k)(model1_in)
        model1_out = Reshape((k,))(model1_out)
        model1 = Model(model1_in, model1_out)

        model2_in = Input(shape=(1,))
        model2_out = Embedding(input_dim = n_item+1, output_dim = k)(model2_in)
        model2_out = Reshape((k,))(model2_out)
        model2 = Model(model2_in, model2_out)

        concatenated = concatenate([model1_out, model2_out])

        model = Dropout(0.2)(concatenated)
        model = Dense(k, activation='relu')(model)
        model = Dropout(0.5)(model)
        model = Dense(int(k/4),activation='relu')(model)
        model = Dropout(0.5)(model)
        model = Dense(int(k/16), activation = 'relu')(model)
        model = Dropout(0.5)(model)

        model = Dense(1, activation='linear', name='output_layer')(model)

        self.merged_model = Model([model1_in, model2_in], model)
        self.merged_model.compile(loss='mse',optimizer='adam')

    def fit(self, X, y, batch_size = 100, epochs = 50):
        self.merged_model.fit(X,y,batch_size, epochs)

并且X定义为[用户,电影],因此它看起来像:

  

[array([1,1,1,...,671,671,671]),array([31,1029,1061,   ...,6365,6385,6565])]

但是当我尝试安装它时,出现了一个错误:

InvalidArgumentError: indices[1,0] = 33679 is not in [0, 9067)
     [[Node: embedding_8/embedding_lookup = GatherV2[Taxis=DT_INT32, 
         Tindices=DT_INT32, Tparams=DT_FLOAT, 
         _class=["loc:@training_1/Adam/Assign_5"], 
         _device="/job:localhost/replica:0/task:0/device:CPU:0"]
       (embedding_8/embeddings/read, embedding_8/Cast, 
        training_1/Adam/gradients/embedding_8/embedding_lookup_grad/concat/axis)
     ]]

我在图层上出错或误解的地方吗?

0 个答案:

没有答案