allenai / bilm-tf

Tensorflow implementation of contextualized word representations from bi-directional language models
Apache License 2.0
1.62k stars 452 forks source link

Python 3.7 - RuntimeError: generator raised StopIteration #170

Closed MatejUlcar closed 5 years ago

MatejUlcar commented 5 years ago

Hello, following the change in the way StopIteration works (https://www.python.org/dev/peps/pep-0479/), running bin/run_test.py results in a RuntimeError.

Traceback:

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/bilm-0.1.post5-py3.7.egg/bilm/data.py", line 410, in get_sentence
    self._ids = self._load_random_shard()
  File "/usr/lib/python3.7/site-packages/bilm-0.1.post5-py3.7.egg/bilm/data.py", line 358, in _load_random_shard
    raise StopIteration
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "bin/run_test.py", line 42, in <module>
    main(args)
  File "bin/run_test.py", line 29, in main
    test(options, ckpt_file, data, batch_size=args.batch_size)
  File "/usr/lib/python3.7/site-packages/bilm-0.1.post5-py3.7.egg/bilm/training.py", line 1015, in test
    data.iter_batches(batch_size, 1), start=1):
  File "/usr/lib/python3.7/site-packages/bilm-0.1.post5-py3.7.egg/bilm/data.py", line 454, in iter_batches
    num_steps, max_word_length)
  File "/usr/lib/python3.7/site-packages/bilm-0.1.post5-py3.7.egg/bilm/data.py", line 284, in _get_batch
    cur_stream[i] = list(next(generator))
RuntimeError: generator raised StopIteration
MatejUlcar commented 5 years ago

Locally I replaced line 358 in bilm/data.py raise StopIteration with Return and line 285 in bilm/data.py except StopIteration with except Exception. I'm guessing the latter might not be necessary. I haven't thoroughly tested it, but it did work for my use case. I also don't know how this affects Python versions <=3.6.

dhpollack commented 5 years ago

@MatejUlcar this worked for me. thanks!

eduamf commented 4 years ago

@MatejUlcar this worked for me too. thanks!