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 CustomFeature base class to support user-defined features with encoding/decoding logic #7221

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

alex-hh
Copy link
Contributor

@alex-hh alex-hh commented Oct 11, 2024

intended as fix for #7220 if this kind of extensibility is something that datasets is willing to support!

from datasets.features.features import CustomFeature


class ListOfStrs(CustomFeature):
    requires_encoding = True
    def _encode_example(self, value):
        if isinstance(value, str):
            return [str]
        else:
            return value
feats = Features(strlist=ListOfStrs())
feats.encode_example({"strlist": "a"})["strlist"] == feats["strlist"].encode_example("a")

@alex-hh alex-hh changed the title add Feature base class to improve support for user-defined features add CustomFeature base class to support for user-defined features Nov 2, 2024
@alex-hh alex-hh changed the title add CustomFeature base class to support for user-defined features add CustomFeature base class to support user-defined features with encoding/decoding logic Nov 2, 2024
@alex-hh alex-hh force-pushed the custom-feature-encoding branch from ee7caa6 to 977a0b7 Compare November 2, 2024 11:43
@alex-hh
Copy link
Contributor Author

alex-hh commented Nov 3, 2024

@lhoestq would you be open to supporting this kind of extensibility?

@lhoestq
Copy link
Member

lhoestq commented Nov 5, 2024

I suggested a fix in #7220 that would not necessarily require a parent class for custom features, lmk what you think

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