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

fix Natural Question inference processing #521

Merged
merged 2 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/natural_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def question_answering():

print(f"\nQuestion: Did GameTrailers rated Twilight Princess as one of the best games ever created?"
f"\nAnswer from model: {result[0].prediction[0].answer}")
model.close_multiprcessing_pool()
model.close_multiprocessing_pool()

if __name__ == "__main__":
question_answering()
Expand Down
15 changes: 9 additions & 6 deletions farm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,15 @@ def stack(list_of_lists):


def try_get(keys, dictionary):
for key in keys:
if key in dictionary:
ret = dictionary[key]
if type(ret) == list:
ret = ret[0]
return ret
try:
for key in keys:
if key in dictionary:
ret = dictionary[key]
if type(ret) == list:
ret = ret[0]
return ret
except Exception as e:
logger.warning(f"Cannot extract from dict {dictionary} with error: {e}")
return None

class Benchmarker:
Expand Down