loss-function

How can I use TensorFlow's sampled softmax loss function in a Keras model?

天涯浪子 提交于 2019-11-29 10:40:57
I'm training a language model in Keras and would like to speed up training by using sampled softmax as the final activation function in my network. From the TF docs, it looks like I need to supply arguments for weights and biases , but I'm unsure of what is expected as input for these. It seems like I could write a custom function in Keras as follows: import keras.backend as K def sampled_softmax(weights, biases, y_true, y_pred, num_sampled, num_classes): return K.sampled_softmax(weights, biases, y_true, y_pred, num_sampled, num_classes) However, I'm unsure of how to "plug this in" to my

Keras using Tensorflow backend— masking on loss function

让人想犯罪 __ 提交于 2019-11-28 22:30:37
问题 I am trying to implement a sequence-to-sequence task using LSTM by Keras with Tensorflow backend. The inputs are English sentences with variable lengths. To construct a dataset with 2-D shape [batch_number, max_sentence_length], I add EOF at the end of line and pad each sentence with enough placeholders, e.g. "#". And then each character in sentence is transformed to one-hot vector, now the dataset has 3-D shape [batch_number, max_sentence_length, character_number]. After LSTM encoder and

Cost function training target versus accuracy desired goal

烈酒焚心 提交于 2019-11-28 14:41:50
When we train neural networks, we typically use gradient descent, which relies on a continuous, differentiable real-valued cost function. The final cost function might, for example, take the mean squared error. Or put another way, gradient descent implicitly assumes the end goal is regression - to minimize a real-valued error measure. Sometimes what we want a neural network to do is perform classification - given an input, classify it into two or more discrete categories. In this case, the end goal the user cares about is classification accuracy - the percentage of cases classified correctly.

Custom loss function in Keras

廉价感情. 提交于 2019-11-27 19:00:32
I'm working on a image class-incremental classifier approach using a CNN as a feature extractor and a fully-connected block for classifying. First, I did a fine-tuning of a VGG per-trained network to do a new task. Once the net is trained for the new task, i store some examples for every class in order to avoid forgetting when new classes are available. When some classes are available, i have to compute every output of the exemplars included the exemplars for the new classes. Now adding zeros to the outputs for old classes and adding the label corresponding to each new class on the new classes

Cost function training target versus accuracy desired goal

半城伤御伤魂 提交于 2019-11-26 23:43:11
问题 When we train neural networks, we typically use gradient descent, which relies on a continuous, differentiable real-valued cost function. The final cost function might, for example, take the mean squared error. Or put another way, gradient descent implicitly assumes the end goal is regression - to minimize a real-valued error measure. Sometimes what we want a neural network to do is perform classification - given an input, classify it into two or more discrete categories. In this case, the

Custom loss function in Keras

巧了我就是萌 提交于 2019-11-26 12:58:15
问题 I\'m working on a image class-incremental classifier approach using a CNN as a feature extractor and a fully-connected block for classifying. First, I did a fine-tuning of a VGG per-trained network to do a new task. Once the net is trained for the new task, i store some examples for every class in order to avoid forgetting when new classes are available. When some classes are available, i have to compute every output of the exemplars included the exemplars for the new classes. Now adding

What function defines accuracy in Keras when the loss is mean squared error (MSE)?

微笑、不失礼 提交于 2019-11-26 05:29:35
How is Accuracy defined when the loss function is mean square error? Is it mean absolute percentage error ? The model I use has output activation linear and is compiled with loss= mean_squared_error model.add(Dense(1)) model.add(Activation('linear')) # number model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy']) and the output looks like this: Epoch 99/100 1000/1000 [==============================] - 687s 687ms/step - loss: 0.0463 - acc: 0.9689 - val_loss: 3.7303 - val_acc: 0.3250 Epoch 100/100 1000/1000 [==============================] - 688s 688ms/step - loss: 0