From 8000432e7061d8a1206753e0abec275bb0bce331 Mon Sep 17 00:00:00 2001 From: Marianne Linhares Monteiro Date: Mon, 14 Aug 2017 18:45:44 -0400 Subject: [PATCH 1/8] adding RNNCell_min_char_rnn --- extras/RNNCell_min_char_rnn.py | 159 +++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 extras/RNNCell_min_char_rnn.py diff --git a/extras/RNNCell_min_char_rnn.py b/extras/RNNCell_min_char_rnn.py new file mode 100644 index 0000000..5096c9e --- /dev/null +++ b/extras/RNNCell_min_char_rnn.py @@ -0,0 +1,159 @@ +""" +Adapted from Karpathy's min-char-rnn.py +https://gist.github.com/karpathy/d4dee566867f8291f086 +Requires tensorflow>=1.0 +BSD License + +Modified by: Marianne Linhares (@mari-linhares) +""" + +import numpy as np +import tensorflow as tf +from tensorflow.contrib import layers + +print(tf.__version__) + +# data I/O + +# should be simple plain text file +data = open('data/about_tensorflow.txt', 'r').read() +chars = list(set(data)) + +DATA_SIZE, VOCAB_SIZE = len(data), len(chars) +print('data has %d characters, %d unique.' % (DATA_SIZE, VOCAB_SIZE)) + +char_to_ix = {ch: i for i, ch in enumerate(chars)} +ix_to_char = {i: ch for i, ch in enumerate(chars)} + +# hyperparameters +HIDDEN_SIZE = 100 # hidden layer's size +SEQ_LENGTH = 25 # number of steps to unroll +LEARNING_RATE = 0.1 # size of step for Gradient Descent +BATCH_SIZE = 1 # number of sequences evaluated at each train step + +# TensorFlow graph definition + +# Placeholders +inputs = tf.placeholder(shape=[None, None], dtype=tf.int32, name='inputs') +targets = tf.placeholder(shape=[None, None], dtype=tf.int32, name='targets') +init_state = tf.placeholder(shape=[None, HIDDEN_SIZE], dtype=tf.float32, + name='state') + +# RNN + +# [ BATCH_SIZE, SEQ_LEN, VOCAB_SIZE ] +input_x = tf.one_hot(inputs, VOCAB_SIZE) +input_y = tf.one_hot(targets, VOCAB_SIZE) + +# creating a RNN cell +rnn_cell = tf.nn.rnn_cell.BasicRNNCell(HIDDEN_SIZE) +# you can use a GRUCell by changing one line of code +''' +rnn_cell = tf.nn.rnn_cell.GRUCell(HIDDEN_SIZE) +''' + +# run RNN +# rnn_outputs: [ BATCH_SIZE, SEQ_LEN, HIDDEN_SIZE] +# final_state: [ BATCH_SIZE, HIDDEN_SIZE] +rnn_outputs, final_state = tf.nn.dynamic_rnn(rnn_cell, input_x, + initial_state=init_state, + dtype=tf.float32) + +# add dense layer on top of the RNN outputs +rnn_outputs_flat = tf.reshape(rnn_outputs, [-1, HIDDEN_SIZE]) +dense_layer = layers.linear(rnn_outputs_flat, VOCAB_SIZE) +labels = tf.reshape(input_y, [-1, VOCAB_SIZE]) +output_softmax = tf.nn.softmax(dense_layer) + +# Loss +loss = tf.reduce_sum( + tf.nn.softmax_cross_entropy_with_logits(logits=dense_layer, + labels=labels)) + +# Minimizer +optimizer = tf.train.AdagradOptimizer(learning_rate=LEARNING_RATE) +minimizer = optimizer.minimize(loss) + +# Gradient clipping +# In this code we're not using gradient clipping, just to make things simpler +# but if you want to use it, the code below implements it. +''' +grads_and_vars = minimizer.compute_gradients(loss) + +grad_clipping = tf.constant(5.0, name='grad_clipping') +clipped_grads_and_vars = [] +for grad, var in grads_and_vars: + clipped_grad = tf.clip_by_value(grad, -grad_clipping, grad_clipping) + clipped_grads_and_vars.append((clipped_grad, var)) + +updates = minimizer.apply_gradients(clipped_grads_and_vars) +''' +# Create session and initialize variables +sess = tf.Session() +init = tf.global_variables_initializer() +sess.run(init) + +# Training + +# n: counts the number of steps, p: pointer to position in sequence +n, p = 0, 0 + +# this var will be used for sampling +hprev_val = np.zeros([1, HIDDEN_SIZE]) + +# loss at iteration 0 +smooth_loss = -np.log(1.0 / VOCAB_SIZE) * SEQ_LENGTH + +while True: + # prepare inputs (we're sweeping from left to right in steps SEQ_LENGTH long) + if p + SEQ_LENGTH + 1 >= len(data) or n == 0: + hprev_val = np.zeros([BATCH_SIZE, HIDDEN_SIZE]) # reset RNN memory + p = 0 # go from start of data + + start_index = p + end_index = p + SEQ_LENGTH + + input_vals = [char_to_ix[ch] for ch in data[start_index: end_index]] + input_vals = np.reshape(input_vals, (-1, SEQ_LENGTH)) + + target_vals = [char_to_ix[ch] for ch in data[start_index + 1: end_index+ 1]] + target_vals = np.reshape(target_vals, (-1, SEQ_LENGTH)) + + # sampling + if n % 1000 == 0: + sample_length = 200 + hprev_sample = np.copy(hprev_val) + + # start from the first letter from the input + first_char = char_to_ix[data[p]] + x = np.asarray([[first_char]]) + # stores predictions + sample_ix = [] + + for t in range(sample_length): + pred, hprev_sample = sess.run([output_softmax, final_state], + feed_dict={inputs: x, + init_state: hprev_sample}) + + # generates next letter + ix = np.random.choice(range(VOCAB_SIZE), p=pred.ravel()) + # update next char with the prediction + x = np.asarray([[ix]]) + sample_ix.append(ix) + + txt = ''.join(ix_to_char[ix] for ix in sample_ix) + print('----\n%s\n----' % (txt)) + + # running the graph + hprev_val, loss_val, _ = sess.run([final_state, loss, minimizer], + feed_dict={inputs: input_vals, + targets: target_vals, + init_state: hprev_val}) + + # print progress + smooth_loss = smooth_loss * 0.999 + loss_val * 0.001 + if n % 100 == 0: print('iter %d, loss: %f' % (n, smooth_loss)) + + p += SEQ_LENGTH + n += 1 + From e6f9d39cc399f25b96b8ec13034867913c8cc364 Mon Sep 17 00:00:00 2001 From: Marianne Linhares Monteiro Date: Tue, 15 Aug 2017 10:16:51 -0400 Subject: [PATCH 2/8] Create RNNCell_min_char_rnn.py --- extras/min-char-rnn/RNNCell_min_char_rnn.py | 158 ++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 extras/min-char-rnn/RNNCell_min_char_rnn.py diff --git a/extras/min-char-rnn/RNNCell_min_char_rnn.py b/extras/min-char-rnn/RNNCell_min_char_rnn.py new file mode 100644 index 0000000..d4029da --- /dev/null +++ b/extras/min-char-rnn/RNNCell_min_char_rnn.py @@ -0,0 +1,158 @@ +""" +Adapted from Karpathy's min-char-rnn.py +https://gist.github.com/karpathy/d4dee566867f8291f086 +Requires tensorflow>=1.0 +BSD License + +Modified by: Marianne Linhares (@mari-linhares) +""" + +import numpy as np +import tensorflow as tf +from tensorflow.contrib import layers + +print(tf.__version__) + +# data I/O + +# should be simple plain text file +data = open('data/about_tensorflow.txt', 'r').read() +chars = list(set(data)) + +DATA_SIZE, VOCAB_SIZE = len(data), len(chars) +print('data has %d characters, %d unique.' % (DATA_SIZE, VOCAB_SIZE)) + +char_to_ix = {ch: i for i, ch in enumerate(chars)} +ix_to_char = {i: ch for i, ch in enumerate(chars)} + +# hyperparameters +HIDDEN_SIZE = 100 # hidden layer's size +SEQ_LENGTH = 25 # number of steps to unroll +LEARNING_RATE = 0.1 # size of step for Gradient Descent +BATCH_SIZE = 1 # number of sequences evaluated at each train step + +# TensorFlow graph definition + +# Placeholders +inputs = tf.placeholder(shape=[None, None], dtype=tf.int32, name='inputs') +targets = tf.placeholder(shape=[None, None], dtype=tf.int32, name='targets') +init_state = tf.placeholder(shape=[None, HIDDEN_SIZE], dtype=tf.float32, + name='state') + +# RNN + +# [ BATCH_SIZE, SEQ_LEN, VOCAB_SIZE ] +input_x = tf.one_hot(inputs, VOCAB_SIZE) +input_y = tf.one_hot(targets, VOCAB_SIZE) + +# creating a RNN cell +rnn_cell = tf.nn.rnn_cell.BasicRNNCell(HIDDEN_SIZE) +# you can use a GRUCell by changing one line of code +''' +rnn_cell = tf.nn.rnn_cell.GRUCell(HIDDEN_SIZE) +''' + +# run RNN +# rnn_outputs: [ BATCH_SIZE, SEQ_LEN, HIDDEN_SIZE] +# final_state: [ BATCH_SIZE, HIDDEN_SIZE] +rnn_outputs, final_state = tf.nn.dynamic_rnn(rnn_cell, input_x, + initial_state=init_state, + dtype=tf.float32) + +# add dense layer on top of the RNN outputs +rnn_outputs_flat = tf.reshape(rnn_outputs, [-1, HIDDEN_SIZE]) +dense_layer = layers.linear(rnn_outputs_flat, VOCAB_SIZE) +labels = tf.reshape(input_y, [-1, VOCAB_SIZE]) +output_softmax = tf.nn.softmax(dense_layer) + +# Loss +loss = tf.reduce_sum( + tf.nn.softmax_cross_entropy_with_logits(logits=dense_layer, + labels=labels)) + +# Minimizer +optimizer = tf.train.AdagradOptimizer(learning_rate=LEARNING_RATE) +minimizer = optimizer.minimize(loss) + +# Gradient clipping +# In this code we're not using gradient clipping, just to make things simpler +# but if you want to use it, the code below implements it. +''' +grads_and_vars = minimizer.compute_gradients(loss) + +grad_clipping = tf.constant(5.0, name='grad_clipping') +clipped_grads_and_vars = [] +for grad, var in grads_and_vars: + clipped_grad = tf.clip_by_value(grad, -grad_clipping, grad_clipping) + clipped_grads_and_vars.append((clipped_grad, var)) + +updates = minimizer.apply_gradients(clipped_grads_and_vars) +''' +# Create session and initialize variables +sess = tf.Session() +init = tf.global_variables_initializer() +sess.run(init) + +# Training + +# n: counts the number of steps, p: pointer to position in sequence +n, p = 0, 0 + +# this var will be used for sampling +hprev_val = np.zeros([1, HIDDEN_SIZE]) + +# loss at iteration 0 +smooth_loss = -np.log(1.0 / VOCAB_SIZE) * SEQ_LENGTH + +while True: + # prepare inputs (we're sweeping from left to right in steps SEQ_LENGTH long) + if p + SEQ_LENGTH + 1 >= len(data) or n == 0: + hprev_val = np.zeros([BATCH_SIZE, HIDDEN_SIZE]) # reset RNN memory + p = 0 # go from start of data + + start_index = p + end_index = p + SEQ_LENGTH + + input_vals = [char_to_ix[ch] for ch in data[start_index: end_index]] + input_vals = np.reshape(input_vals, (-1, SEQ_LENGTH)) + + target_vals = [char_to_ix[ch] for ch in data[start_index + 1: end_index+ 1]] + target_vals = np.reshape(target_vals, (-1, SEQ_LENGTH)) + + # sampling + if n % 1000 == 0: + sample_length = 200 + hprev_sample = np.copy(hprev_val) + + # start from the first letter from the input + first_char = char_to_ix[data[p]] + x = np.asarray([[first_char]]) + # stores predictions + sample_ix = [] + + for t in range(sample_length): + pred, hprev_sample = sess.run([output_softmax, final_state], + feed_dict={inputs: x, + init_state: hprev_sample}) + + # generates next letter + ix = np.random.choice(range(VOCAB_SIZE), p=pred.ravel()) + # update next char with the prediction + x = np.asarray([[ix]]) + sample_ix.append(ix) + + txt = ''.join(ix_to_char[ix] for ix in sample_ix) + print('----\n%s\n----' % (txt)) + + # running the graph + hprev_val, loss_val, _ = sess.run([final_state, loss, minimizer], + feed_dict={inputs: input_vals, + targets: target_vals, + init_state: hprev_val}) + + # print progress + smooth_loss = smooth_loss * 0.999 + loss_val * 0.001 + if n % 100 == 0: print('iter %d, loss: %f' % (n, smooth_loss)) + + p += SEQ_LENGTH + n += 1 From dfaf2844a9a4de5a494aba1c651c33d549400925 Mon Sep 17 00:00:00 2001 From: Marianne Linhares Monteiro Date: Tue, 15 Aug 2017 10:17:28 -0400 Subject: [PATCH 3/8] Adding about_tensorflow.txt --- extras/min-char-rnn/about_tensorflow.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 extras/min-char-rnn/about_tensorflow.txt diff --git a/extras/min-char-rnn/about_tensorflow.txt b/extras/min-char-rnn/about_tensorflow.txt new file mode 100644 index 0000000..e5deb27 --- /dev/null +++ b/extras/min-char-rnn/about_tensorflow.txt @@ -0,0 +1 @@ +tensorflow is an open source software library for numerical computation using data flow graphs nodes in the graph represent mathematical operations while the graph edges represent the multidimensional data arrays (tensors) communicated between them the flexible architecture allows you to deploy computation to one or more cpus or gpus in a desktop server or mobile device with a single api tensorflow was originally developed by researchers and engineers working on the google brain team within googles machine intelligence research organization for the purposes of conducting machine learning and deep neural networks research but the system is general enough to be applicable in a wide variety of other domains as well From ca874e5ad7d47ca1c06b0fc998dc7f58b646cd8f Mon Sep 17 00:00:00 2001 From: Marianne Linhares Monteiro Date: Tue, 15 Aug 2017 10:17:53 -0400 Subject: [PATCH 4/8] Adding README --- extras/min-char-rnn/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 extras/min-char-rnn/README.md diff --git a/extras/min-char-rnn/README.md b/extras/min-char-rnn/README.md new file mode 100644 index 0000000..22aa322 --- /dev/null +++ b/extras/min-char-rnn/README.md @@ -0,0 +1,13 @@ +## Implementations of min_char_rnn + +This repo contain implementations of a very simple char-to-char generator, based on the blog post: +[The Unreasonable Effectiveness of Recurrent Neural Networks by Andrej Karpathy](http://karpathy.github.io/2015/05/21/rnn-effectiveness/). + + +* min_char_rnn.py it's just a commented version with small changes of a [code](https://gist.github.com/karpathy/d4dee566867f8291f086) from Andrej Karpathy (@karpathy), that has done this amazing work for teaching RNNs. Thank you, Andrej :) + +* tensorflow_min_char_rnn.py was based on the great [code](https://gist.github.com/vinhkhuc/7ec5bf797308279dc587) from: Vinh Khuc (@knvinh), that is basically the min_char_rnn.py implemented in low-level TensorFlow. Thank you, Vinh :) + +* RNNCell_min_char_rnn.py was made my @monteirom, and is the min_char_rnn.py implemented using the RNNCell from TensorFLow. + + From 226f3053e59794da379045c943e0ba0f41e85c8e Mon Sep 17 00:00:00 2001 From: Marianne Linhares Monteiro Date: Tue, 15 Aug 2017 10:18:31 -0400 Subject: [PATCH 5/8] Delete README.md --- extras/min-char-rnn/README.md | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 extras/min-char-rnn/README.md diff --git a/extras/min-char-rnn/README.md b/extras/min-char-rnn/README.md deleted file mode 100644 index 22aa322..0000000 --- a/extras/min-char-rnn/README.md +++ /dev/null @@ -1,13 +0,0 @@ -## Implementations of min_char_rnn - -This repo contain implementations of a very simple char-to-char generator, based on the blog post: -[The Unreasonable Effectiveness of Recurrent Neural Networks by Andrej Karpathy](http://karpathy.github.io/2015/05/21/rnn-effectiveness/). - - -* min_char_rnn.py it's just a commented version with small changes of a [code](https://gist.github.com/karpathy/d4dee566867f8291f086) from Andrej Karpathy (@karpathy), that has done this amazing work for teaching RNNs. Thank you, Andrej :) - -* tensorflow_min_char_rnn.py was based on the great [code](https://gist.github.com/vinhkhuc/7ec5bf797308279dc587) from: Vinh Khuc (@knvinh), that is basically the min_char_rnn.py implemented in low-level TensorFlow. Thank you, Vinh :) - -* RNNCell_min_char_rnn.py was made my @monteirom, and is the min_char_rnn.py implemented using the RNNCell from TensorFLow. - - From e81c5a612d74fbc950f1ae3e9ac9f1b610194e4d Mon Sep 17 00:00:00 2001 From: Marianne Linhares Monteiro Date: Tue, 15 Aug 2017 10:18:41 -0400 Subject: [PATCH 6/8] Delete RNNCell_min_char_rnn.py --- extras/RNNCell_min_char_rnn.py | 159 --------------------------------- 1 file changed, 159 deletions(-) delete mode 100644 extras/RNNCell_min_char_rnn.py diff --git a/extras/RNNCell_min_char_rnn.py b/extras/RNNCell_min_char_rnn.py deleted file mode 100644 index 5096c9e..0000000 --- a/extras/RNNCell_min_char_rnn.py +++ /dev/null @@ -1,159 +0,0 @@ -""" -Adapted from Karpathy's min-char-rnn.py -https://gist.github.com/karpathy/d4dee566867f8291f086 -Requires tensorflow>=1.0 -BSD License - -Modified by: Marianne Linhares (@mari-linhares) -""" - -import numpy as np -import tensorflow as tf -from tensorflow.contrib import layers - -print(tf.__version__) - -# data I/O - -# should be simple plain text file -data = open('data/about_tensorflow.txt', 'r').read() -chars = list(set(data)) - -DATA_SIZE, VOCAB_SIZE = len(data), len(chars) -print('data has %d characters, %d unique.' % (DATA_SIZE, VOCAB_SIZE)) - -char_to_ix = {ch: i for i, ch in enumerate(chars)} -ix_to_char = {i: ch for i, ch in enumerate(chars)} - -# hyperparameters -HIDDEN_SIZE = 100 # hidden layer's size -SEQ_LENGTH = 25 # number of steps to unroll -LEARNING_RATE = 0.1 # size of step for Gradient Descent -BATCH_SIZE = 1 # number of sequences evaluated at each train step - -# TensorFlow graph definition - -# Placeholders -inputs = tf.placeholder(shape=[None, None], dtype=tf.int32, name='inputs') -targets = tf.placeholder(shape=[None, None], dtype=tf.int32, name='targets') -init_state = tf.placeholder(shape=[None, HIDDEN_SIZE], dtype=tf.float32, - name='state') - -# RNN - -# [ BATCH_SIZE, SEQ_LEN, VOCAB_SIZE ] -input_x = tf.one_hot(inputs, VOCAB_SIZE) -input_y = tf.one_hot(targets, VOCAB_SIZE) - -# creating a RNN cell -rnn_cell = tf.nn.rnn_cell.BasicRNNCell(HIDDEN_SIZE) -# you can use a GRUCell by changing one line of code -''' -rnn_cell = tf.nn.rnn_cell.GRUCell(HIDDEN_SIZE) -''' - -# run RNN -# rnn_outputs: [ BATCH_SIZE, SEQ_LEN, HIDDEN_SIZE] -# final_state: [ BATCH_SIZE, HIDDEN_SIZE] -rnn_outputs, final_state = tf.nn.dynamic_rnn(rnn_cell, input_x, - initial_state=init_state, - dtype=tf.float32) - -# add dense layer on top of the RNN outputs -rnn_outputs_flat = tf.reshape(rnn_outputs, [-1, HIDDEN_SIZE]) -dense_layer = layers.linear(rnn_outputs_flat, VOCAB_SIZE) -labels = tf.reshape(input_y, [-1, VOCAB_SIZE]) -output_softmax = tf.nn.softmax(dense_layer) - -# Loss -loss = tf.reduce_sum( - tf.nn.softmax_cross_entropy_with_logits(logits=dense_layer, - labels=labels)) - -# Minimizer -optimizer = tf.train.AdagradOptimizer(learning_rate=LEARNING_RATE) -minimizer = optimizer.minimize(loss) - -# Gradient clipping -# In this code we're not using gradient clipping, just to make things simpler -# but if you want to use it, the code below implements it. -''' -grads_and_vars = minimizer.compute_gradients(loss) - -grad_clipping = tf.constant(5.0, name='grad_clipping') -clipped_grads_and_vars = [] -for grad, var in grads_and_vars: - clipped_grad = tf.clip_by_value(grad, -grad_clipping, grad_clipping) - clipped_grads_and_vars.append((clipped_grad, var)) - -updates = minimizer.apply_gradients(clipped_grads_and_vars) -''' -# Create session and initialize variables -sess = tf.Session() -init = tf.global_variables_initializer() -sess.run(init) - -# Training - -# n: counts the number of steps, p: pointer to position in sequence -n, p = 0, 0 - -# this var will be used for sampling -hprev_val = np.zeros([1, HIDDEN_SIZE]) - -# loss at iteration 0 -smooth_loss = -np.log(1.0 / VOCAB_SIZE) * SEQ_LENGTH - -while True: - # prepare inputs (we're sweeping from left to right in steps SEQ_LENGTH long) - if p + SEQ_LENGTH + 1 >= len(data) or n == 0: - hprev_val = np.zeros([BATCH_SIZE, HIDDEN_SIZE]) # reset RNN memory - p = 0 # go from start of data - - start_index = p - end_index = p + SEQ_LENGTH - - input_vals = [char_to_ix[ch] for ch in data[start_index: end_index]] - input_vals = np.reshape(input_vals, (-1, SEQ_LENGTH)) - - target_vals = [char_to_ix[ch] for ch in data[start_index + 1: end_index+ 1]] - target_vals = np.reshape(target_vals, (-1, SEQ_LENGTH)) - - # sampling - if n % 1000 == 0: - sample_length = 200 - hprev_sample = np.copy(hprev_val) - - # start from the first letter from the input - first_char = char_to_ix[data[p]] - x = np.asarray([[first_char]]) - # stores predictions - sample_ix = [] - - for t in range(sample_length): - pred, hprev_sample = sess.run([output_softmax, final_state], - feed_dict={inputs: x, - init_state: hprev_sample}) - - # generates next letter - ix = np.random.choice(range(VOCAB_SIZE), p=pred.ravel()) - # update next char with the prediction - x = np.asarray([[ix]]) - sample_ix.append(ix) - - txt = ''.join(ix_to_char[ix] for ix in sample_ix) - print('----\n%s\n----' % (txt)) - - # running the graph - hprev_val, loss_val, _ = sess.run([final_state, loss, minimizer], - feed_dict={inputs: input_vals, - targets: target_vals, - init_state: hprev_val}) - - # print progress - smooth_loss = smooth_loss * 0.999 + loss_val * 0.001 - if n % 100 == 0: print('iter %d, loss: %f' % (n, smooth_loss)) - - p += SEQ_LENGTH - n += 1 - From 7760f0e742a1376c716bd39973bff783ebf79989 Mon Sep 17 00:00:00 2001 From: Marianne Linhares Monteiro Date: Tue, 15 Aug 2017 10:18:54 -0400 Subject: [PATCH 7/8] Update RNNCell_min_char_rnn.py --- extras/min-char-rnn/RNNCell_min_char_rnn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/min-char-rnn/RNNCell_min_char_rnn.py b/extras/min-char-rnn/RNNCell_min_char_rnn.py index d4029da..1d0a3c8 100644 --- a/extras/min-char-rnn/RNNCell_min_char_rnn.py +++ b/extras/min-char-rnn/RNNCell_min_char_rnn.py @@ -16,7 +16,7 @@ # data I/O # should be simple plain text file -data = open('data/about_tensorflow.txt', 'r').read() +data = open('about_tensorflow.txt', 'r').read() chars = list(set(data)) DATA_SIZE, VOCAB_SIZE = len(data), len(chars) From ffc664b3876a75ef568a1cb9d9ca24a5e09ff55d Mon Sep 17 00:00:00 2001 From: Marianne Linhares Monteiro Date: Tue, 15 Aug 2017 10:19:35 -0400 Subject: [PATCH 8/8] Fixing style and adding correct data referrence --- extras/min-char-rnn/RNNCell_min_char_rnn.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extras/min-char-rnn/RNNCell_min_char_rnn.py b/extras/min-char-rnn/RNNCell_min_char_rnn.py index 1d0a3c8..1a5ae41 100644 --- a/extras/min-char-rnn/RNNCell_min_char_rnn.py +++ b/extras/min-char-rnn/RNNCell_min_char_rnn.py @@ -26,8 +26,8 @@ ix_to_char = {i: ch for i, ch in enumerate(chars)} # hyperparameters -HIDDEN_SIZE = 100 # hidden layer's size -SEQ_LENGTH = 25 # number of steps to unroll +HIDDEN_SIZE = 100 # hidden layer's size +SEQ_LENGTH = 25 # number of steps to unroll LEARNING_RATE = 0.1 # size of step for Gradient Descent BATCH_SIZE = 1 # number of sequences evaluated at each train step @@ -53,8 +53,8 @@ ''' # run RNN -# rnn_outputs: [ BATCH_SIZE, SEQ_LEN, HIDDEN_SIZE] -# final_state: [ BATCH_SIZE, HIDDEN_SIZE] +# rnn_outputs: [BATCH_SIZE, SEQ_LEN, HIDDEN_SIZE] +# final_state: [BATCH_SIZE, HIDDEN_SIZE] rnn_outputs, final_state = tf.nn.dynamic_rnn(rnn_cell, input_x, initial_state=init_state, dtype=tf.float32)