Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
fix(server): skip the unknown-token id in the ColBERT punctuation skiplist
krisztian-gajdarb078a94c5573
diff --git a/packages/sie_server/src/sie_server/adapters/_colbert_utils.py b/packages/sie_server/src/sie_server/adapters/_colbert_utils.pyindex 7bf059a7d..16dbcb6f3 100644--- a/packages/sie_server/src/sie_server/adapters/_colbert_utils.py+++ b/packages/sie_server/src/sie_server/adapters/_colbert_utils.py@@ -5,10 +5,14 @@ from typing import Anydef punctuation_token_ids(tokenizer: Any) -> set[int]:- """Return exact punctuation vocabulary IDs without tokenizing the strings."""+ """Return exact punctuation vocabulary IDs without tokenizing the strings.++ Like PyLate's skiplist, a character missing from the vocabulary resolves+ to the unknown-token ID, which is then skipped as well.+ """token_ids: set[int] = set()for character in string.punctuation:token_id = tokenizer.convert_tokens_to_ids(character)- if isinstance(token_id, int) and token_id != tokenizer.unk_token_id:+ if isinstance(token_id, int):token_ids.add(token_id)return token_idsdiff --git a/packages/sie_server/tests/adapters/test_colbert_punctuation.py b/packages/sie_server/tests/adapters/test_colbert_punctuation.pyindex a5b72e0b0..95aa55643 100644--- a/packages/sie_server/tests/adapters/test_colbert_punctuation.py+++ b/packages/sie_server/tests/adapters/test_colbert_punctuation.py@@ -25,7 +25,7 @@ def test_punctuation_skiplist_uses_exact_ids_without_encoded_boundary_tokens() -assert 6 not in token_ids # XLM-R's incidental standalone word-boundary token.-def test_punctuation_skiplist_excludes_unknown_and_invalid_ids() -> None:+def test_punctuation_skiplist_keeps_the_unknown_id_and_excludes_invalid_ids() -> None:tokenizer = _TokenizerStub({"!": _TokenizerStub.unk_token_id,@@ -37,4 +37,4 @@ def test_punctuation_skiplist_excludes_unknown_and_invalid_ids() -> None:token_ids = punctuation_token_ids(tokenizer)- assert token_ids == {5}+ assert token_ids == {_TokenizerStub.unk_token_id, 5}