Haystack: Colab demo: finder.get_answers throws error

Created on 20 Apr 2020  路  10Comments  路  Source: deepset-ai/haystack

I was trying out the Bsic QA colab tutorial and the call to finder.get_answers throws following error

----> 1 prediction = finder.get_answers(question="Who is the father of Arya Stark?", top_k_retriever=10, top_k_reader=5)

1 frames
/usr/local/lib/python3.6/dist-packages/haystack/finder.py in get_answers(self, question, top_k_reader, top_k_retriever, filters)
     53 
     54         # 3) Apply reader to get granular answer(s)
---> 55         len_chars = sum([len(d.text) for d in documents])
     56         logger.info(f"Reader is looking for detailed answer in {len_chars} chars ...")
     57         results = self.reader.predict(question=question,

/usr/local/lib/python3.6/dist-packages/haystack/finder.py in <listcomp>(.0)
     53 
     54         # 3) Apply reader to get granular answer(s)
---> 55         len_chars = sum([len(d.text) for d in documents])
     56         logger.info(f"Reader is looking for detailed answer in {len_chars} chars ...")
     57         results = self.reader.predict(question=question,

AttributeError: 'list' object has no attribute 'text'

I looked through the codebase and it seems that finder.getanswers expects a list of Document objects form retriever.retrieve but retriever.retrieve returns a tuple with 2 lists, list of paragraph text and list of meta-data dicts.

bug

Most helpful comment

I managed to fix this issue by converting the list of Paragraph tuples to Document objects in retrieve method. Also changed the getanswers method to accept both document list and meta-data dicts. This fixed the issue.

All 10 comments

Thanks for reporting this @patil-suraj!

@tanaysoni Can you please have a look? I think it's related to our change from last Friday introducing the Document class. We haven't changed it for the SQL-based Retriever yet.

I managed to fix this issue by converting the list of Paragraph tuples to Document objects in retrieve method. Also changed the getanswers method to accept both document list and meta-data dicts. This fixed the issue.

Hey @patil-suraj, so there's is a pull request or something with the fix? Thanks

Hey @mansilla ,
We will update the tutorials tomorrow with a fix. Sorry for the inconvenience.

Great! Thanks for the hard work.

Hey @mansilla
You can install haystack from my fork to try the demo till the fix comes live. https://github.com/patil-suraj/haystack/

We are working on revamping the tutorials in #79 and incorporating the many new features released since the tutorials were written.

This issue will be fixed in the updated tutorials.

@tanaysoni Great! And thank you for resolving this issue.

@tanaysoni Thanks!

Fixed

Was this page helpful?
0 / 5 - 0 ratings