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

convert chord maps back to tuples from list when loading tokenizer from a saved configuration #141

Merged
merged 1 commit into from
Jan 27, 2024

Conversation

shenranwang
Copy link
Contributor

@shenranwang shenranwang commented Jan 26, 2024

Hi,

I encountered an issue with chord maps when loading a saved tokenizer configuration from a file.

The CHORD_MAPS constant value has each chord map defined in a tuple, but after creating a tokenizer and saving the configuration, the chord maps are represented as lists (example snippet below):

...
"chord_maps": {
            "min": [
                0,
                3,
                7
            ],
            "maj": [
                0,
                4,
                7
            ],
...
            "9min": [
                0,
                4,
                7,
                10,
                13
            ]
        },
...

This is caused by json.dump converting all tuples into lists. This results in the detect_chords function always returning ukn chord tokens, i.e. 'Chord_A:ukn3', 'Chord_E:ukn3', etc.

There are a few ways to fix this:

  • Make sure when saving the tokenizer config that the chord maps remain as tuples
  • After loading the tokenizer, convert chord maps back into tuples
  • Convert chord maps into lists and adjusting tests and documentation wherever necessary

I've implemented the second one for this PR, as it required the least amount of work and fixes the issue.


📚 Documentation preview 📚: https://miditok--141.org.readthedocs.build/en/141/

Copy link
Owner

@Natooz Natooz left a comment

Choose a reason for hiding this comment

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

Excellent, nice catch thank you!

I won't forget to also include chord maps in the save/load tests later!

Copy link

codecov bot commented Jan 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (84de034) 91.23% compared to head (05732d8) 91.01%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #141      +/-   ##
==========================================
- Coverage   91.23%   91.01%   -0.23%     
==========================================
  Files          33       33              
  Lines        4917     4919       +2     
==========================================
- Hits         4486     4477       -9     
- Misses        431      442      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Natooz Natooz merged commit ebd2d61 into Natooz:main Jan 27, 2024
15 checks passed
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.

None yet

2 participants