Python AttributeError:“非类型”对象没有属性“strip”jupyter笔记本

Python AttributeError:“非类型”对象没有属性“strip”jupyter笔记本,python,deep-learning,jupyter-notebook,nonetype,question-answering,Python,Deep Learning,Jupyter Notebook,Nonetype,Question Answering,我正在尝试运行一个问答系统的实现。 运行第8个单元后: challenges = { # QA1 with 10,000 samples 'single_supporting_fact_10k': 'tasks_1-20_v1-2/en-10k/qa1_single-supporting-fact_{}.txt', # QA2 with 10,000 samples 'two_supporting_facts_10k': 'tasks_1-20_v1-2/en-1

我正在尝试运行一个问答系统的实现。 运行第8个单元后:

challenges = {
    # QA1 with 10,000 samples
    'single_supporting_fact_10k': 'tasks_1-20_v1-2/en-10k/qa1_single-supporting-fact_{}.txt',
    # QA2 with 10,000 samples
    'two_supporting_facts_10k': 'tasks_1-20_v1-2/en-10k/qa2_two-supporting-facts_{}.txt',
}
challenge_type = 'single_supporting_fact_10k'
challenge = challenges[challenge_type]

print('Extracting stories for the challenge:', challenge_type)
train_stories = get_stories(tar.extractfile(challenge.format('train')))
test_stories = get_stories(tar.extractfile(challenge.format('test')))
我得到这个错误:

AttributeError:“非类型”对象没有属性“strip”

它在以下功能中使用了拆分:

def tokenize(sent):
    return [ x.strip() for x in re.split('(\W+)?', sent) if x.strip()]

def parse_stories(lines, only_supporting=False):
    '''Parse stories provided in the bAbi tasks format
    If only_supporting is true, only the sentences
    that support the answer are kept.
    '''
    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:
                # Only select the related substory
                supporting = map(int, supporting.split())
                substory = [story[i - 1] for i in supporting]
            else:
                # Provide all the substories
                substory = [x for x in story if x]
            data.append((substory, q, a))
            story.append('')
        else:
            sent = tokenize(line)
        story.append(sent)
return data
def get_stories(f, only_supporting=False, max_length=None):
    data = parse_stories(f.readlines(), only_supporting=only_supporting)
    flatten = lambda data: reduce(lambda x, y: x + y, data)
    data = [(flatten(story), q, answer) for story, q, answer in data if not max_length or len(flatten(story)) < max_length]
return data

我无法找出缺失的内容以及如何修复它。

据我所知,有一种情况是传递给tokenize的参数没有对象。因此,错误“NoneType”对象没有属性“strip”。您可能希望围绕tokenize调用设置一些try-catch,以查看何时将空字符串传递给函数


为了解决此问题,您可能需要浏览数据。

并且。。。代码在哪里?请提供一个