In the parse_squad function of exercise 2, I’m confused on how to extract the context from the paragraph. It says in the assignment that the context is usually the last element of the paragraph, so that would suggest paragraph[-1]. But this appears to return the last letter of the first word that appears in the article.
Hi @blackdragon
Note the structure of each example/article (it is show in the output of the prior cell). It is a nested structure and you should not use the integers (like -1) for indexing but keywords (like “context”).
Cheers
When I try to do that, I get an error message that string indices must be integers.
{mentor edit: code removed}
Take a close look and try to to understand the underlying structure:
The structure of each article is as follows:
title: The article title paragraphs: A list of paragraphs and questions related to them context: The actual paragraph text qas: A set of question related to the paragraph question: A question id: The question unique identifier is_imposible: Boolean, specifies if the question can be answered or not answers: A set of possible answers for the question text: The answer answer_start: The index of the character that starts the sentence containing the explicit answer to the question
Note that paragraphs are under the key “paragraphs” for each article.
For example, the i’th “paragraph” of an article is article['paragraphs'][i], but your second loop does not specify the key “paragraphs”.
And the same mistake for questions, which are under the “qas” key for each paragraph.
Cheers
{mentor edit: code removed}
A reminder:
Please do not post your code for the programming exercises. That’s not allowed by the Code of Conduct.