Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel
Integration:  git
cd4843ae06
added screen shot of vpython window showing network
2 years ago
4064a98fd5
first push of first class and image file
2 years ago
b5e3ca5530
updating with IMLAI
1 year ago
b5e3ca5530
updating with IMLAI
1 year ago
b5e3ca5530
updating with IMLAI
1 year ago
b5e3ca5530
updating with IMLAI
1 year ago
Storage Buckets

ReadMe.html

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
  1. <!DOCTYPE html><html><head>
  2. <title>ReadMe</title>
  3. <meta charset="utf-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  5. <link rel="stylesheet" href="file:////home/thom/.vscode/extensions/shd101wyy.markdown-preview-enhanced-0.6.5/node_modules/@shd101wyy/mume/dependencies/katex/katex.min.css">
  6. <style>
  7. /**
  8. * prism.js Github theme based on GitHub's theme.
  9. * @author Sam Clarke
  10. */
  11. code[class*="language-"],
  12. pre[class*="language-"] {
  13. color: #333;
  14. background: none;
  15. font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
  16. text-align: left;
  17. white-space: pre;
  18. word-spacing: normal;
  19. word-break: normal;
  20. word-wrap: normal;
  21. line-height: 1.4;
  22. -moz-tab-size: 8;
  23. -o-tab-size: 8;
  24. tab-size: 8;
  25. -webkit-hyphens: none;
  26. -moz-hyphens: none;
  27. -ms-hyphens: none;
  28. hyphens: none;
  29. }
  30. /* Code blocks */
  31. pre[class*="language-"] {
  32. padding: .8em;
  33. overflow: auto;
  34. /* border: 1px solid #ddd; */
  35. border-radius: 3px;
  36. /* background: #fff; */
  37. background: #f5f5f5;
  38. }
  39. /* Inline code */
  40. :not(pre) > code[class*="language-"] {
  41. padding: .1em;
  42. border-radius: .3em;
  43. white-space: normal;
  44. background: #f5f5f5;
  45. }
  46. .token.comment,
  47. .token.blockquote {
  48. color: #969896;
  49. }
  50. .token.cdata {
  51. color: #183691;
  52. }
  53. .token.doctype,
  54. .token.punctuation,
  55. .token.variable,
  56. .token.macro.property {
  57. color: #333;
  58. }
  59. .token.operator,
  60. .token.important,
  61. .token.keyword,
  62. .token.rule,
  63. .token.builtin {
  64. color: #a71d5d;
  65. }
  66. .token.string,
  67. .token.url,
  68. .token.regex,
  69. .token.attr-value {
  70. color: #183691;
  71. }
  72. .token.property,
  73. .token.number,
  74. .token.boolean,
  75. .token.entity,
  76. .token.atrule,
  77. .token.constant,
  78. .token.symbol,
  79. .token.command,
  80. .token.code {
  81. color: #0086b3;
  82. }
  83. .token.tag,
  84. .token.selector,
  85. .token.prolog {
  86. color: #63a35c;
  87. }
  88. .token.function,
  89. .token.namespace,
  90. .token.pseudo-element,
  91. .token.class,
  92. .token.class-name,
  93. .token.pseudo-class,
  94. .token.id,
  95. .token.url-reference .token.variable,
  96. .token.attr-name {
  97. color: #795da3;
  98. }
  99. .token.entity {
  100. cursor: help;
  101. }
  102. .token.title,
  103. .token.title .token.punctuation {
  104. font-weight: bold;
  105. color: #1d3e81;
  106. }
  107. .token.list {
  108. color: #ed6a43;
  109. }
  110. .token.inserted {
  111. background-color: #eaffea;
  112. color: #55a532;
  113. }
  114. .token.deleted {
  115. background-color: #ffecec;
  116. color: #bd2c00;
  117. }
  118. .token.bold {
  119. font-weight: bold;
  120. }
  121. .token.italic {
  122. font-style: italic;
  123. }
  124. /* JSON */
  125. .language-json .token.property {
  126. color: #183691;
  127. }
  128. .language-markup .token.tag .token.punctuation {
  129. color: #333;
  130. }
  131. /* CSS */
  132. code.language-css,
  133. .language-css .token.function {
  134. color: #0086b3;
  135. }
  136. /* YAML */
  137. .language-yaml .token.atrule {
  138. color: #63a35c;
  139. }
  140. code.language-yaml {
  141. color: #183691;
  142. }
  143. /* Ruby */
  144. .language-ruby .token.function {
  145. color: #333;
  146. }
  147. /* Markdown */
  148. .language-markdown .token.url {
  149. color: #795da3;
  150. }
  151. /* Makefile */
  152. .language-makefile .token.symbol {
  153. color: #795da3;
  154. }
  155. .language-makefile .token.variable {
  156. color: #183691;
  157. }
  158. .language-makefile .token.builtin {
  159. color: #0086b3;
  160. }
  161. /* Bash */
  162. .language-bash .token.keyword {
  163. color: #0086b3;
  164. }
  165. /* highlight */
  166. pre[data-line] {
  167. position: relative;
  168. padding: 1em 0 1em 3em;
  169. }
  170. pre[data-line] .line-highlight-wrapper {
  171. position: absolute;
  172. top: 0;
  173. left: 0;
  174. background-color: transparent;
  175. display: block;
  176. width: 100%;
  177. }
  178. pre[data-line] .line-highlight {
  179. position: absolute;
  180. left: 0;
  181. right: 0;
  182. padding: inherit 0;
  183. margin-top: 1em;
  184. background: hsla(24, 20%, 50%,.08);
  185. background: linear-gradient(to right, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
  186. pointer-events: none;
  187. line-height: inherit;
  188. white-space: pre;
  189. }
  190. pre[data-line] .line-highlight:before,
  191. pre[data-line] .line-highlight[data-end]:after {
  192. content: attr(data-start);
  193. position: absolute;
  194. top: .4em;
  195. left: .6em;
  196. min-width: 1em;
  197. padding: 0 .5em;
  198. background-color: hsla(24, 20%, 50%,.4);
  199. color: hsl(24, 20%, 95%);
  200. font: bold 65%/1.5 sans-serif;
  201. text-align: center;
  202. vertical-align: .3em;
  203. border-radius: 999px;
  204. text-shadow: none;
  205. box-shadow: 0 1px white;
  206. }
  207. pre[data-line] .line-highlight[data-end]:after {
  208. content: attr(data-end);
  209. top: auto;
  210. bottom: .4em;
  211. }html body{font-family:"Helvetica Neue",Helvetica,"Segoe UI",Arial,freesans,sans-serif;font-size:16px;line-height:1.6;color:#333;background-color:#fff;overflow:initial;box-sizing:border-box;word-wrap:break-word}html body>:first-child{margin-top:0}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{line-height:1.2;margin-top:1em;margin-bottom:16px;color:#000}html body h1{font-size:2.25em;font-weight:300;padding-bottom:.3em}html body h2{font-size:1.75em;font-weight:400;padding-bottom:.3em}html body h3{font-size:1.5em;font-weight:500}html body h4{font-size:1.25em;font-weight:600}html body h5{font-size:1.1em;font-weight:600}html body h6{font-size:1em;font-weight:600}html body h1,html body h2,html body h3,html body h4,html body h5{font-weight:600}html body h5{font-size:1em}html body h6{color:#5c5c5c}html body strong{color:#000}html body del{color:#5c5c5c}html body a:not([href]){color:inherit;text-decoration:none}html body a{color:#08c;text-decoration:none}html body a:hover{color:#00a3f5;text-decoration:none}html body img{max-width:100%}html body>p{margin-top:0;margin-bottom:16px;word-wrap:break-word}html body>ul,html body>ol{margin-bottom:16px}html body ul,html body ol{padding-left:2em}html body ul.no-list,html body ol.no-list{padding:0;list-style-type:none}html body ul ul,html body ul ol,html body ol ol,html body ol ul{margin-top:0;margin-bottom:0}html body li{margin-bottom:0}html body li.task-list-item{list-style:none}html body li>p{margin-top:0;margin-bottom:0}html body .task-list-item-checkbox{margin:0 .2em .25em -1.8em;vertical-align:middle}html body .task-list-item-checkbox:hover{cursor:pointer}html body blockquote{margin:16px 0;font-size:inherit;padding:0 15px;color:#5c5c5c;background-color:#f0f0f0;border-left:4px solid #d6d6d6}html body blockquote>:first-child{margin-top:0}html body blockquote>:last-child{margin-bottom:0}html body hr{height:4px;margin:32px 0;background-color:#d6d6d6;border:0 none}html body table{margin:10px 0 15px 0;border-collapse:collapse;border-spacing:0;display:block;width:100%;overflow:auto;word-break:normal;word-break:keep-all}html body table th{font-weight:bold;color:#000}html body table td,html body table th{border:1px solid #d6d6d6;padding:6px 13px}html body dl{padding:0}html body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:bold}html body dl dd{padding:0 16px;margin-bottom:16px}html body code{font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:.85em !important;color:#000;background-color:#f0f0f0;border-radius:3px;padding:.2em 0}html body code::before,html body code::after{letter-spacing:-0.2em;content:"\00a0"}html body pre>code{padding:0;margin:0;font-size:.85em !important;word-break:normal;white-space:pre;background:transparent;border:0}html body .highlight{margin-bottom:16px}html body .highlight pre,html body pre{padding:1em;overflow:auto;font-size:.85em !important;line-height:1.45;border:#d6d6d6;border-radius:3px}html body .highlight pre{margin-bottom:0;word-break:normal}html body pre code,html body pre tt{display:inline;max-width:initial;padding:0;margin:0;overflow:initial;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}html body pre code:before,html body pre tt:before,html body pre code:after,html body pre tt:after{content:normal}html body p,html body blockquote,html body ul,html body ol,html body dl,html body pre{margin-top:0;margin-bottom:16px}html body kbd{color:#000;border:1px solid #d6d6d6;border-bottom:2px solid #c7c7c7;padding:2px 4px;background-color:#f0f0f0;border-radius:3px}@media print{html body{background-color:#fff}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{color:#000;page-break-after:avoid}html body blockquote{color:#5c5c5c}html body pre{page-break-inside:avoid}html body table{display:table}html body img{display:block;max-width:100%;max-height:100%}html body pre,html body code{word-wrap:break-word;white-space:pre}}.markdown-preview{width:100%;height:100%;box-sizing:border-box}.markdown-preview .pagebreak,.markdown-preview .newpage{page-break-before:always}.markdown-preview pre.line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}.markdown-preview pre.line-numbers>code{position:relative}.markdown-preview pre.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:1em;font-size:100%;left:0;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.markdown-preview pre.line-numbers .line-numbers-rows>span{pointer-events:none;display:block;counter-increment:linenumber}.markdown-preview pre.line-numbers .line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right}.markdown-preview .mathjax-exps .MathJax_Display{text-align:center !important}.markdown-preview:not([for="preview"]) .code-chunk .btn-group{display:none}.markdown-preview:not([for="preview"]) .code-chunk .status{display:none}.markdown-preview:not([for="preview"]) .code-chunk .output-div{margin-bottom:16px}.scrollbar-style::-webkit-scrollbar{width:8px}.scrollbar-style::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}.scrollbar-style::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(150,150,150,0.66);border:4px solid rgba(150,150,150,0.66);background-clip:content-box}html body[for="html-export"]:not([data-presentation-mode]){position:relative;width:100%;height:100%;top:0;left:0;margin:0;padding:0;overflow:auto}html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{position:relative;top:0}@media screen and (min-width:914px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{padding:2em calc(50% - 457px + 2em)}}@media screen and (max-width:914px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{font-size:14px !important;padding:1em}}@media print{html body[for="html-export"]:not([data-presentation-mode]) #sidebar-toc-btn{display:none}}html body[for="html-export"]:not([data-presentation-mode]) #sidebar-toc-btn{position:fixed;bottom:8px;left:8px;font-size:28px;cursor:pointer;color:inherit;z-index:99;width:32px;text-align:center;opacity:.4}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] #sidebar-toc-btn{opacity:1}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc{position:fixed;top:0;left:0;width:300px;height:100%;padding:32px 0 48px 0;font-size:14px;box-shadow:0 0 4px rgba(150,150,150,0.33);box-sizing:border-box;overflow:auto;background-color:inherit}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar{width:8px}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(150,150,150,0.66);border:4px solid rgba(150,150,150,0.66);background-clip:content-box}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc a{text-decoration:none}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc ul{padding:0 1.6em;margin-top:.8em}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc li{margin-bottom:.8em}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc ul{list-style-type:none}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{left:300px;width:calc(100% - 300px);padding:2em calc(50% - 457px - 150px);margin:0;box-sizing:border-box}@media screen and (max-width:1274px){html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{width:100%}}html body[for="html-export"]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .markdown-preview{left:50%;transform:translateX(-50%)}html body[for="html-export"]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .md-sidebar-toc{display:none}
  212. /* Please visit the URL below for more information: */
  213. /* https://shd101wyy.github.io/markdown-preview-enhanced/#/customize-css */
  214. </style>
  215. </head>
  216. <body for="html-export">
  217. <div class="mume markdown-preview ">
  218. <h1 class="mume-header" id="a-neural-network-visualizer-class-created-using-visual-python">A Neural Network Visualizer Class created using Visual Python</h1>
  219. <blockquote>
  220. <p>by Thom Ives, Ph.D.</p>
  221. </blockquote>
  222. <p><img src="https://dagshub.com/ThomIves/PyTorch_Journey/raw/aefdfaa0c20cdff3c13e8238f1cb93bec72eb461/IMLAI_1700x500_Inv.png" alt="Integrated Machine Learning &amp; AI Logo"></p>
  223. <p>This class is meant to help us practice <strong>ABV</strong> in our DS, ML, AI work - <em>Always Be Visualizing</em>.</p>
  224. <p><img src="Initial_Neural_Network.png" alt="First Neural Net Test"></p>
  225. <p>Why not Manim? I had a suspicion that it would be easier, at least for me, to do this in Visual Python, which I have been using for over 20 years now. That said, which is best? I don&apos;t know yet. I feel they are both good and powerful, and I do want to do the same in Manim. I suspect that it might work out quite easily in Manim too, but I am not sure yet if it would be as flexible as this tool turned out to be. And this is only the beginning for this class. <strong>NOTE</strong> that there is only an <code>__init__</code> function at this point. We will be able to add dynamic coloring and images representing neuron activations and more in the future. However, this is a great start.</p>
  226. <h1 class="mume-header" id="the-code">The Code</h1>
  227. <pre data-role="codeBlock" data-info="python" class="language-python"><span class="token keyword keyword-import">import</span> vpython <span class="token keyword keyword-as">as</span> vp
  228. <span class="token keyword keyword-import">import</span> numpy <span class="token keyword keyword-as">as</span> np
  229. </pre><p>We want to establish colors in one place, so that we do not need to update multiple places when we want to change them.</p>
  230. <pre data-role="codeBlock" data-info="python" class="language-python">neuron_color <span class="token operator">=</span> vp<span class="token punctuation">.</span>vector<span class="token punctuation">(</span><span class="token number">0.00</span><span class="token punctuation">,</span> <span class="token number">0.49</span><span class="token punctuation">,</span> <span class="token number">0.73</span><span class="token punctuation">)</span>
  231. weight_color <span class="token operator">=</span> vp<span class="token punctuation">.</span>vector<span class="token punctuation">(</span><span class="token number">0.80</span><span class="token punctuation">,</span> <span class="token number">0.80</span><span class="token punctuation">,</span> <span class="token number">0.80</span><span class="token punctuation">)</span>
  232. text_color <span class="token operator">=</span> vp<span class="token punctuation">.</span>vector<span class="token punctuation">(</span><span class="token number">1.0</span><span class="token punctuation">,</span> <span class="token number">1.0</span><span class="token punctuation">,</span> <span class="token number">1.0</span><span class="token punctuation">)</span>
  233. </pre><p>We pass in an architecture, which is simply an array with the number of neurons in each layer as the elements. Thus, the length of the architecture array is the number of layers including input and output layers. We also pass in a title. We also initialize storage arrays for Visual Python objects that form the network. Finally, we establish some helpful values for spacing out the network objects.</p>
  234. <pre data-role="codeBlock" data-info="python" class="language-python"><span class="token keyword keyword-class">class</span> <span class="token class-name">Network</span><span class="token punctuation">:</span>
  235. <span class="token keyword keyword-def">def</span> <span class="token function">__init__</span><span class="token punctuation">(</span>self<span class="token punctuation">,</span> architecture<span class="token punctuation">,</span> title<span class="token punctuation">)</span><span class="token punctuation">:</span>
  236. neuron_storage <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
  237. weight_storage <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
  238. net_amp <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span>architecture<span class="token punctuation">)</span> <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span>
  239. max_amp <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token builtin">max</span><span class="token punctuation">(</span>architecture<span class="token punctuation">)</span> <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span>
  240. </pre><p>We also establish some helpful values for spacing out the textS objects.</p>
  241. <pre data-role="codeBlock" data-info="python" class="language-python"> x_text <span class="token operator">=</span> net_amp
  242. y_text <span class="token operator">=</span> max_amp <span class="token operator">+</span> <span class="token number">0.5</span>
  243. </pre><p>Create the title text.</p>
  244. <pre data-role="codeBlock" data-info="python" class="language-python"> vp<span class="token punctuation">.</span>text<span class="token punctuation">(</span>text<span class="token operator">=</span>title<span class="token punctuation">,</span> pos<span class="token operator">=</span>vp<span class="token punctuation">.</span>vector<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> y_text<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  245. align<span class="token operator">=</span><span class="token string">&quot;center&quot;</span><span class="token punctuation">,</span> color<span class="token operator">=</span>text_color<span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">0.2</span><span class="token punctuation">)</span>
  246. </pre><p>Create helpful text below the network.</p>
  247. <pre data-role="codeBlock" data-info="python" class="language-python"> <span class="token comment"># Descriptive Text Below the Network</span>
  248. vp<span class="token punctuation">.</span>text<span class="token punctuation">(</span>text<span class="token operator">=</span><span class="token string">&quot;inputs&quot;</span><span class="token punctuation">,</span> pos<span class="token operator">=</span>vp<span class="token punctuation">.</span>vector<span class="token punctuation">(</span><span class="token operator">-</span>x_text<span class="token punctuation">,</span> <span class="token operator">-</span>y_text<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  249. align<span class="token operator">=</span><span class="token string">&quot;right&quot;</span><span class="token punctuation">,</span> color<span class="token operator">=</span>text_color<span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">0.2</span><span class="token punctuation">)</span>
  250. vp<span class="token punctuation">.</span>text<span class="token punctuation">(</span>text<span class="token operator">=</span><span class="token string">&quot;|&quot;</span><span class="token punctuation">,</span> pos<span class="token operator">=</span>vp<span class="token punctuation">.</span>vector<span class="token punctuation">(</span><span class="token operator">-</span>x_text <span class="token operator">+</span> <span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token operator">-</span>y_text<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  251. align<span class="token operator">=</span><span class="token string">&quot;center&quot;</span><span class="token punctuation">,</span> color<span class="token operator">=</span>text_color<span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">0.2</span><span class="token punctuation">)</span>
  252. vp<span class="token punctuation">.</span>text<span class="token punctuation">(</span>text<span class="token operator">=</span><span class="token string">&quot;hidden layers&quot;</span><span class="token punctuation">,</span> pos<span class="token operator">=</span>vp<span class="token punctuation">.</span>vector<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token operator">-</span>y_text<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  253. align<span class="token operator">=</span><span class="token string">&quot;center&quot;</span><span class="token punctuation">,</span> color<span class="token operator">=</span>text_color<span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">0.2</span><span class="token punctuation">)</span>
  254. vp<span class="token punctuation">.</span>text<span class="token punctuation">(</span>text<span class="token operator">=</span><span class="token string">&quot;|&quot;</span><span class="token punctuation">,</span> pos<span class="token operator">=</span>vp<span class="token punctuation">.</span>vector<span class="token punctuation">(</span>x_text <span class="token operator">-</span> <span class="token number">0.5</span><span class="token punctuation">,</span> <span class="token operator">-</span>y_text<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  255. align<span class="token operator">=</span><span class="token string">&quot;center&quot;</span><span class="token punctuation">,</span> color<span class="token operator">=</span>text_color<span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">0.2</span><span class="token punctuation">)</span>
  256. vp<span class="token punctuation">.</span>text<span class="token punctuation">(</span>text<span class="token operator">=</span><span class="token string">&quot;outputs&quot;</span><span class="token punctuation">,</span> pos<span class="token operator">=</span>vp<span class="token punctuation">.</span>vector<span class="token punctuation">(</span>x_text<span class="token punctuation">,</span> <span class="token operator">-</span>y_text<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  257. align<span class="token operator">=</span><span class="token string">&quot;left&quot;</span><span class="token punctuation">,</span> color<span class="token operator">=</span>text_color<span class="token punctuation">,</span> height<span class="token operator">=</span><span class="token number">0.2</span><span class="token punctuation">)</span>
  258. </pre><p>Fill out the space needed for neuron storage.</p>
  259. <pre data-role="codeBlock" data-info="python" class="language-python"> <span class="token comment"># Initialize the Neuron Storage</span>
  260. <span class="token keyword keyword-for">for</span> n <span class="token keyword keyword-in">in</span> architecture<span class="token punctuation">:</span>
  261. layer <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">0</span> <span class="token keyword keyword-for">for</span> i <span class="token keyword keyword-in">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token punctuation">]</span>
  262. neuron_storage<span class="token punctuation">.</span>append<span class="token punctuation">(</span>layer<span class="token punctuation">)</span>
  263. </pre><p>Now, create neurons in the correct locations for each layer.</p>
  264. <pre data-role="codeBlock" data-info="python" class="language-python"> <span class="token comment"># Create and Store the Neuron Spheres</span>
  265. <span class="token keyword keyword-for">for</span> layer_num<span class="token punctuation">,</span> num_neurons <span class="token keyword keyword-in">in</span> <span class="token builtin">enumerate</span><span class="token punctuation">(</span>architecture<span class="token punctuation">)</span><span class="token punctuation">:</span>
  266. layer_amp <span class="token operator">=</span> <span class="token punctuation">(</span>num_neurons <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span>
  267. </pre><pre data-role="codeBlock" data-info="python" class="language-python"> <span class="token keyword keyword-for">for</span> neuron_num <span class="token keyword keyword-in">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span>num_neurons<span class="token punctuation">)</span><span class="token punctuation">:</span>
  268. neuron_pos <span class="token operator">=</span> vp<span class="token punctuation">.</span>vector<span class="token punctuation">(</span>
  269. layer_num <span class="token operator">-</span> net_amp<span class="token punctuation">,</span> neuron_num <span class="token operator">-</span> layer_amp<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
  270. neuron_storage<span class="token punctuation">[</span>layer_num<span class="token punctuation">]</span><span class="token punctuation">[</span>neuron_num<span class="token punctuation">]</span> <span class="token operator">=</span> vp<span class="token punctuation">.</span>sphere<span class="token punctuation">(</span>
  271. pos<span class="token operator">=</span>neuron_pos<span class="token punctuation">,</span> radius<span class="token operator">=</span><span class="token number">0.1</span><span class="token punctuation">,</span> color<span class="token operator">=</span>neuron_color<span class="token punctuation">)</span>
  272. </pre><p>Now create the weight bond objects. These are actually just very long thin cylinders.</p>
  273. <pre data-role="codeBlock" data-info="python" class="language-python"> <span class="token comment"># Create and Store the Weight Bonds</span>
  274. <span class="token keyword keyword-for">for</span> layer_num<span class="token punctuation">,</span> current_n <span class="token keyword keyword-in">in</span> <span class="token builtin">enumerate</span><span class="token punctuation">(</span>architecture<span class="token punctuation">[</span><span class="token punctuation">:</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
  275. next_n <span class="token operator">=</span> architecture<span class="token punctuation">[</span>layer_num<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">]</span>
  276. </pre><pre data-role="codeBlock" data-info="python" class="language-python"> weight_storage<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
  277. </pre><pre data-role="codeBlock" data-info="python" class="language-python"> <span class="token keyword keyword-for">for</span> i <span class="token keyword keyword-in">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span>current_n<span class="token punctuation">)</span><span class="token punctuation">:</span>
  278. weight_storage<span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
  279. </pre><pre data-role="codeBlock" data-info="python" class="language-python"> x_start <span class="token operator">=</span> layer_num <span class="token operator">-</span> net_amp
  280. x_end <span class="token operator">=</span> x_start <span class="token operator">+</span> <span class="token number">1</span>
  281. </pre><pre data-role="codeBlock" data-info="python" class="language-python"> <span class="token keyword keyword-for">for</span> j <span class="token keyword keyword-in">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span>next_n<span class="token punctuation">)</span><span class="token punctuation">:</span>
  282. y_start <span class="token operator">=</span> i <span class="token operator">-</span> <span class="token punctuation">(</span>current_n <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span>
  283. y_end <span class="token operator">=</span> j <span class="token operator">-</span> <span class="token punctuation">(</span>next_n <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span>
  284. </pre><pre data-role="codeBlock" data-info="python" class="language-python"> start <span class="token operator">=</span> vp<span class="token punctuation">.</span>vector<span class="token punctuation">(</span>x_start<span class="token punctuation">,</span> y_start<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
  285. end <span class="token operator">=</span> vp<span class="token punctuation">.</span>vector<span class="token punctuation">(</span>x_end<span class="token punctuation">,</span> y_end<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span>
  286. </pre><pre data-role="codeBlock" data-info="python" class="language-python"> weight_storage<span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">.</span>append<span class="token punctuation">(</span>vp<span class="token punctuation">.</span>cylinder<span class="token punctuation">(</span>
  287. pos<span class="token operator">=</span>start<span class="token punctuation">,</span> axis<span class="token operator">=</span>end<span class="token operator">-</span>start<span class="token punctuation">,</span> radius<span class="token operator">=</span><span class="token number">0.01</span><span class="token punctuation">,</span>
  288. color<span class="token operator">=</span>weight_color<span class="token punctuation">)</span><span class="token punctuation">)</span>
  289. </pre><p>Finally, we make our storage objects of visual neuron and weight objects into class attributes for later usage.</p>
  290. <pre data-role="codeBlock" data-info="python" class="language-python"> <span class="token comment"># Make Neuron and Weight Bond Storage Class Attributes</span>
  291. self<span class="token punctuation">.</span>neuron_storage <span class="token operator">=</span> neuron_storage
  292. self<span class="token punctuation">.</span>weight_storage <span class="token operator">=</span> weight_storage
  293. </pre><h2 class="mume-header" id="instantiation">Instantiation</h2>
  294. <p>The instantiation of this object builds a static 3D neural network object. Why does 3D matter? It doesn&apos;t ... yet. I intend to extend this work to transformers and beyond. I believe 3D will end up being very helpful for that work.</p>
  295. <pre data-role="codeBlock" data-info="python" class="language-python">arch <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]</span>
  296. network <span class="token operator">=</span> Network<span class="token punctuation">(</span>arch<span class="token punctuation">,</span> <span class="token string">&quot;Neural Network&quot;</span><span class="token punctuation">)</span>
  297. </pre><p><strong>NOTE</strong> that we could import this Network class from this module into a separate file, and then instantiate it in the separate file. I just did it here for convenience.</p>
  298. <h1 class="mume-header" id="summary">Summary</h1>
  299. <p>This work will be ongoing. It started with my <a href="https://dagshub.com/ThomIves/PyTorch_Journey">PyTorch Journey</a>, but I am sure it will be reused on many other projects.</p>
  300. </div>
  301. </body></html>
Tip!

Press p or to see the previous file or, n or to see the next file

About

A neural network visualizer that use Visual Python (VPython)

Collaborators 1

Comments

Loading...