huggingface / transformers

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
132.8k stars 26.46k forks source link

Bug in transformers v4.43.3: 'p_mask' variable type mismatch in pipelines/question_answering.py #32398

Closed 8libra closed 1 month ago

8libra commented 1 month ago

System Info

Transformers v4.43.3, Python 3.12.4, Debian Linux

Who can help?

No response

Information

Tasks

Reproduction

  1. Install transformers v4.43.x.

  2. Trigger the bug with this script:

#! /usr/bin/env python
from transformers import pipeline
checkpoint = "impira/layoutlm-document-qa"
nlp = pipeline("document-question-answering", model = checkpoint)

url = "https://templates.invoicehome.com/invoice-template-us-neat-750px.png"
question = "What is the invoice number?"
p = nlp(url, question)
  1. The issue is found when Comparing .../site-packages/transformers/pipelines/question_answering.py between transformers v4.42.4 and transformers v4.43.3. Here's the diff:
121c121
<     undesired_tokens = np.abs(np.array(p_mask) - 1)
---
>     undesired_tokens = np.abs(p_mask.numpy() - 1)

The variable p_mask is of type list and has no numpy() method.

Expected behavior

No crash

ArthurZucker commented 1 month ago

Hey! would you like to open a PR to fix this?

JamesSand commented 1 month ago

Hi @ArthurZucker , I have checked the code. It seems this issue has been fixed in the current version of code. Please refer to this line of code

8libra commented 1 month ago

Thanks. I’m going to mark this as close.