Keras嵌入层:InvalidArgumentError:indices [0,0] = 740不在[0,13]中

时间:2017-11-08 23:28:02

标签: tensorflow keras

在嵌入层上训练模型时出现错误:

  

InvalidArgumentError:indices [0,0] = 740不在[0,13]中        [[Node:MM_emb / Gather = Gather [Tindices = DT_INT32,Tparams = DT_FLOAT,validate_indices = true,_device =" / job:localhost / replica:0 / task:0 / device:CPU:0"] (MM_emb / embeddings / read,MM_emb / Cast)]]

嵌入代码是:

def get_embedding(attr):
    name = str(attr)
    input_dims = len(categorical_features_mappings[attr])+1
    output_dims = category_embedding_sizes[attr]
    output_dims = (input_dims+1)//2
    if output_dims>50: output_dims=50

    inp = Input((1,), dtype='int64', name=name+'_in')
    u = Flatten(name=name+'_flt')(Embedding(input_dims, output_dims, name=name+'_emb',  embeddings_initializer='uniform')(inp))
    return inp,u


contin_inp = Input((len(continuous_features),), name='contin')
contin_out = Dense(len(continuous_features) * 10, activation='relu', name='contin_d')(contin_inp)
embeddings = [get_embedding(attr) for attr in category_embedding_sizes]

x = merge([emb for inp, emb in embeddings] + [contin_out], mode='concat')

x = Dropout(0.02)(x)
x = Dense(100, activation='relu', kernel_initializer='uniform')(x)
x = Dense(50, activation='relu', kernel_initializer='uniform')(x)
x = Dropout(0.2)(x)
x = Dense(1, activation='sigmoid')(x)

model = Model([inp for inp,emb in embeddings] + [contin_inp], x)

有人有任何想法吗?

谢谢!

0 个答案:

没有答案