sherjilozair / char-rnn-tensorflow

Multi-layer Recurrent Neural Networks (LSTM, RNN) for character-level language models in Python using Tensorflow
MIT License
2.64k stars 964 forks source link

sample.py crashes if training data did not have a space #97

Closed Jaspi10 closed 6 years ago

Jaspi10 commented 7 years ago

When sampling a model, whose vocab does not contain a space I get the following error:

Traceback (most recent call last):
  File "sample.py", line 46, in <module>
    main()
  File "sample.py", line 27, in main
    sample(args)
  File "sample.py", line 43, in sample
    args.sample).encode('utf-8'))
  File "E:\Projekte\tensorflow\rnn\char-rnn-tensorflow\model.py", line 107, in sample
    x[0, 0] = vocab[char]
KeyError: ' '

Simplest test case is that Hello world! works, but Helloworld! dose not.

I'm using tensorflow-gpu on python 3.5.0.

SRombauts commented 7 years ago

For future reference, you can simply work around this by specifying manually a prime texte with something adequate (that is, one or more character present in your vocabulary) like:

python sample.py --prime "abc"