Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit 928948b

Browse files
authored
Fix logged error msg for FastTokenizer + QA (#541)
Former-commit-id: f340a9e Former-commit-id: 1aa26e7e51f959fe978315c97b76d0de639ee4b5
1 parent b1c92bb commit 928948b

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎farm/data_handler/input_features.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,16 @@ def sample_to_features_qa(sample, tokenizer, max_seq_len, sp_toks_start, sp_toks
438438
return_special_tokens_mask=True,
439439
return_token_type_ids=True)
440440

441-
if (len(encoded["input_ids"]) - encoded["special_tokens_mask"].count(1)) != \
442-
(len(sample.tokenized["question_tokens"]) + len(sample.tokenized["passage_tokens"])):
443-
logger.error(f"FastTokenizer encoded sample {sample.clear_text['text']} to "
444-
f"{len(encoded['input_ids']) - encoded['special_tokens_mask'].count(1)} tokens, which differs "
445-
f"from number of tokens produced in tokenize_with_metadata(). \n"
446-
f"Further processing is likely to be wrong.")
441+
n_tokens_encoded = len(encoded["input_ids"]) - encoded["special_tokens_mask"].count(1)
442+
n_tokens_with_metadata = len(sample.tokenized["question_tokens"]) + len(sample.tokenized["passage_tokens"])
443+
444+
if n_tokens_encoded != n_tokens_with_metadata:
445+
tokens_encoded = tokenizer.convert_ids_to_tokens(encoded["input_ids"])
446+
logger.error(f"FastTokenizer encoded sample to {n_tokens_encoded} tokens,"
447+
f" while the previous tokenize_with_metadata produced {n_tokens_with_metadata} tokens. \n"
448+
f"Further processing is likely to be wrong.\n"
449+
f"FastTokenizer: {tokens_encoded} \n"
450+
f"tokenize_with_metadata: {sample.tokenized['question_tokens'] + sample.tokenized['passage_tokens']}")
447451
else:
448452
encoded = tokenizer.encode_plus(text=sample.tokenized["question_tokens"],
449453
text_pair=sample.tokenized["passage_tokens"],

0 commit comments

Comments
 (0)