sampled-softmax

Sampled Softmax in Keras Model

心不动则不痛 提交于 2019-12-11 12:44:37
问题 Some approaches I have considered: Inheriting from Model class Sampled softmax in tensorflow keras Inheriting from Layers class How can I use TensorFlow's sampled softmax loss function in a Keras model? Of the two approaches the Model approach is cleaner, as the layers approach is a little hacky - it pushes in the target as part of the input and then bye bye multi-output models. I'd like some help in subclassing the Model class - Specifically: 1) Unlike the first approach - I would like to

Keras: Using weights for NCE loss

懵懂的女人 提交于 2019-12-10 10:11:06
问题 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',

Keras: Using weights for NCE loss

我与影子孤独终老i 提交于 2019-12-05 19:37:43
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