{"by":"nopro","descendants":102,"id":39995908,"kids":[39998678,39999143,40000531,39998886,39998935,39998812,40000438,40000128,39998933,39999922,39998905,39998665,40004052,40004902,39998976,39996261],"score":88,"text":"What inspired this project today was watching this amazing video by 3Blue1Brown called &quot;But what is a GPT?&quot; on Youtube (<a href=\"https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=wjZofJX0v4M\" rel=\"nofollow\">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=wjZofJX0v4M</a> - I highly recommend watching it). I added it to the repo for reference.<p>When it clicked in my head that &quot;knowing a fact&quot; is nearly synonymous with predicting a word (or series of words), I wanted to put it to the test, because it seemed so simple. I chose JavaScript because I can exploit the way it structures objects to aid in the modeling of language.<p>For example:<p>&quot;I want to be at the beach&quot;, \n&quot;I will do it later&quot;, \n&quot;I want to know the answer&quot;, \n...<p>becomes:<p><pre><code>  {\n    I: { \n      want: { \n        to: { \n          be: { ... }, \n          know: { ... }\n        }\n      },\n      will: { ... }\n    },\n    ...\n  }\n</code></pre>\nin JavaScript. You can exploit the language&#x27;s fast object lookup speed to find known sentences this way, rather than recursively searching text - which is the convention and would take forever or not work at all considering there are several full books loaded in by default (and it could support many more).<p>Accompanying research yielded learnings about what &quot;tokens&quot; and &quot;embeddings&quot; are, what is meant by &quot;training&quot;, and most of the rest - though I&#x27;m still learning jargon. I wrote a script to iterate over every single word of every single book to rank how likely it is that word will appear next, if given a cursor, and extended that to rank entire phrases. The base decoder started out what I&#x27;ll call &quot;token-agnostic&quot; - didn&#x27;t care if you were looking for the next letter... word... pixel... it&#x27;s the same logic. But actually it&#x27;s not, and it soon evolved into a text (language) model. But I have plans to get into image generation next (next-pixel prediction), using this. Overall the concepts are similar, but there are differences primarily around extraction and formatting.<p>Goals of the project:<p>- Demystify LLMs for people, show that it&#x27;s just regular code that does normal stuff<p>- Actually make a pretty good LLM in JavaScript, with a version at least capable of running in a browser tab","time":1712784427,"title":"Show HN: Next-token prediction in JavaScript","type":"story","url":"https://github.com/bennyschmidt/next-token-prediction"}