Skip to content

ENH: Refactor examples API #185

Closed
Closed

Description

@NickleDave
  • It's annoying that we need to specify a return_type when we call examples, and that if we don't, we get the path by default; usually I just want a Sound instead
  • this also makes extra work when I want a larger example dataset (which is still not a full dataset, so I think we should resist a scikit-learn-like datasets API, at least for now. Make pollyglot an extra at some point, maybe) -- I have to specify the type and then make additional call to examples to get multiple "types", e.g. the Sounds and the Annotations

I think we should do the following:

  • for built-in examples that are a sound file, just return a Sound
  • if we add other types of examples later, just return the type by default too; e.g., Spectrogram or Annotation
  • change the return_type to a Boolean return_path argument that if True returns the path (the way we do now by default) -- but have it default to False
  • for larger example datasets, have a scikit-learn-style Bunch that we return with keys for "sounds", "annotations", etc. The idea here is that we get everything for the example dataset in one fell swoop, and we also don't prescribe via strict attribute names or something what exactly is in the dataset; I can imagine scenarios, say datasets from behavioral experiments, where we might want to return stuff that's not strictly a built-in VocalPy-specific type. The reason to have a Bunch is so that we can have dotted attribute acces like the sklearn Bunch does (via the __getattr__ dunder)

Activity

  1. self-assigned this
    on Oct 8, 2024
  2. added a commit that references this issue on Oct 13, 2024
    e0268c9
  3. NickleDave commented on Oct 13, 2024

    @NickleDave
    ContributorAuthor

    I think I should further refactor to do what I did when I rewrote crowsetta.data as crowsetta.examples:

    • have an Example dataclass that is basically what we call ExampleMetadata now; this will be internal to the _example module but it makes it clear that what we are representing with the class is a specific example
    • We should also put all the metadata in a static json file, and (again as in crowsetta) add a classmethod from_metadata that makes an Example instance from the metadata in the json; i.e. there will be a json file that is a list ("array") of dicts ("objects"), and we will get an Example for each "object"
    • and have a separate text file with a description, which is what we now call metadata as a field on the ExampleMeta class (confusingly)
    • and then load all the Examples inside the module and have the REGISTRY just be a mapping from Example.name to Example (for each instance)
  4. added 2 commits that reference this issue on Oct 13, 2024
    59e5202
    f3d40e3
  5. closed this as completedby moving to Done in vocalpy-0.10.0on Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions