Upgrade FARM version (#172)

This commit is contained in:
Tanay Soni 2020-06-24 15:14:09 +02:00 committed by GitHub
parent 587b2fe749
commit 44f89c94ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 5 deletions

View File

@ -411,8 +411,8 @@ class FARMReader(BaseReader):
@staticmethod
def _check_no_answer(d: dict):
# check for correct value in "answer"
if d["offset_answer_start"] == -1 and d["offset_answer_end"] == -1:
assert d["answer"] == "is_impossible"
if d["offset_answer_start"] == 0 and d["offset_answer_end"] == 0:
assert d["answer"] == "is_impossible", f"Check for no answer is not working"
# check weather the model thinks there is no answer
if d["answer"] == "is_impossible":

View File

@ -1,4 +1,4 @@
farm==0.4.4
farm==0.4.5
--find-links=https://download.pytorch.org/whl/torch_stable.html
fastapi
uvicorn

View File

@ -22,6 +22,7 @@ from haystack.reader.transformers import TransformersReader
from haystack.utils import print_answers
from haystack.retriever.elasticsearch import ElasticsearchRetriever
logger = logging.getLogger(__name__)
LAUNCH_ELASTICSEARCH = True
@ -75,7 +76,11 @@ dicts = convert_files_to_dicts(dir_path=doc_dir, clean_func=clean_wiki_text, spl
# It must take a str as input, and return a str.
# Now, let's write the docs to our DB.
document_store.write_documents(dicts)
if LAUNCH_ELASTICSEARCH:
document_store.write_documents(dicts)
else:
logger.warning("Since we already have a running ES instance we should not index the same documents again. \n"
"If you still want to do this call: document_store.write_documents(dicts) manually ")
# ## Initalize Retriever, Reader, & Finder
@ -137,7 +142,7 @@ finder = Finder(reader, retriever)
# ## Voilà! Ask a question!
# You can configure how many candidates the reader and retriever shall return
# The higher top_k_retriever, the better (but also the slower) your answers.
prediction = finder.get_answers(question="Who is the father of Arya Stark?", top_k_retriever=10, top_k_reader=5)
prediction = finder.get_answers(question="Who is the father of Sansa Stark?", top_k_retriever=10, top_k_reader=5)
# prediction = finder.get_answers(question="Who created the Dothraki vocabulary?", top_k_reader=5)