Skip to content
New issue

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

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

Already on GitHub? # to your account

TypeError: string indices must be integers #734

Closed
kruthikakr opened this issue Mar 5, 2021 · 4 comments · Fixed by #735
Closed

TypeError: string indices must be integers #734

kruthikakr opened this issue Mar 5, 2021 · 4 comments · Fixed by #735
Labels
bug Something isn't working

Comments

@kruthikakr
Copy link

kruthikakr commented Mar 5, 2021

Hi not sure if it is a bug , but i am trying to follow the steps in the tutorial and found the issue
I am using Transformer model model is being downloaded

from farm.infer import *

nlp = Inferencer.load("bert-large-uncased-whole-word-masking-finetuned-squad", task_type="question_answering")

Run predictions

QA_input = [{"qas": ["Why is model conversion important?"],
"context": "Model conversion lets people easily switch between frameworks."}]
result = nlp.inference_from_dicts(dicts=QA_input)

But getting the error as :
question_text = q["question"]
TypeError: string indices must be integers

@kruthikakr kruthikakr added the bug Something isn't working label Mar 5, 2021
@julian-risch
Copy link
Member

julian-risch commented Mar 5, 2021

Hi @kruthikakr could you please use this format for QA_input and let me know whether it solves your problem?
QA_input = [ { "questions": ["Why is model conversion important?"], "text": "Model conversion lets people easily switch between frameworks." }]

@kruthikakr
Copy link
Author

kruthikakr commented Mar 5, 2021

Thank you for response Yes it worked.

and the output of result is [{'task': 'qa', 'predictions': [{'question': 'How did the gross margin change?', 'id': '0-0', 'ground_truth': [], 'answers': [{'score': 13.446313858032227, 'probability': None, 'answer': 'largely stable quarter-to-quarter', 'offset_answer_start': 2103, 'offset_answer_end': 2136, 'context': 'egment. The gross margin remained largely stable quarter-to-quarter, falling from 39.8 percent to 39', 'offset_context_start': 2069, 'offset_context_end': 2169, 'document_id': '0-0'}, {'score': 12.707515716552734, 'probability': None, 'answer': 'largely stable quarter-to-quarter, falling from 39.8 percent to 39.5 percent', 'offset_answer_start': 2103, 'offset_answer_end': 2179, 'context': 'in remained largely stable quarter-to-quarter, falling from 39.8 percent to 39.5 percent. Included t', 'offset_context_start': 2091, 'offset_context_end': 2191, 'document_id': '0-0'}, {'score': 12.551894187927246, 'probability': None, 'answer': 'The gross margin remained largely stable quarter-to-quarter', 'offset_answer_start': 2077, 'offset_answer_end': 2136, 'context': 'tions (DSS) segment. The gross margin remained largely stable quarter-to-quarter, falling from 39.8 ', 'offset_context_start': 2056, 'offset_context_end': 2156, 'document_id': '0-0'}, {'score': 11.987415313720703, 'probability': None, 'answer': 'falling from 39.8 percent to 39.5 percent', 'offset_answer_start': 2138, 'offset_answer_end': 2179, 'context': 'ly stable quarter-to-quarter, falling from 39.8 percent to 39.5 percent. Included therein are acquis', 'offset_context_start': 2108, 'offset_context_end': 2208, 'document_id': '0-0'}, {'score': 11.898091316223145, 'probability': None, 'answer': 'largely stable quarter-to-quarter, falling from 39.8 percent to 39.5 percent.', 'offset_answer_start': 2103, 'offset_answer_end': 2180, 'context': 'in remained largely stable quarter-to-quarter, falling from 39.8 percent to 39.5 percent. Included t', 'offset_context_start': 2091, 'offset_context_end': 2191, 'document_id': '0-0'}], 'no_ans_gap': 7.642787456512451}]}]

should i call the aggregator here to have the final answer ?

@julian-risch
Copy link
Member

julian-risch commented Mar 5, 2021

Thanks for trying that. Happy to hear that it works now. I will make sure that the tutorial is updated.
Aggregation is only needed to aggregate predictions across different samples. The document here is relatively small. It seems that all the predictions are coming from the same sample. in that case, take the top answer with the highest score.
Regarding the aggregation of predictions: I recommend having a look at this line of code:

aggregate_preds = hasattr(self.model.prediction_heads[0], "aggregate_preds")

It shows that the aggregation of predictions depends on the model.
I will close this issue after having updated the tutorial with regards to the format of QA_input.

@kruthikakr
Copy link
Author

please provide me with the information , In the squad question answering demo , there is a limit of 15000 words . Which parameters decides the limit .
And where is the code line which outputs the top answer in case the context is small .. or when the aggregation should be used .

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants