0

When I execute code available here https://keras.io/examples/babi_memnn/

I found this error

runfile('E:/Courses/PhD/ML/Sample Prog/Practicals/memNetworkBabi.py', wdir='E:/Courses/PhD/ML/Sample Prog/Practicals')
Using TensorFlow backend.
Extracting stories for the challenge: single_supporting_fact_10k
Traceback (most recent call last):

  File "<ipython-input-1-9db756ed995f>", line 1, in <module>
    runfile('E:/Courses/PhD/ML/Sample Prog/Practicals/memNetworkBabi.py', wdir='E:/Courses/PhD/ML/Sample Prog/Practicals')

  File "C:\Users\Khubaib\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 704, in runfile
    execfile(filename, namespace)

  File "C:\Users\Khubaib\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "E:/Courses/PhD/ML/Sample Prog/Practicals/memNetworkBabi.py", line 107, in <module>
    train_stories = get_stories(tar.extractfile(challenge.format('train')))

  File "E:/Courses/PhD/ML/Sample Prog/Practicals/memNetworkBabi.py", line 65, in get_stories
    data = parse_stories(f.readlines(), only_supporting=only_supporting)

  File "E:/Courses/PhD/ML/Sample Prog/Practicals/memNetworkBabi.py", line 52, in parse_stories
    sent = tokenize(line)

  File "E:/Courses/PhD/ML/Sample Prog/Practicals/memNetworkBabi.py", line 22, in tokenize
    return [x.strip() for x in re.split(r'(\W+)?', sent) if x.strip()]

  File "E:/Courses/PhD/ML/Sample Prog/Practicals/memNetworkBabi.py", line 22, in <listcomp>
    return [x.strip() for x in re.split(r'(\W+)?', sent) if x.strip()]

AttributeError: 'NoneType' object has no attribute 'strip'
barbsan
  • 3,418
  • 11
  • 21
  • 28
  • Your `x` variable is `None`. Check what `re.split(r'(\W+)?', sent)` returns – Swapnesh Khare May 09 '19 at 09:15
  • Yes its obvious as error message is printed, actually following lines of code need tar file opening which i thing failing, if you could check the program in link: print('Extracting stories for the challenge:', challenge_type) with tarfile.open(path) as tar: train_stories = get_stories(tar.extractfile(challenge.format('train'))) test_stories = get_stories(tar.extractfile(challenge.format('test'))) – Khubaib Ahmed May 10 '19 at 03:46

1 Answers1

0

Changing re.split(r'(\W+)?', sent) to re.split(r'(\W+)+', sent) in line 37 solved it for me, see also pull request in Keras: https://github.com/keras-team/keras/pull/13519

Metlam
  • 21
  • 2