Skip to content

Commit 34e0aa9

Browse files
author
ugik
committed
ANN examples
1 parent 6ba7e84 commit 34e0aa9

File tree

7 files changed

+391
-71
lines changed

7 files changed

+391
-71
lines changed

Simple_Neural_Network.ipynb

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 9,
5+
"execution_count": 8,
66
"metadata": {
77
"collapsed": false
88
},
@@ -14,23 +14,35 @@
1414
"Random starting synaptic weights: \n",
1515
"[[-0.16595599]\n",
1616
" [ 0.44064899]\n",
17-
" [-0.99977125]]\n",
18-
"error after 0 iterations: 0.578374046722\n",
19-
"error after 1000 iterations: 0.0353771814512\n",
20-
"error after 2000 iterations: 0.024323319584\n",
21-
"error after 3000 iterations: 0.0196075022358\n",
22-
"error after 4000 iterations: 0.016850233908\n",
23-
"error after 5000 iterations: 0.014991814044\n",
24-
"error after 6000 iterations: 0.0136320935305\n",
25-
"error after 7000 iterations: 0.01258242301\n",
26-
"error after 8000 iterations: 0.0117408289409\n",
27-
"error after 9000 iterations: 0.0110467781322\n",
17+
" [-0.99977125]\n",
18+
" [-0.39533485]]\n",
19+
"error after 0 iterations: 0.449903018833\n",
20+
"error after 1000 iterations: 0.013750440233\n",
21+
"error after 2000 iterations: 0.00965974377145\n",
22+
"error after 3000 iterations: 0.00786218913086\n",
23+
"error after 4000 iterations: 0.00679524113652\n",
24+
"error after 5000 iterations: 0.00606919069443\n",
25+
"error after 6000 iterations: 0.00553435906148\n",
26+
"error after 7000 iterations: 0.00511936227674\n",
27+
"error after 8000 iterations: 0.00478528276951\n",
28+
"error after 9000 iterations: 0.00450886340585\n",
29+
"error after 10000 iterations: 0.00427523967482\n",
30+
"error after 11000 iterations: 0.00407440954071\n",
31+
"error after 12000 iterations: 0.00389936317766\n",
32+
"error after 13000 iterations: 0.00374502274318\n",
33+
"error after 14000 iterations: 0.00360760779755\n",
34+
"error after 15000 iterations: 0.00348423814505\n",
35+
"error after 16000 iterations: 0.00337267580097\n",
36+
"error after 17000 iterations: 0.00327115193553\n",
37+
"error after 18000 iterations: 0.00317824759008\n",
38+
"error after 19000 iterations: 0.00309280947588\n",
2839
"New synaptic weights after training: \n",
29-
"[[ 12.79547496]\n",
30-
" [ -4.2162058 ]\n",
31-
" [ -4.21608782]]\n",
32-
"Considering new situation [1, 0, 0] -> ?: \n",
33-
"[ 0.99999723]\n"
40+
"[[ 3.16744718]\n",
41+
" [-0.24954816]\n",
42+
" [-5.53795575]\n",
43+
" [ 2.93806832]]\n",
44+
"Considering new situation [1, 0, 1, 1] -> ?: \n",
45+
"[ 0.63819991]\n"
3446
]
3547
}
3648
],
@@ -47,7 +59,7 @@
4759
" # We model a single neuron, with 3 input connections and 1 output connection.\n",
4860
" # We assign random weights to a 3 x 1 matrix, with values in the range -1 to 1\n",
4961
" # and mean 0.\n",
50-
" self.synaptic_weights = 2 * np.random.random((3, 1)) - 1\n",
62+
" self.synaptic_weights = 2 * np.random.random((4, 1)) - 1\n",
5163
"\n",
5264
" # The Sigmoid function, which describes an S shaped curve.\n",
5365
" # We pass the weighted sum of the inputs through this function to\n",
@@ -98,25 +110,25 @@
98110
"\n",
99111
" # The training set. We have 4 examples, each consisting of 3 input values\n",
100112
" # and 1 output value.\n",
101-
" training_set_inputs = np.array([[0, 0, 1], [1, 1, 1], [1, 0, 1], [0, 1, 0]])\n",
113+
" training_set_inputs = np.array([[0, 0, 1, 0], [1, 1, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0]])\n",
102114
" training_set_outputs = np.array([[0, 1, 1, 0]]).T\n",
103115
"\n",
104116
" # Train the neural network using a training set.\n",
105117
" # Do it 10,000 times and make small adjustments each time.\n",
106-
" neural_network.train(training_set_inputs, training_set_outputs, 10000)\n",
118+
" neural_network.train(training_set_inputs, training_set_outputs, 20000)\n",
107119
"\n",
108120
" print (\"New synaptic weights after training: \")\n",
109121
" print (neural_network.synaptic_weights)\n",
110122
"\n",
111123
" # Test the neural network with a new pattern\n",
112-
" test = [1, 0, 0]\n",
124+
" test = [1, 0, 1, 1]\n",
113125
" print (\"Considering new situation %s -> ?: \" % test )\n",
114126
" print (neural_network.think(np.array(test)))\n"
115127
]
116128
},
117129
{
118130
"cell_type": "code",
119-
"execution_count": 14,
131+
"execution_count": 6,
120132
"metadata": {
121133
"collapsed": false
122134
},
@@ -185,21 +197,21 @@
185197
],
186198
"metadata": {
187199
"kernelspec": {
188-
"display_name": "Python 3",
200+
"display_name": "Python 2",
189201
"language": "python",
190-
"name": "python3"
202+
"name": "python2"
191203
},
192204
"language_info": {
193205
"codemirror_mode": {
194206
"name": "ipython",
195-
"version": 3
207+
"version": 2
196208
},
197209
"file_extension": ".py",
198210
"mimetype": "text/x-python",
199211
"name": "python",
200212
"nbconvert_exporter": "python",
201-
"pygments_lexer": "ipython3",
202-
"version": "3.5.2"
213+
"pygments_lexer": "ipython2",
214+
"version": "2.7.12"
203215
}
204216
},
205217
"nbformat": 4,

Tensorflow chat-bot model.ipynb

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": 2,
66
"metadata": {
77
"collapsed": false
88
},
9-
"outputs": [
10-
{
11-
"name": "stdout",
12-
"output_type": "stream",
13-
"text": [
14-
"hdf5 is not supported on this machine (please install/reinstall h5py for optimal experience)\n"
15-
]
16-
}
17-
],
9+
"outputs": [],
1810
"source": [
1911
"# things we need for NLP\n",
2012
"import nltk\n",
@@ -30,7 +22,7 @@
3022
},
3123
{
3224
"cell_type": "code",
33-
"execution_count": 2,
25+
"execution_count": 3,
3426
"metadata": {
3527
"collapsed": false
3628
},
@@ -44,7 +36,7 @@
4436
},
4537
{
4638
"cell_type": "code",
47-
"execution_count": 3,
39+
"execution_count": 4,
4840
"metadata": {
4941
"collapsed": false
5042
},
@@ -91,7 +83,7 @@
9183
},
9284
{
9385
"cell_type": "code",
94-
"execution_count": 4,
86+
"execution_count": 5,
9587
"metadata": {
9688
"collapsed": false
9789
},
@@ -132,7 +124,7 @@
132124
},
133125
{
134126
"cell_type": "code",
135-
"execution_count": 5,
127+
"execution_count": 6,
136128
"metadata": {
137129
"collapsed": false,
138130
"scrolled": true
@@ -142,10 +134,10 @@
142134
"name": "stdout",
143135
"output_type": "stream",
144136
"text": [
145-
"Training Step: 3999 | total loss: \u001b[1m\u001b[32m0.79875\u001b[0m\u001b[0m | time: 0.009s\n",
146-
"| Adam | epoch: 1000 | loss: 0.79875 - acc: 0.9100 -- iter: 24/27\n",
147-
"Training Step: 4000 | total loss: \u001b[1m\u001b[32m0.72213\u001b[0m\u001b[0m | time: 0.012s\n",
148-
"| Adam | epoch: 1000 | loss: 0.72213 - acc: 0.9190 -- iter: 27/27\n",
137+
"Training Step: 3999 | total loss: \u001b[1m\u001b[32m1.00123\u001b[0m\u001b[0m | time: 0.009s\n",
138+
"| Adam | epoch: 1000 | loss: 1.00123 - acc: 0.9098 -- iter: 24/27\n",
139+
"Training Step: 4000 | total loss: \u001b[1m\u001b[32m0.91795\u001b[0m\u001b[0m | time: 0.013s\n",
140+
"| Adam | epoch: 1000 | loss: 0.91795 - acc: 0.9188 -- iter: 27/27\n",
149141
"--\n",
150142
"INFO:tensorflow:/home/gk/gensim/notebooks/model.tflearn is not in all_model_checkpoint_paths. Manually adding it.\n"
151143
]
@@ -170,7 +162,7 @@
170162
},
171163
{
172164
"cell_type": "code",
173-
"execution_count": 6,
165+
"execution_count": 7,
174166
"metadata": {
175167
"collapsed": true
176168
},
@@ -201,7 +193,7 @@
201193
},
202194
{
203195
"cell_type": "code",
204-
"execution_count": 7,
196+
"execution_count": 8,
205197
"metadata": {
206198
"collapsed": false
207199
},
@@ -224,7 +216,7 @@
224216
},
225217
{
226218
"cell_type": "code",
227-
"execution_count": 8,
219+
"execution_count": 9,
228220
"metadata": {
229221
"collapsed": false
230222
},
@@ -233,7 +225,7 @@
233225
"name": "stdout",
234226
"output_type": "stream",
235227
"text": [
236-
"[[0.0006383281433954835, 1.1489937890019064e-08, 0.005845240317285061, 2.1674446543329395e-05, 0.9596946239471436, 1.4315231666728323e-08, 0.0018385507864877582, 1.7271321439693565e-06, 0.031959764659404755]]\n"
228+
"[[0.01907932758331299, 1.0800805583244255e-08, 0.0016339969588443637, 1.445684461032215e-09, 0.6044806838035583, 1.0841611128853401e-06, 2.067307436348642e-09, 6.506108093162766e-06, 0.37479835748672485]]\n"
237229
]
238230
}
239231
],
@@ -243,7 +235,7 @@
243235
},
244236
{
245237
"cell_type": "code",
246-
"execution_count": 9,
238+
"execution_count": 10,
247239
"metadata": {
248240
"collapsed": false
249241
},

Tensorflow chat-bot response.ipynb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,25 @@
264264
"response('what kind of mopeds do you rent?')"
265265
]
266266
},
267+
{
268+
"cell_type": "code",
269+
"execution_count": 26,
270+
"metadata": {
271+
"collapsed": false
272+
},
273+
"outputs": [
274+
{
275+
"name": "stdout",
276+
"output_type": "stream",
277+
"text": [
278+
"Bye! Come back again soon.\n"
279+
]
280+
}
281+
],
282+
"source": [
283+
"response('Goodbye, see you later')"
284+
]
285+
},
267286
{
268287
"cell_type": "code",
269288
"execution_count": 12,

0 commit comments

Comments
 (0)