Keras: Using weights for NCE loss
So here is the model with the standard loss function. target = Input(shape=(1, ), dtype='int32') w_inputs = Input(shape=(1, ), dtype='int32') w_emb = Embedding(V, dim, embeddings_initializer='glorot_uniform',name='word_emb')(w_inputs) w_flat= Flatten()(w_emb) # context w1= Dense(input_dim=dim, units=V, activation='softmax') # because I want to use predicition on valid set) w= w1(w_flat) model = Model(inputs=[w_inputs], outputs=[w]) model.compile(loss='sparse_categorical_crossentropy', optimizer='sgd',metrics=['accuracy']) It works fine. Given NCE loss isnt available in keras, I wrote up a