Fix tokenization for query marker #351
Open
+8
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request addresses the issue of inconsistent tokenization when prepending a query marker to the input text. The current implementation appends ". " at the beginning of each string and then replaces it with a query marker. This approach can lead to inconsistent behavior because different tokenizers might handle the punctuation and spaces differently, resulting in superfluous IDs within the tokenized output.
To resolve this issue, the changes ensure that the query marker is directly added to the beginning of each string before tokenization. This method avoids the potential inconsistency by ensuring that the query marker is always tokenized as a single token.
Changes
Modified the tensorize method in doc_tokenizer.py and query_tokenizer.py to prepend the query marker directly to each string in batch_text.
Included a utility to test if the query marker tokenizes into a single token, ensuring consistency across different tokenizers.
Related Issues
Fixes issue #346 .