-
Notifications
You must be signed in to change notification settings - Fork 19.6k
categorical accuracy doesn't account for mask (w/ proposed solution) #2260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
if anyone knows the equivalent of def perplexity(y_true, y_pred, mask=None):
if mask is not None:
y_pred /= K.sum(y_pred, axis=-1, keepdims=True)
mask = K.permute_dimensions(K.reshape(mask, y_true.shape[:-1]), (0, 1, 'x'))
truth_mask = K.flatten(y_true*mask).nonzero()[0] ### How do you do this on tensorflow?
predictions = K.gather(y_pred.flatten(), truth_mask)
return K.pow(2, K.mean(-K.log2(predictions)))
else:
return K.pow(2, K.mean(-K.log2(y_pred))) |
ya that's what I did: https://github.com/braingineer/keras/blob/master/keras/metrics.py#L10 Though, it's better if you use the mask that's passed with the network. It requires a commitment inside the main part of Keras too to push the mask through. But, it requires some some operations that I don't know how to implement inside Tensorflow, so I haven't pushed them upstream. |
No, I solved it in theano ages ago (as per my first answer). I just didn't solve it for tensorflow, hence why this is still open. The passing of the mask to the accuracy calculations should be happening anyway (imo). |
I used the implementation provided by @braingineer
but the problem is that |
* Reshape y_pred and y_true from (samples, timesteps, ... ) to (samples * timesteps, ... ) * Filter out masked timesteps from y_pred and y_true * Added K.where() and extended functionality of K.flatten() * Added/changed corresponding tests
Hi @braingineer, |
Hi all,
currently, accuracy is
I am running an RNN with variable length sentences and I want to get the accuracy of predictions at every time step. So basically, for a 3dim tensor, I have a binary matrix. I want each timestep of each batch to only be counted in the accuracy mean if it has a 1 entry in the binary matrix.
Proposed solution mwe (though, this is in theano, not using the abstracted keras backend.. but the change is trivial):
edit: currently using this
and i've shot from
loss: 3.9160 - acc: 0.1424
toloss: 3.9165 - acc: 0.2614
The text was updated successfully, but these errors were encountered: