Skip to content

Commit d0d5d1c

Browse files
authored
Merge pull request #49 from sunbohit/patch-1
compatibility of python3.5 --> nlp/read_words()
2 parents 10d73fa + 38387fc commit d0d5d1c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

tensorlayer/nlp.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,12 @@ def read_words(filename="nietzsche.txt", replace = ['\n', '<eos>']):
415415
- `tensorflow.models.rnn.ptb.reader <https://github.com/tensorflow/tensorflow/tree/master/tensorflow/models/rnn/ptb>`_
416416
"""
417417
with tf.gfile.GFile(filename, "r") as f:
418-
return f.read().replace(*replace).split()
418+
try:
419+
context_list = f.read().replace(*replace).split()
420+
except:
421+
replace = [x.encode('utf-8') for x in replace]
422+
context_list = f.read().replace(*replace).split()
423+
return context_list
419424

420425
def read_analogies_file(eval_file='questions-words.txt', word2id={}):
421426
"""Reads through an analogy question file, return its id format.

0 commit comments

Comments
 (0)