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

Create new IntersectCorrespondingFields operator #1531

Merged
merged 12 commits into from
Jan 30, 2025

Conversation

pklpriv
Copy link
Member

@pklpriv pklpriv commented Jan 20, 2025

In this PR Intersect() operator is updated. It allows us to filter out some values from data when running benchmarks. Additionally, test were updated and rewritten for more readability.

Copy link
Member

@elronbandel elronbandel left a comment

Choose a reason for hiding this comment

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

Two issues:
(1) This is not backward compatible, what if anyone using it now?
(2) The same behavior can be achieved with current implementation:
Intersect(field_to_field={"label": "label", "name": "name"}, allowed_values=["b", "f"])

Am I missing something?

@yoavkatz
Copy link
Member

Two issues: (1) This is not backward compatible, what if anyone using it now? (2) The same behavior can be achieved with current implementation: Intersect(field_to_field={"label": "label", "name": "name"}, allowed_values=["b", "f"])

Am I missing something?

This relates to a need (e.g in ner datasets) to filter multiple fields together ( e.g keep only two entity types and remove the start ,end, and label fields).

The current code changes are not backwards compatible (e.g hard code the field to " labels").

I'll write more details later on how to address.

@yoavkatz yoavkatz changed the title Modify Intersect operator Create new IntersectCorrespondingFields operator Jan 25, 2025
@yoavkatz
Copy link
Member

To keep things backward compatible, but still consistent - I've add a new Operator called IntersectCorrespondingFields.

"""Intersects the value of a field, which must be a list, with a given list , and removes corresponding elements from other list fields.

For example:

Assume the instances contain a field of 'labels' and a field with the labels' corresponding 'positions' in the text.

IntersectCorrespondingFields(field="label",
                             allowed_values=["b", "f"],
                             corresponding_fields_to_intersect=["position"])

would keep only "b" and "f" values in 'labels' field and
their respective values in the 'position' field.
(All other fields are not effected)

Given this input:

[
    {"label": ["a", "b"],"position": [0,1],"other" : "not"},
    {"label": ["a", "c", "d"], "position": [0,1,2], "other" : "relevant"},
    {"label": ["a", "b", "f"], "position": [0,1,2], "other" : "field"}
]

So the output would be:
[
        {"label": ["b"], "position":[1],"other" : "not"},
        {"label": [], "position": [], "other" : "relevant"},
        {"label": ["b", "f"],"position": [1,2], "other" : "field"},
]

Args:
    field - the field to intersected (must contain list values)
    allowed_values (list) - list of values to keep
    corresponding_fields_to_intersect (list) - additional list fields from which values
    are removed based the corresponding index of values removed from the 'field'
"""

Also updated the test cases.

@yoavkatz yoavkatz merged commit 121c268 into main Jan 30, 2025
17 of 18 checks passed
@yoavkatz yoavkatz deleted the add_entity_type_filter_to_operators branch January 30, 2025 15:08
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.

3 participants