(article)
return rows
Flatten each article in training data.
Flatten each article in training data.
Flatten each article in training data .
def proc_train(article):
    '''Flatten each article in training data.'''
    rows = []
    for paragraph in article['paragraphs']:
        context = paragraph['context']
        for qa in paragraph['qas']:
            id_, question, answers = qa['id'], qa['question'], qa['answers']
            answer = answers[0]['text']  # in training data there's only one answer
            answer_start = answers[0]['answer_start']
            answer_end = answer_start + len(answer)
            rows.append((id_, context, question, answer, answer_start, answer_end))
    return rows
def proc_train ( article ) : rows = [ ] for paragraph in article [ 'paragraphs' ] : context = paragraph [ 'context' ] for qa in paragraph [ 'qas' ] : id_ , question , answers = qa [ 'id' ] , qa [ 'question' ] , qa [ 'answers' ] answer = answers [ 0 ] [ 'text' ] # in training data there's only one answer answer_start = answers [ 0 ] [ 'answer_start' ] answer_end = answer_start + len ( answer ) rows . append ( ( id_ , context , question , answer , answer_start , answer_end ) ) return rows