Created
December 12, 2017 04:42
-
-
Save kieranbrowne/70d39b2d46a2444cb64e21f38b81c578 to your computer and use it in GitHub Desktop.
Redraw of Interpretable, long-range LSTM cells visualisation published in Karpathy, Andrej, Justin Johnson, and Li Fei-Fei. "Visualizing and understanding recurrent networks." arXiv preprint arXiv:1506.02078 (2015).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
MIT License | |
Copyright (c) 2017 Kieran Browne | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | |
Excerpts from Tolstoy's War and Peace were taken from The Project Gutenberg. https://www.gutenberg.org/files/2600/2600-0.txt | |
--> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<style> | |
body { | |
font-family: monospace; | |
letter-spacing: 2px; | |
} | |
h2 { | |
font-family: sans-serif; | |
font-size: 12px; | |
margin:12px 0 6px; | |
} | |
.container { | |
max-width: 60em; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<div id="target"></div> | |
</div> | |
<script> | |
var tolstoy1 = "The sole importance of the crossing of the Berëzina lies in the fact\n that it plainly and indubitably proved the fallacy of all the plans for \ncutting off the enemy’s retreat and the soundness of the only possible \n line of action--the one Kutúzov and the general mass of the army \n demanded--namely, simply to follow the enemy up. The French crowd fled\n at a continually increasing speed and all its energywas directed to \nreaching its goal. It fled like a wounded animal and it was impossible \nto block its path. This was shown not so much by the arrangements it\n made for crossing as by what took place at the bridges. When the bridges\n broke down, unarmed soldiers, people from Moscow and women with children\n who were with the French transport,all—carried on by vis inertiea --\npressed forward into boats and into the ice-covered water and did not,\n surrender." | |
var tolstoy2 = "\"You mean to imply that I have nothing to eat out of.... On the \ncontrary, I can supply you with everything even if you want to \ngive dinner parties,\" warmly replied Chichagóv, who tried by every\n word he spoke to prove his own rectitude and therefore imagined \nKutúzov to be animated by the same desire.\n\nKutúzov, shrugging his shoulders, replied with his subtle \npenetrating smile: \"I meant merely to say what I said.\"" | |
var target = document.getElementById('target'); | |
function highlight(str,val) { | |
if(str == "\n") return "<br>" | |
return "<span style='background:"+ | |
"hsl(" + (val>0?200:0) + "," + | |
Math.max(50,100-Math.abs(val)*50) + "%," + | |
Math.max(50,100-Math.abs(val)*50) + "%)" | |
+"'>"+str+"</span>" | |
} | |
target.innerHTML += "<h2>Cell sensitive to position in line:</h2>"; | |
var v = 0.7; | |
tolstoy1.split('') | |
.map(x => { | |
v -=Math.random()*0.035 | |
if(x =="\n") v = 0.7; | |
return highlight(x,v+Math.random()*0.1) | |
}) | |
.map(x => target.innerHTML += x); | |
target.innerHTML += "<h2>Cell that turns on inside quotes:</h2>"; | |
var v = -.7; | |
tolstoy2.split('') | |
.map(x => { | |
if(x =="\"" && v > 0) v -= .8; | |
else if(x =="\"" && v < 0) v += .8; | |
else if (v < 0 && v > -.7) v -= .3; | |
else if (v > 0 && v < .7) v += .3; | |
return highlight(x,v + Math.random()*0.07); | |
}) | |
.map(x => target.innerHTML += x); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment