Skip to content
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

Add Hard Negative Mining Layer. #24

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

hertschuh
Copy link
Collaborator

This layer extract negative logits and labels.

Copy link
Collaborator

@abheesht17 abheesht17 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! Left some minor comments

from keras_rs.src.layers.loss import hard_negative_mining


class HardNegativeMiningTest(testing.TestCase, parameterized.TestCase):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add a test_predict test to check whether it works when compiled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also added to FeatureCross

match.
"""
num_row = ops.shape(data)[0]
num_column = ops.shape(data)[1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we know it'll be a 2D tensor, we can rewrite these two lines to:

num_row, num_column = ops.shape(data)

num_hard_negatives: How many hard negatives to return.
"""

def __init__(self, num_hard_negatives: int) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

**kwargs, and then passed to super().__init__(**kwargs)

@hertschuh
Copy link
Collaborator Author

Thanks for the PR! Left some minor comments

I'll be moving this layer to the retrieval folder per discussion.

This layer extract negative logits and labels.

Also made layer test more similar.
Copy link
Collaborator

@abheesht17 abheesht17 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@hertschuh hertschuh merged commit d5d0372 into keras-team:main Feb 27, 2025
5 checks passed
@hertschuh hertschuh deleted the hard_negative branch February 27, 2025 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants