HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
bennyschmidt
next-token-prediction
JavaScript2024–2024
bennyschmidt / next-token-prediction

next-token-prediction

Next-token prediction in JavaScript - build fast language and diffusion models.

4Distinct people
11Mentions
0Explicit recommenders
145GitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Next-token prediction in JavaScript - build fast language and diffusion models.

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 3:56:07 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by week11 dated mentions

Observed mentions: 2024-04-10 21:27:07 UTC to 2024-09-03 04:41:06 UTC. Weeks start Monday, UTC.

0122024-04-08 00:00:00 UTC to 2024-04-15 00:00:00 UTC (exclusive): 2 mentions; 1 submissions, 1 commentsApr 82024-04-15 00:00:00 UTC to 2024-04-22 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2024-04-22 00:00:00 UTC to 2024-04-29 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2024-04-29 00:00:00 UTC to 2024-05-06 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2024-05-06 00:00:00 UTC to 2024-05-13 00:00:00 UTC (exclusive): 1 mentions; 1 submissions, 0 comments2024-05-13 00:00:00 UTC to 2024-05-20 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-05-20 00:00:00 UTC to 2024-05-27 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-05-27 00:00:00 UTC to 2024-06-03 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-06-03 00:00:00 UTC to 2024-06-10 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-06-10 00:00:00 UTC to 2024-06-17 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-06-17 00:00:00 UTC to 2024-06-24 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 commentsJun 172024-06-24 00:00:00 UTC to 2024-07-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-07-01 00:00:00 UTC to 2024-07-08 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-07-08 00:00:00 UTC to 2024-07-15 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-07-15 00:00:00 UTC to 2024-07-22 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-07-22 00:00:00 UTC to 2024-07-29 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-07-29 00:00:00 UTC to 2024-08-05 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-08-05 00:00:00 UTC to 2024-08-12 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-08-12 00:00:00 UTC to 2024-08-19 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-08-19 00:00:00 UTC to 2024-08-26 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-08-26 00:00:00 UTC to 2024-09-02 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2024-09-02 00:00:00 UTC to 2024-09-09 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 commentsSep 2

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
Apr 82024-04-08 00:00:00 UTC2024-04-15 00:00:00 UTC211
Apr 152024-04-15 00:00:00 UTC2024-04-22 00:00:00 UTC101
Apr 222024-04-22 00:00:00 UTC2024-04-29 00:00:00 UTC202
Apr 292024-04-29 00:00:00 UTC2024-05-06 00:00:00 UTC101
May 62024-05-06 00:00:00 UTC2024-05-13 00:00:00 UTC110
May 132024-05-13 00:00:00 UTC2024-05-20 00:00:00 UTC000
May 202024-05-20 00:00:00 UTC2024-05-27 00:00:00 UTC000
May 272024-05-27 00:00:00 UTC2024-06-03 00:00:00 UTC000
Jun 32024-06-03 00:00:00 UTC2024-06-10 00:00:00 UTC000
Jun 102024-06-10 00:00:00 UTC2024-06-17 00:00:00 UTC000
Jun 172024-06-17 00:00:00 UTC2024-06-24 00:00:00 UTC000
Jun 242024-06-24 00:00:00 UTC2024-07-01 00:00:00 UTC000
Jul 12024-07-01 00:00:00 UTC2024-07-08 00:00:00 UTC000
Jul 82024-07-08 00:00:00 UTC2024-07-15 00:00:00 UTC000
Jul 152024-07-15 00:00:00 UTC2024-07-22 00:00:00 UTC000
Jul 222024-07-22 00:00:00 UTC2024-07-29 00:00:00 UTC000
Jul 292024-07-29 00:00:00 UTC2024-08-05 00:00:00 UTC000
Aug 52024-08-05 00:00:00 UTC2024-08-12 00:00:00 UTC000
Aug 122024-08-12 00:00:00 UTC2024-08-19 00:00:00 UTC000
Aug 192024-08-19 00:00:00 UTC2024-08-26 00:00:00 UTC000
Aug 262024-08-26 00:00:00 UTC2024-09-02 00:00:00 UTC202
Sep 22024-09-02 00:00:00 UTC2024-09-09 00:00:00 UTC202

What Hacker News says

11 sources
It's literally what it is. You for some reason think transformers are unique to language models - boy are you late to the game https://en.wikipedia.org/wiki/Transformation_matrix A CSS matrix "transform" is the same concept. Same with tile engines & game dev. Say I wanted to rotate a map: Input [ [0, 0, 1], [0, 0, 0], [0, 0, 0] ] Output [ [0, 0, 0], [0, 0, 0], [0, 0, 1] ] The function is a "transformer" because it is not looking up some rule that says where to put the new values, it's performing math on the data structure whose result determines the new values. > Not quite sure about "it's not based on rules" when your code has things like: > > const MATCH_FIRST_MODAL Totally irrelevant to the topic. This is the chat interface itself which mostly just parses questions into cursors to be completed. You would be a
Read the rest
fool to think ChatGPT has no NLP or parts-of-speech analysis. text-ada-embedding itself uses POS. > Pretty sure your examples in the video are also cherry-picked Fantastic detective work, you caught me. But just to confirm - why not just use it yourself? npm i next-token-prediction Here is an example you can run very easily in Chrome, so you don't have to rely solely on your amazing bullshit detector: https://github.com/bennyschmidt/next-token-prediction/tree/m... Don't forget to log the completions to prove that they aren't broken down by token, and instead just doing key/val lookups or text searches as you said. > What really happens is, one of the hardcoded regexps transforms it to "Paris is" The only thing you got right - that questions are transformed into sentences using conventional NLP in order to complete them. This functionality is what makes it a chat bot that you can ask questions.
In Building LLMs from the Ground Up: A 3-Hour Coding Workshop
I get this question only on Hacker News, and am baffled as to why (and also the question "isn't this just n-grams, nothing more?"). https://github.com/bennyschmidt/next-token-prediction ^ If you look at this GitHub repo, should be obvious it's a token prediction library - the video of the browser demo shown there clearly shows it being used with an <input /> to autocomplete text based on your domain-specific data. Is THAT a Markov chain, nothing more? What a strange question, the answer is an obvious "No" - it's a front-end library for predicting text and pixels (AKA tokens). https://github.com/bennyschmidt/llimo This project, which uses the aforementioned library is a chat bot. There's an added NLP layer that uses parts-of-speech analysis to transform your inputs into a cursor that is completed (AKA "answered"). See the video where I am
Read the rest
chatting with the bot about Paris? Is that nothing more than a standard Markov chain? Nothing else going on? Again the answer is an obvious "No" it's a chat bot - what about the NLP work, or the chat interface, etc. makes you ask if it's nothing more than a standard [insert vague philosophical idea]? To me, your question is like when people were asking if jQuery "is just a monad"? I don't understand the significance of the question - jQuery is a library for web development. Maybe there are some similarities to this philosophical concept "monad"? See: https://stackoverflow.com/questions/10496932/is-jquery-a-mon... It's like saying "I looked at your website and have concluded it is nothing more than an Array."
In Building LLMs from the Ground Up: A 3-Hour Coding Workshop
nopro·May 9, 2024Submission

Ask HN: Good AI/LLM hiring communities?

Are there any sites focused on just hiring for AI/LLM companies? The best I've found so far is workatastartup with "llm" in the search field. The reason I ask is because HN is very divided on the issue of AI and posting anything about it gets you easily downvoted. For job posts "Who's Hiring", etc. it would be neat if the AI/LLMs were separated out to its own post. Is there any forum-like community focused around AI/LLMs? I'm a full stack engineer in SF specifically looking for a job working with LLMs pref. in a Node/React setup. Here is my info: Location: San Francisco Remote: Sure Relocate: Depends Technologies: Node/React, working with LLMs would be a plus Résumé/CV: https://bennyschmidt.com Email: hello@bennyschmidt.com ----- YC alum of: Brave, Checkr GitHub: https://github.com/benny
Read the rest
schmidt Neat project: https://github.com/bennyschmidt/next-token-prediction Any help is appreciated! Edit: Feel free to turn this post into a "Who's Looking for Work: LLM Edition" by leaving your info in a comment!
1 points · Open discussion
GPU vs CPU: It's faster to use a GPU. If you tried to play a game on a laptop with onboard gfx vs buying a good external graphics card, it might technically work but a good GPU gives you more processing power and VRAM to make it a faster experience. Same thing here. When is GPU needed: You need it for both initial training (which it sounds like you've done) and also when someone prompts the LLM and it parses their query (called inference). So to answer your question - your web server that handles LLM queries coming in also needs a great GPU because with any amount of user activity it will be running effectively 24/7 as users are continually prompting it, as they would use any other site you have online. When is GPU not needed: Computationally, inference is just "next token prediction", but depending on how the user enters their prompt som
Read the rest
etimes it's able to provide those predictions (called completions) with pre-computed embeddings, or in other words by performing a simple lookup, and the GPU is not invoked. For example in this autocompletion/token-prediction library I wrote that uses an ngram language model (https://github.com/bennyschmidt/next-token-prediction), GPU is only needed for initial training on text data, but there's no inference component to it - so completions are fast and don't invoke the GPU, they are effectively lookups. An LM like this could be trained offline and deployed cheaply, no cloud GPU needed. And you will notice that LLMs sometimes will work this way, especially with follow-up prompting once it already has the needed embeddings from the initial prompt - for some responses, an LLM is fast like this. On-prem: Beyond the GPU requirement, it's not fundamentally different than any other web server. You can buy/build a gaming PC with a decent GPU, forward ports, get a domain, install a cert, run your model locally, and now you have an LLM server online. If you like Raspberry Pi, you might look into the NVIDIA Jetson Nano (https://www.nvidia.com/en-us/autonomous-machines/embedded-sy...) as it's basically a tiny computer like the Pi but with a GPU and designed for AI. So you can cheaply and easily get an AI/LLM server running out of your apartment. Cloud & serverless: Hosting is not very different from conventional web servers except that their hardware has more VRAM and their software is designed for LLM access rather than a web backend (different db technologies, different frameworks/libraries). Of course AWS already has options for deploying your own models and there are a number of tutorials showing how to deploy Ollama on EC2. There's also serverless providers - Replicate, Lightning.AI - these are your Vercels and Herokus that you might pay a little more for but get convenience so you can get up and running quickly. TLDR: It's like any other web server except you need more GPU/VRAM to do training and inference. Whether you want to run it yourself on-prem, host in the cloud, use a PaaS, etc. those are mostly the same decisions as any other project.
In Ask HN: How does deploying a fine-tuned model work
Very nice, thanks for sharing! I noticed their token sequence length is fixed: Constructing 7-gram LM ... Created trie with 21,502,513 nodes. People on here will be happy to say that I do a similar thing, however my sequence length is dynamic because I also use a 2nd data structure - I'll use pretentious academic speak: I use a simple bigram LM (2-gram) for single next-word likeliness and separately a trie that models all words and phrases (so, n-gram). Not sure how many total nodes because sentence lengths vary in training data, but there are about 200,000 entry points (keys) so probably about 2-10 million total nodes in the default setup. "Constructing 7-gram LM": They likely started with bigrams (what I use) which only tells you the next word based on 1 word given, and thought to increase accuracy by modeling out more words in a s
Read the rest
equence, and eventually let the user (developer) pass in any amount they want to model (https://github.com/google-research/google-research/blob/5c87...). I thought of this too at first, but I actually got more accuracy (and speed) out of just keeping them as bigrams and making a totally separate structure that models out an n-gram of all phrases (e.g. could be a 24-token long sequence or 100+ tokens etc. I model it all) and if that phrase is found, then I just get the bigram assumption of the last token of the phrase. This works better when the training data is more diverse (for a very generic model), but theirs would probably outperform mine on accuracy when the training data has a lot of nearly identical sentences that only change wildly toward the end - I don't find this pattern in typical data though, maybe for certain coding and other tasks there are those patterns though. But because it's not dynamic and they make you provide that number, even a low number (any phrase longer than 2 words) - theirs will always have to do more lookup work than with simple bigrams and they're also limited by that fixed number as far as accuracy. I wonder how scalable that is - if I need to train on occasional ~100-word long sentences but also (and mostly) just ~3-word long sentences, I guess I set this to 100 and have a mostly "undefined" trie. I also thought of the name "LMJS", theirs is "jslm" :) but I went with simply "next-token-prediction" because that's what it ultimately does as a library. I don't know what theirs is really designed for other than proving a concept. Most of their code files are actually comments and hypothetical scenarios. I recently added a browser example showing simple autocomplete using my library: https://github.com/bennyschmidt/next-token-prediction/tree/m... (video) And next I'm implementing 8-dimensional embeddings that are converted to normalized vectors between 0-1 to see if doing math on them does anything useful beyond similarity, right now they look like this: [nextFrequency, prevalence, specificity, length, firstLetter, lastLetter, firstVowel, lastVowel] For example, here's the embedding for "dog": [0.6666666666666666, 0.6, 0.45714285714285713, 0.15, 0.12, 0.24, 0.56, 0.56] where it used to just be 1D: { dog: 23 } Up until now I've only effectively used nextFrequency to predict the next word, but with these other 7 metrics I'm able to store more info about each word and being vectors am able to store it efficiently, and do what all the smart people keep saying like dot product similarity index etc. The big boys are using like 1536D arrays etc. but with just 7 it still works, and it's weird that it works. Thanks again for sharing!
In Show HN: Next-token prediction in JavaScript
nopro·Apr 10, 2024Submission

Show HN: Next-token prediction in JavaScript

What inspired this project today was watching this amazing video by 3Blue1Brown called "But what is a GPT?" on Youtube (https://www.youtube.com/watch?v=wjZofJX0v4M - I highly recommend watching it). I added it to the repo for reference. When it clicked in my head that "knowing a fact" 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. For example: "I want to be at the beach", "I will do it later", "I want to know the answer", ... becomes: { I: { want: { to: { be: { ... }, know: { ... } } }, will: { ... } }, ... } in JavaScript. You can exploit the language's fast object lookup speed
Read the rest
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). Accompanying research yielded learnings about what "tokens" and "embeddings" are, what is meant by "training", and most of the rest - though I'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'll call "token-agnostic" - didn't care if you were looking for the next letter... word... pixel... it's the same logic. But actually it'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. Goals of the project: - Demystify LLMs for people, show that it's just regular code that does normal stuff - Actually make a pretty good LLM in JavaScript, with a version at least capable of running in a browser tab
88 points · Open discussion

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.