Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HappyBERT throws an error while running the Q&A example #144

Closed
KiranAkadas opened this issue Dec 7, 2020 · 4 comments
Closed

HappyBERT throws an error while running the Q&A example #144

KiranAkadas opened this issue Dec 7, 2020 · 4 comments

Comments

@KiranAkadas
Copy link

KiranAkadas commented Dec 7, 2020

Python 3.8.5

happy_bert = HappyBERT()
question = "Who does Ernie live with?"
text = "Ernie is an orange Muppet character on the long running PBS and HBO children's television show Sesame Street. He and his roommate Bert form the comic duo Bert and Ernie, one of the program's centerpieces, with Ernie acting the role of the naïve troublemaker and Bert the world weary foil."  # Source: https://en.wikipedia.org/wiki/Ernie_(Sesame_Street)
result = happy_bert.answer_question(question,text)
print(type(result)) # prints: <class 'str'>
print(result) # prints: bert

The example given in the official documentation gives the following error when run:

TypeError                                 Traceback (most recent call last)
<ipython-input-8-618d260e51a7> in <module>()
      2 question = "Who does Ernie live with?"
      3 text = "Ernie is an orange Muppet character on the long running PBS and HBO children's television show Sesame Street. He and his roommate Bert form the comic duo Bert and Ernie, one of the program's centerpieces, with Ernie acting the role of the naïve troublemaker and Bert the world weary foil."  # Source: https://en.wikipedia.org/wiki/Ernie_(Sesame_Street)
----> 4 result = happy_bert.answer_question(question,text)
      5 print(type(result)) # prints: <class 'str'>
      6 print(result) # prints: bert

/usr/local/lib/python3.6/dist-packages/happytransformer/happy_bert.py in answer_question(self, question, text)
    140                                                token_type_ids=segment_tensor)
    141         all_tokens = self.tokenizer.convert_ids_to_tokens(input_ids)
--> 142         answer_list = all_tokens[torch.argmax(start_scores):
    143                                  torch.argmax(end_scores)+1]
    144         answer = self.tokenizer.convert_tokens_to_string(answer_list)

TypeError: argmax(): argument 'input' (position 1) must be Tensor, not str
@ted537
Copy link
Collaborator

ted537 commented Dec 8, 2020

You say Python 3.8.5 but your path is at /usr/local/lib/python3.6

This is probably related to the dependencies in setup.py, as they are not versioned currently

@skymansandy
Copy link

skymansandy commented Dec 8, 2020

Hey @ted537, @EricFillion. I faced this error too.

Looks like destructuring the output of the qa model into start_scores and end_scores is somehow causing them to be type string instead of tensor. Not sure if this has something to do with the python version being used?

For a temporary solution, I changed the library code a bit to make it run on my machine. Stored the qa model output in a scores and used indexing to get the scores. (scores[0], scores[1] for start and end scores).

PS: I'm on python 3.8.5.

@EricFillion
Copy link
Owner

Thank you @KiranAkadas and @skymansandy. I just created a PR to address this issue. Ted and I are both in the middle of exams, but we'll be sure to publish an update shortly.

@EricFillion
Copy link
Owner

EricFillion commented Dec 13, 2020

I just published an update to PyPi that resolves this issue. I hope it helps :) @KiranAkadas @skymansandy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants