Skip to content

fix: store key-value pairs in the hashmap preserving the order of insertions #1

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

umbertogriffo
Copy link

@umbertogriffo umbertogriffo commented Sep 25, 2024

This PR:

  • Fixes a severe bug in saving and loading the merging rules.
  • Checks if an element is missing from the vocabulary, raising a warning.
  • Drops a useless \n while writing the vocabulary.

The bug

Since we were using BTreeMap we saved and loaded the merging rules (pair and index) not following the order of insertions, causing the following errors while loading the model:

Screenshot from 2024-09-25 10-01-32

The pairs are not found in the vocabulary since the order of the pairs during the saving and load was wrong.

To fix the issue, we need to use an IndexMap type from the indexmap crate since the standard HashMap in Rust does not maintain insertion order. The issue is not present in the Python version since, from Python 3.7, the built-in dict type maintains insertion order by default.

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.

1 participant