

def parse_stories(lines, only_supporting=False):
    'Parse stories provided in the bAbi tasks format\n\n    If only_supporting is true, only the sentences that support the answer are kept.\n    '
    data = []
    story = []
    for line in lines:
        line = line.decode('utf-8').strip()
        (nid, line) = line.split(' ', 1)
        nid = int(nid)
        if (nid == 1):
            story = []
        if ('\t' in line):
            (q, a, supporting) = line.split('\t')
            q = tokenize(q)
            substory = None
            if only_supporting:
                supporting = map(int, supporting.split())
                substory = [story[(i - 1)] for i in supporting]
            else:
                substory = [x for x in story if x]
            data.append((substory, q, a))
            story.append('')
        else:
            sent = tokenize(line)
            story.append(sent)
    return data

dataset/ETHPy150Open fchollet/keras/examples/babi_rnn.py parse_stories/original