Skip to content

Commit 9221e3d

Browse files
committed
fix unicode error in specified shell
1 parent 3d00a35 commit 9221e3d

File tree

1 file changed

+6
-3
lines changed
  • chapter9-神经网络写诗(CharRNN)

1 file changed

+6
-3
lines changed

chapter9-神经网络写诗(CharRNN)/main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ def gen(**kwargs):
192192

193193
for k,v in kwargs.items():
194194
setattr(opt,k,v)
195-
196195
data,word2ix,ix2word = get_data(opt)
197196
model = PoetryModel(len(word2ix), 128, 256);
198197
map_location = lambda s,l:s
@@ -202,8 +201,12 @@ def gen(**kwargs):
202201
if opt.use_gpu:
203202
model.cuda()
204203
if sys.version_info.major == 3:
205-
start_words = opt.start_words.encode('ascii', 'surrogateescape').decode('utf8')
206-
prefix_words = opt.prefix_words.encode('ascii', 'surrogateescape').decode('utf8') if opt.prefix_words else None
204+
if opt.start_words.isprintable():
205+
start_words = opt.start_words
206+
prefix_words = opt.prefix_words if opt.prefix_words else None
207+
else:
208+
start_words = opt.start_words.encode('ascii', 'surrogateescape').decode('utf8')
209+
prefix_words = opt.prefix_words.encode('ascii', 'surrogateescape').decode('utf8') if opt.prefix_words else None
207210
else:
208211
start_words = opt.start_words.decode('utf8')
209212
prefix_words = opt.prefix_words.decode('utf8') if opt.prefix_words else None

0 commit comments

Comments
 (0)