Skip to content

Commit a80bdbe

Browse files
committed
Fixes for Python 3 compatibility.
* Use six.iteritems to ensure lazy iteration on both Python 2 and Python 3 * Use integer division when dividing epoch_size by n_save
1 parent 0787ebc commit a80bdbe

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

char_rnn_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def run_epoch(self, session, data_size, batch_generator, is_training,
216216
state = session.run(self.zero_state)
217217
self.reset_loss_monitor.run()
218218
start_time = time.time()
219-
for step in range(epoch_size / divide_by_n):
219+
for step in range(epoch_size // divide_by_n):
220220
# Generate the batch and use [:-1] as inputs and [1:] as targets.
221221
data = batch_generator.next()
222222
inputs = np.array(data[:-1]).transpose()

train.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import numpy as np
1313
from char_rnn_model import *
14+
from six import iteritems
1415

1516

1617
def main():
@@ -364,7 +365,7 @@ def load_vocab(vocab_file, encoding):
364365
vocab_index_dict = json.load(f)
365366
index_vocab_dict = {}
366367
vocab_size = 0
367-
for char, index in vocab_index_dict.iteritems():
368+
for char, index in iteritems(vocab_index_dict):
368369
index_vocab_dict[index] = char
369370
vocab_size += 1
370371
return vocab_index_dict, index_vocab_dict, vocab_size

0 commit comments

Comments
 (0)