News to me - can you tell me what principle you think an LLM works on?
Now, I haven't gone through your code, I'm relying mainly on your description, so what you've said may have confused me and be different from what you've done, but what you seem to be calling an 'embedding' is a trie storing a dataset of sentences. The actual embedding used in LLMs is a mapping from words (a word/token list is effectively a 1 dimensional space) into a much higher dimensional space that captures aspects of the meaning of the words being embedded (e.g. similar concepts may map to similar vectors in the space, or you might be able to do classic word arithmetic like king - man + woman = queen with the vectors that each word maps to).
Then the neural network works, ultimately resulting in a vector in that space, which we map into the next token.
This is a very different process to looking up a set of options in a trie, and I would expect it to outperform the trie method by an enormous amount on longer outputs, or where outputs that are not in the training data are needed.
// Predict the next word
agent.getTokenPrediction('what');
// Predict the next 5 words
agent.getTokenSequencePrediction('what is', 5);
// Complete the phrase
agent.complete('hopefully');
// Get a top k sample of completion predictions
agent.getCompletions('The sun');
And it has this ability to predict because it's based on a language model that turns mere sentences like: "I want to be at the beach", "I will do it later", "I want to know the answer" into a single model: {
I: {
want: {
to: {
be: { ... },
know: { ... }
}
},
will: { ... }
},
...
}
This model - call it a prefix tree (trie), call it a Markov model or "chain", or "just lookups", anything you like - but it's more specifically than all those a language model.Embeddings: Where my embeddings differ is that they're kept in a structure reflective of their source context. That's how I know what the meaning of the word is. OpenAI's embedding is like this:
Text: "The dog"
Embedding:
{
"object": "embedding",
"index": 0,
"embedding": [
-0.006929283495992422,
-0.005336422007530928,
-4.547132266452536e-05,
-0.024047505110502243,
...
],
}
And those values, particularly those for "dog" will be - like you said - computable with others to find things like similarity, etc. And using that math, they can tell you what the next word will be - and probably a lot of other useful chat-specific things I haven't gotten into.My method is also commonly used in machine learning, and would be TF-IDF vectorization except that I don't fully vectorize the semantics, because it's just based on frequency and token structure:
{
"the": {
"dog": {
"was": 834,
"is": 721,
"will": 36
"has": 442
}
}
}
This system predicts "was" as the next word because it usually is the next word after "dog" (in the source data). This library was built to ultimately provide completions, not have a conversation, so no doubt OpenAI's approach works better for chat.I am however already making a chat model. Here's my approach if anyone cares: The completer already gives great completions and fast, but some of them make no sense to what was asked. The chat model I'm working on here (https://github.com/bennyschmidt/llimo/pull/1) can just get all completions and use parts-of-speech codes to match a completion to the cursor. I don't have this fully implemented yet, but you can get the idea in this PR. This is like an NLP layer specific to chat - has nothing to do with the next-token prediction in general, and there are no NLP libraries in `next-token-prediction` (the npm). The example I've been using to explain this is:
User: "Where is Paris?"
Convert to cursor: "Paris is"
Get completions: "in France", "really nice", "a first name", etc.
Analyze input: "Where is" refers to a location
Analyze completions: "in France" refers to a location
Answer: "Paris is in France"
I hope it makes sense! Thanks for your comment.Edit: And yes, again, the library does not claim to "be an LLM" - it's not that at all, it's actually a next-token prediction library that has methods like `getTokenPrediction` etc. Though you are set up to build an LLM with this if you train enough data :) The library is not going to provide a `chat` function like GPT, not going to provide an img2img API like Stable Diffusion, that would be whatever chat-based or image-based LLM is being made with this library.
It's not an analogy - an artificial neural network is literally what an LLM is. A trie is not an LLM, because it's not a neural network. If someone asked how many parameters a trie loaded with many sentences has, that question wouldn't even make sense, because it doesn't model weights between neurons, unlike an LLM.
I think perhaps you're getting confused between the class of 'next token predicting algorithms' (which is a class with lots of different algorithms in it) and 'LLMs'. LLMs are a specific kind of next token predicting algorithm that work in a particular way. You can make a next token predictor out of a trie (as you have), but it is not an LLM.
(reply was not visible before, so I appended as an Edit)
But you aren't. No amount of data loaded into a trie will turn the trie into a neural net.
> The library is not going to provide a `chat` function like GPT,
Providing a 'chat' function is nothing to do with what a LLM is. Here's the first sentence from the second paragraph of wikipedia on Large Language Models: "LLMs are artificial neural networks." When someone points out that you wouldn't use this kind of library to create an LLM, you generally say something about how you think they're complaining that it doesn't chat with you. It's not about chat, it's about the fact that the functionality you've written about has nothing to do with the way that LLMs work. LLMs are artificial neural networks. What you've written is a trie, not an artificial neural network. Artificial neural networks need fast matrix multiplication, not tries.
`agent.getTokenPrediction('when')`
It's not "bro it's just a trie" like you keep saying no matter what I tell you or try to show you. "A trie" is not a JavaScript library you can install with methods like "getTokenPrediction" or "complete" that help you auto-complete sequences.
And since you love the neuron model so much, know that you can train on data that begets the same node/weight based "learning" that an ANN does, I just haven't gone all-in on the "neuron" analogy. You know - other people here want me to call it a Markov chain, not a trie at all, and don't want me to call the semantic score "embeddings" because they aren't stored as numbers, so one thing I've learned is this phrasing ("branding") matters more than functionality.
Your last paragraph - yeah we agree, and I've been trying to tell a lot of other people that "LLM !== chat bot". Providing a `chat` method doesn't make it equivalent to an LLM so I didn't provide anything related to chat. I have no idea what kind of AI model you might build - could be next-pixel prediction and you get into Stable Diffusion-like functionality, not chat at all.
"What you've written is a trie" I didn't write a trie, they're automatically generated during training. The library has nothing to do with that, but you keep saying it does. What I did write is a next-token prediction library for giving you the next likeliest letter, word, pixel, etc.
Hope this makes sense!
A couple people have basically said "but what does it do?", "what value does it add?"
So I am planning a series of examples with videos for use cases like: Auto-completion, auto-correct, spell checking, search/lookup, and if I can get around to making an ImageDecoder, could get into "next-pixel prediction".
Beyond prediction, I want to make a YouTube video when I can show a working example of a really good chatbot than anyone can just npm install and use, would be funny to give some of the open models a run for their money - but you're right, it's just a hobby project for now. Working on that in a separate project: https://github.com/bennyschmidt/llimo
Thanks for the comment and motivation to write about it!