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

id_to_piece and piece_to_id return None in case of invalid inputs #43

Merged
merged 1 commit into from
Jul 4, 2023

Conversation

shadeMe
Copy link
Collaborator

@shadeMe shadeMe commented Jun 26, 2023

Description

Normalize id_to_piece and piece_to_id methods (and their equivalents) across all processors to return None instead of throwing when an invalid piece or piece identifier is encountered.

Types of change

Refactor

Checklist

  • I confirm that I have the right to submit this contribution under the project's MIT license.
  • I ran the tests, and all new and existing tests passed.
  • My changes don't require a change to the documentation, or if they do, I've added all required information.

@shadeMe shadeMe added the enhancement New feature or request label Jun 26, 2023
def test_id_to_piece_and_piece_to_id(toy_processor):
assert toy_processor.piece_to_id("woord") == 4083
assert toy_processor.piece_to_id("Ġwebsite") == 258
assert toy_processor.piece_to_id("kglw") is None
Copy link
Contributor

Choose a reason for hiding this comment

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

👨‍🎤

@@ -148,12 +148,10 @@ def test_id_to_piece_and_piece_to_id(toy_model):
assert toy_model.piece_to_id("<s>") == toy_model.bos_id()
assert toy_model.piece_to_id("</s>") == toy_model.eos_id()
assert toy_model.piece_to_id("<unk>") == toy_model.unk_id()
assert toy_model.piece_to_id("qotsa") == toy_model.unk_id()
assert toy_model.piece_to_id("qotsa") is None
Copy link
Contributor

Choose a reason for hiding this comment

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

👨‍🎤

@danieldk danieldk merged commit ac856cf into explosion:main Jul 4, 2023
6 checks passed
@shadeMe shadeMe deleted the refactor/piece-id-methods-api branch July 4, 2023 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants