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

Custom features not compatible with special encoding/decoding logic #7220

Open
alex-hh opened this issue Oct 11, 2024 · 0 comments
Open

Custom features not compatible with special encoding/decoding logic #7220

alex-hh opened this issue Oct 11, 2024 · 0 comments

Comments

@alex-hh
Copy link
Contributor

alex-hh commented Oct 11, 2024

Describe the bug

It is possible to register custom features using datasets.features.features.register_feature (#6727)

However such features are not compatible with Features.encode_example/decode_example if they require special encoding / decoding logic because encode_nested_example / decode_nested_example checks whether the feature is in a fixed list of encodable types:

elif isinstance(schema, (Audio, Image, ClassLabel, TranslationVariableLanguages, Value, _ArrayXD)):

This prevents the extensibility of features to complex cases

Steps to reproduce the bug

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

Expected behavior

Registered feature types should be encoded based on some property of the feature (e.g. requires_encoding)?

Environment info

3.0.2

@alex-hh alex-hh changed the title Custom features not compatible with special encoding logic Custom features not compatible with special encoding/decoding logic Oct 11, 2024
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

No branches or pull requests

1 participant