Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2921009

Browse files
authored
Merge pull request #40 from energyfirefox/master
Fixed ValueError in ch10_rnn/Concept02_rnn.ipynb
2 parents 4461953 + 62e33eb commit 2921009

File tree

1 file changed

+33
-52
lines changed

1 file changed

+33
-52
lines changed

‎ch10_rnn/Concept02_rnn.ipynb

Lines changed: 33 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,29 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"metadata": {
6-
"deletable": true,
7-
"editable": true
8-
},
5+
"metadata": {},
96
"source": [
107
"# Ch `10`: Concept `02`"
118
]
129
},
1310
{
1411
"cell_type": "markdown",
15-
"metadata": {
16-
"deletable": true,
17-
"editable": true
18-
},
12+
"metadata": {},
1913
"source": [
2014
"## Recurrent Neural Network"
2115
]
2216
},
2317
{
2418
"cell_type": "markdown",
25-
"metadata": {
26-
"deletable": true,
27-
"editable": true
28-
},
19+
"metadata": {},
2920
"source": [
3021
"Import the relevant libraries:"
3122
]
3223
},
3324
{
3425
"cell_type": "code",
35-
"execution_count": 1,
36-
"metadata": {
37-
"collapsed": false,
38-
"deletable": true,
39-
"editable": true
40-
},
26+
"execution_count": 2,
27+
"metadata": {},
4128
"outputs": [],
4229
"source": [
4330
"import numpy as np\n",
@@ -47,22 +34,15 @@
4734
},
4835
{
4936
"cell_type": "markdown",
50-
"metadata": {
51-
"deletable": true,
52-
"editable": true
53-
},
37+
"metadata": {},
5438
"source": [
5539
"Define the RNN model:"
5640
]
5741
},
5842
{
5943
"cell_type": "code",
60-
"execution_count": 2,
61-
"metadata": {
62-
"collapsed": true,
63-
"deletable": true,
64-
"editable": true
65-
},
44+
"execution_count": 3,
45+
"metadata": {},
6646
"outputs": [],
6747
"source": [
6848
"class SeriesPredictor:\n",
@@ -92,7 +72,7 @@
9272
" :param W: matrix of fully-connected output layer weights\n",
9373
" :param b: vector of fully-connected output layer biases\n",
9474
" \"\"\"\n",
95-
" cell = rnn.BasicLSTMCell(self.hidden_dim)\n",
75+
" cell = rnn.BasicLSTMCell(self.hidden_dim, reuse=tf.get_variable_scope().reuse)\n",
9676
" outputs, states = tf.nn.dynamic_rnn(cell, self.x, dtype=tf.float32)\n",
9777
" num_examples = tf.shape(self.x)[0]\n",
9878
" W_repeated = tf.tile(tf.expand_dims(self.W_out, 0), [num_examples, 1, 1])\n",
@@ -123,48 +103,42 @@
123103
},
124104
{
125105
"cell_type": "markdown",
126-
"metadata": {
127-
"deletable": true,
128-
"editable": true
129-
},
106+
"metadata": {},
130107
"source": [
131108
"Now, we'll train a series predictor. Let's say we have a sequence of numbers `[a, b, c, d]` that we want to transform into `[a, a+b, b+c, c+d]`. We'll give the RNN a couple examples in the training data. Let's see how well it learns this intended transformation:"
132109
]
133110
},
134111
{
135112
"cell_type": "code",
136-
"execution_count": 3,
137-
"metadata": {
138-
"collapsed": false,
139-
"deletable": true,
140-
"editable": true
141-
},
113+
"execution_count": 4,
114+
"metadata": {},
142115
"outputs": [
143116
{
144117
"name": "stdout",
145118
"output_type": "stream",
146119
"text": [
147-
"0 92.1852\n",
148-
"100 61.1175\n",
149-
"200 27.0341\n",
150-
"300 13.9523\n",
151-
"400 9.39037\n",
152-
"500 7.08643\n",
153-
"600 5.50997\n",
154-
"700 4.12571\n",
155-
"800 3.12016\n",
156-
"900 2.42311\n",
120+
"0 103.46295\n",
121+
"100 63.418705\n",
122+
"200 23.072838\n",
123+
"300 11.47684\n",
124+
"400 7.195353\n",
125+
"500 4.4564924\n",
126+
"600 2.8910196\n",
127+
"700 1.948163\n",
128+
"800 1.3193887\n",
129+
"900 0.88628125\n",
157130
"Model saved to model.ckpt\n",
131+
"INFO:tensorflow:Restoring parameters from ./model.ckpt\n",
158132
"\n",
159133
"Lets run some tests!\n",
160134
"\n",
161135
"When the input is [[1], [2], [3], [4]]\n",
162136
"The ground truth output should be [[1], [3], [5], [7]]\n",
163-
"And the model thinks it is [ 0.96018004 2.76944828 5.35826826 7.3706851 ]\n",
137+
"And the model thinks it is [0.86705637 2.7930977 5.307706 7.302184 ]\n",
164138
"\n",
165139
"When the input is [[4], [5], [6], [7]]\n",
166140
"The ground truth output should be [[4], [9], [11], [13]]\n",
167-
"And the model thinks it is [ 4.17302942 9.161376 11.13204765 11.64120388]\n",
141+
"And the model thinks it is [ 4.0726233 9.083956 11.937489 12.943668 ]\n",
168142
"\n"
169143
]
170144
}
@@ -193,6 +167,13 @@
193167
" print(\"The ground truth output should be {}\".format(actual_y[i]))\n",
194168
" print(\"And the model thinks it is {}\\n\".format(pred_y[i]))"
195169
]
170+
},
171+
{
172+
"cell_type": "code",
173+
"execution_count": null,
174+
"metadata": {},
175+
"outputs": [],
176+
"source": []
196177
}
197178
],
198179
"metadata": {
@@ -211,7 +192,7 @@
211192
"name": "python",
212193
"nbconvert_exporter": "python",
213194
"pygments_lexer": "ipython3",
214-
"version": "3.5.2"
195+
"version": "3.6.5"
215196
}
216197
},
217198
"nbformat": 4,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /