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

Bring back support for eq on sentence piece vocabulary based on md5 of the model #765

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion seqio/vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,18 @@ def _decode_tf(self, ids):
def __eq__(self, other):
if not isinstance(other, SentencePieceVocabulary):
return False
return self.__getstate__() == other.__getstate__()
if self.__getstate__() == other.__getstate__():
return True
if self.sp_model is None:
return False
try:
their_md5 = hashlib.md5(other.sp_model).hexdigest()
# If other has no sp_model attribute, we can't test for equality
except AttributeError:
return False
our_md5 = hashlib.md5(self.sp_model).hexdigest()
return our_md5 == their_md5


def __str__(self) -> str:
return (
Expand Down
Loading