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

Error in QA #1

Closed
whoafridi opened this issue Dec 21, 2020 · 4 comments
Closed

Error in QA #1

whoafridi opened this issue Dec 21, 2020 · 4 comments

Comments

@whoafridi
Copy link

Gives an error in your code that I've tried in recent days! can you give me solution for this ???
Screenshot & error status available below .::

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-fa96e99fcb8e> in <module>()
     57 
     58 #Testing function
---> 59 bert_answering_machine ("Which state john's friend lives", 'My name is John. I live in San Jose, California. Rob is my friend. He lives in Seattle, Washington')

<ipython-input-4-fa96e99fcb8e> in bert_answering_machine(question, passage, max_len)
     29 
     30     #Converting scores tensors to numpy arrays so that we can use numpy functions
---> 31     start_token_scores = start_token_scores.detach().numpy().flatten()
     32     end_token_scores = end_token_scores.detach().numpy().flatten()
     33 

AttributeError: 'str' object has no attribute 'detach'

image

@Degananda264
Copy link

convert the start_token_scores,end_token_scores line of code into two lines as per below

getting start and end scores for answer. Converting input arrays to torch tensors before passing to the model

start_token_scores = model(torch.tensor([input_ids]), token_type_ids=torch.tensor([segment_ids]) )[0]
end_token_scores = model(torch.tensor([input_ids]), token_type_ids=torch.tensor([segment_ids]) )[1]

and run the same will give expected output

@whoafridi
Copy link
Author

Yes it works. Is the error for the new transformers updated package?

@Degananda264
Copy link

yeah might be

@whoafridi
Copy link
Author

Thanks for response .

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

2 participants