Skip to content

Commit 38387fc

Browse files
authored
Update nlp.py
1 parent 2b4a9c2 commit 38387fc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tensorlayer/nlp.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def simple_read_words(filename="nietzsche.txt"):
394394
words = f.read()
395395
return words
396396

397-
def read_words(filename="nietzsche.txt", replace = [b'\n', b'<eos>']):
397+
def read_words(filename="nietzsche.txt", replace = ['\n', '<eos>']):
398398
"""File to list format context. Note that, this script can not handle punctuations.
399399
For customized read_words method, see ``tutorial_generate_text.py``.
400400
@@ -415,7 +415,12 @@ def read_words(filename="nietzsche.txt", replace = [b'\n', b'<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)