Skip to content

Commit b26307a

Browse files
committed
GH-3400: fix mypy errors
1 parent 47faa24 commit b26307a

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

flair/embeddings/transformer.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def document_max_pooling(sentence_hidden_states: torch.Tensor, sentence_lengths:
223223

224224
def map_tokens_to_subtokens(subtoken_offsets, token_offsets, verbose: bool = False, subtokens=None, tokens=None):
225225

226-
mapping = []
226+
mapping: list[Optional[int]] = []
227227
for subtoken_id, subtoken in enumerate(subtoken_offsets):
228228

229229
# subtokens of length 0 should not be mapped to anything
@@ -702,6 +702,7 @@ def __build_transformer_model_inputs(
702702

703703
if self.use_raw_text_as_input:
704704
word_ids_list = []
705+
assert flair_tokens # assert that this is not None for mypy type checking
705706
for sentence_no, sentence_tokens in enumerate(flair_tokens):
706707

707708
subtoken_offsets = batch_encoding["offset_mapping"][sentence_no]
@@ -729,8 +730,6 @@ def __build_transformer_model_inputs(
729730
# word_ids is only supported for fast rust tokenizers. Some models like "xlm-mlm-ende-1024" do not have
730731
# a fast tokenizer implementation, hence we need to fall back to our own reconstruction of word_ids.
731732

732-
# print(word_ids_list)
733-
734733
if self.token_embedding:
735734
assert offsets is not None # for type checking
736735
if self.allow_long_sentences:

0 commit comments

Comments
 (0)