Skip to content

Conversation

n3011
Copy link
Contributor

@n3011 n3011 commented Nov 27, 2019

It fixes the following two bugs related to the CohenKappa metric:

Copy link
Member

@WindQAQ WindQAQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

return kp
return tf.cond(tf.math.is_nan(denominator),
true_fn=lambda: 0.0,
false_fn=lambda: 1 - (numerator / denominator))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I think the fix is correct, but a better approach should be change the division of these two lines into tf.math.divide_no_nan. And modify kp to kp = tf.math.divide_no_nan(denominator - numerator, denominator). How do you think about this @n3011?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WindQAQ there are two problems with tf.math.divide_no_nan approach:

  • it will produce nan result only, as nan/nan not defined.
  • it slightly slower than tf.cond based aproach.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. After a rough test, your approach is actually faster :-) Thanks for the report.

@WindQAQ WindQAQ self-requested a review December 1, 2019 08:45
Copy link
Member

@WindQAQ WindQAQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind running make code-format to format codes? Or see the following log to manually format codes. I'd like to merge this after tests pass. Thanks again for the fix!

https://source.cloud.google.com/results/invocations/ff1ff9f3-81b8-4671-b13c-9d40519190f1/log

@n3011
Copy link
Contributor Author

n3011 commented Dec 1, 2019

@WindQAQ thanks, pushed the formatted changes.

Copy link
Member

@WindQAQ WindQAQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you again for the contribution!

@WindQAQ WindQAQ merged commit 9b7fdc7 into tensorflow:master Dec 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants