make p_mask a numpy array before passing to select_starts_ends (#32076)

* fix

* bug fix

* refine

* fix
This commit is contained in:
Fanli Lin 2024-07-29 17:29:11 +08:00 committed by GitHub
parent 535fe78b9f
commit 6494479f1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -378,7 +378,7 @@ class DocumentQuestionAnsweringPipeline(ChunkPipeline):
# p_mask: mask with 1 for token than cannot be in the answer (0 for token which can be in an answer)
# We put 0 on the tokens from the context and 1 everywhere else (question and special tokens)
# This logic mirrors the logic in the question_answering pipeline
p_mask = [[tok != 1 for tok in encoding.sequence_ids(span_id)] for span_id in range(num_spans)]
p_mask = np.array([[tok != 1 for tok in encoding.sequence_ids(span_id)] for span_id in range(num_spans)])
for span_idx in range(num_spans):
if self.framework == "pt":
span_encoding = {k: torch.tensor(v[span_idx : span_idx + 1]) for (k, v) in encoding.items()}