10 ms·
I made a transformer to predict a simple sequence manually
- PaulHoule 3y agoIt's some kind of abstract machine, like a turing machine or the machine that parses regexes, isn't it?
- enriquto 3y agoNeural networks are Turing machines. You can make them perform any computation by carefully setting up their weights. It would be nice to have compilers for them that were not based on approximation, though.
- PartiallyTyped 3y ago> It would be nice to have compilers for them that were not based on approximation, though. Could you elaborate?
- enriquto 3y agoPeople typically set the weights of a neural network using heuristic approximation algorithms, by looking at a large set of example inputs/outputs and trying to find weights that perform the needed computation as accurately as possible. This approximation process is called training. But this approximation happens because nobody really knows how to set the weights otherwise. It would be nice if we had "compilers" for neural networks, where you write an algorithm in a programming language, and you get a neural network (architecture+weights) that performs the same computation. TFA is a beautiful step in that direction. What I want is an automated way to do this, without having to hire vgel every time.
- PartiallyTyped 3y agoWhy would you do that when it's better to do the opposite? Given a model quantize it and compile it to direct code objects that do the same thing much much much faster? The generality of the approach [NNs] implies that they are effectively a union of all programs that may be represented, and as such there needs to be the capacity for that, this capacity is in size, which makes them wasteful for exact solutions. it is fairly trivial to create FFNNs that behave as decision trees using just relus if you can encode your problem as a continuous problem with a finite set of inputs. Then you can very well say that this decision tree is, well, a program, and there you have it. The actual problem is the encoding, which is why NNs are so powerful, that is, they learn the encodings themselves through grad descent and variants.
- nyrikki 3y agoA turing complete system doesn't necessarily mean it's useful, it just means that it's equivalent with a turing machine. The ability to describe any possible algorithm is not that powerful in itself. As an example, algebraic type systems are often TC simply because general recursion is allowed. Feed forward networks are effectively DAGs and while you may be able to express any algorithms using them they are also pairwise linear in respect to inputs. Statistical learning is powerful in finding and matching patterns, but graph rewriting, which is what your doing with initial random weights and training is not trivial. More importantly it doesn't make issues like the halting problem decidable. I don't see why the same limits in graph rewriting languages which were explored in the 90s won't hit using feed forward networks as computation systems outside of the application of nation-state scale computing power. But I am open to understanding where I am wrong.
- shawntan 3y agoShort version of this without the caveats: It's not even Turing complete. I review a few papers on the topic here: https://blog.wtf.sg/posts/2023-02-03-the-new-xor-problem/ https://blog.wtf.sg/posts/2023-02-03-the-new-xor-problem/
- justo-rivera 3y agoThat makes no entropy or cyber-netic sense at all. You would just get a neural network that outputs the exact formula, or algo. Like, if you would just do a sine it would be a taylor series encoded into neurons Its like going from computing PI as a constant to computing it as a giantic float. You lose info
- Legend2440 3y agoThe point of training is to create computer programs through optimization, because there are many problems (like understanding language) that we just don't know how to write programs to do. It's not that we don't know how to set the weights - neural networks are only designed with weights because it makes them easy to optimize. There is no reason to use them if you plan to write your own code for them. You won't be able to do anything that you couldn't do in a normal programming language, because what makes NNs special is the training process.
- shawntan 3y agoSomething close exists: RASP https://arxiv.org/abs/2106.06981 https://arxiv.org/abs/2106.06981 python implementation: https://srush.github.io/raspy/ https://srush.github.io/raspy/
- ComputerGuru 3y agoThe whole point is that we don’t know what rules to encode and we want the system to derive the weights for itself as part of the training process. We have compilers that can do deterministic code - that’s the normal approach.
- shawntan 3y agoWould I be able to solve the Travelling Salesman Problem with a Transformer with the appropriately assigned weights? That would be an achievement. You'd beat some known bounds of the complexity of TSP.
- fooker 3y agoWe don't know. And even if we could try to solve this problem, there is no known way of verifying the solution would be correct in general.
- shawntan 3y agoTSPs are not unsolvable. My point was that Transformers and neural networks as they are now are not Turing machines if you don't allow for the model to grow with the input size. That said, it has to grow in "depth" not just parameters. The fact that people think fixed depth computation can universally compute everything is a worrying trend.
- taneq 3y agoIt’s just any pile of linear algebra that’s been in contact with the AllSpark, right?
- nerdponx 3y agoIt's kind of hard to interpret these things as "automata" in the sense that one might usually think of them. Everything is usually a little fuzzy in a neural network. There's rarely anything like an if/else statement, although (as in the transformer example) you have some cases of "masking" values with 0 or -∞. The output is almost always fuzzy as well, being a collection of scores or probabilities. For example, a model that distinguishes cat pictures and dog pictures might emit a result like "dog:0.95 cat:0.05", and we say that it predicted a cat because the dog score is higher than the cat score. In fact, the core of the transformer, the attention mechanism, is based on a kind of "soft lookup" operation. In a non-fuzzy system, you might want to do something like loop through each token in the sequence, check if that token is relevant to the current token, and take some action if it's relevant. But in a transformer, relevance is not a binary decision. Instead, the attention mechanism computes a continuous relevance score between each pair of tokens in the sequence, and uses those scores to take further action. But some things are not easily generalized directly from a system based on of binary decisions. For example, those relevance scores are used as weights to compute a weighted average over tokens in the vocabulary, and thereby obtain an "average token" for the current position in the sequence. I don't think there's an easy way to interpret this as an extension of some process based on branching logic.
- thewataccount 3y agoThis is simplified a bit - It's just a "machine" that maps [set of inputs] -> [set of probabilities of the next output] First you define a list of tokens - lets say 24 letters because that's easier. They are a machine that takes an input sequence of tokens, does a deterministic series of matrix operations, and outputs what is a list of the probability of every token. "learning" is just the process of setting some of the numbers inside of a matrix(s) used for some of the operations. Notice that there's only a single "if" statement in their final code, and it's for evaluating the result's accuracy. All of the "logic" is from the result of these matrix operations.
- ntonozzi 3y agoYes! Check out this paper describing how Linear Transformers are secretly Fast Weight Programmers: https://arxiv.org/abs/2102.11174 https://arxiv.org/abs/2102.11174.
- KirillPanov 3y agoJürgen Schmidhuber reminds me of Richard Feynman in one very specific way: while everybody else in their respective fields uses math to hide the deep insights they've been mining for publications, Schmidhuber and Feynman just simply tell you the big insight, and then proceed to refine and illuminate it with math.
- tayo42 3y ago> maybe even feel inspired to make your own model by hand as well! Other then a learning exercise to satisfy your curiosity what are you doing with this? I'm starting to get the feeling that anything complex with ml models is unreasonable for a at home blog reader?
- taneq 3y agoI dunno, maybe they actually enjoy hacking on projects like this? Weird I know.
- nerdponx 3y agoIt's an excellent learning exercise, not just to satisfy curiosity but to develop and deepen understanding.
- onemoresoop 3y agoAuthor states in the first paragraph of their blog post: "I've been wanting to understand transformers and attention better for awhile now—I'd read The Illustrated Transformer, but still didn't feel like I had an intuitive understanding of what the various pieces of attention were doing. What's the difference between q and k? And don't even get me started on v!"
- tayo42 3y agolol three people said the same thing, i get that. thats why i said other than learning and satisfying curiosity...
- sterlind 3y agoIn nanoGPT, you pre-train a model on Shakespeare, and in 3 minutes it gets to a Lewis Carroll's Jabberwocky level of fidelity on the source material. It makes up lots of plausible-seeming old English words, learns the basics of English grammar, the layout of the plays, etc. I was pretty amazed that it got that good in such a short period of time. I think locally training a bunch of models to the fidelity of Shakespeare-from-Wish.com might tell you when you've hit on a winning architecture, and when to try scaling up.
- teddykoker 3y agoA related line of work is "Thinking Like Transformers" [1]. They introduce a primitive programming language, RASP, which is composed of operations capable of being modeled with transformer components, and demonstrate how different programs can be written with it, e.g. histograms, sorting. Sasha Rush and Gail Weiss have an excellent blog post on it as well [2]. Follow on work actually demonstrated how RASP-like programs could actually be compiled into model weights without training [3]. [1] https://arxiv.org/abs/2106.06981 https://arxiv.org/abs/2106.06981 [2] https://srush.github.io/raspy/ https://srush.github.io/raspy/ [3] https://arxiv.org/abs/2301.05062 https://arxiv.org/abs/2301.05062
- newhouseb 3y agoHuge fan of RASP et al. If you enjoy this space, might be fun to take a glance at some of my work on HandCrafted Transformers [1] wherein I hand-pick the weights in a transformer model to do long-handed addition similar to how humans learn to do it in gradeshcool. [1] https://colab.research.google.com/github/newhouseb/handcrafted/blob/main/HandCrafted.ipynb https://colab.research.google.com/github/newhouseb/handcraft...
- theGnuMe 3y agoIt seems like a functional language like Haskell would be the right tool for this. Also going from a net to code would be super interesting in terms of explain-ability.
- Supply5411 3y agoI've been kicking around a similar idea for awhile. Why can't we have an intuitive interface to the weights of a model, that a domain expert can tweak by hand to accelerate training? For example, in a vision model, they can increase the "orangeness" collection of weights when detecting traffic cones. That way, instead of requiring thousands/millions more examples to calibrate "orangeness" right, it's accelerated by a human expert. The difficulty is obviously having this interface map to the collections of weights that mean different things, but is there a technical reason this can't be done?
- amilios 3y agoThe technical reason it can't be done (or would be very difficult to do) is that weights are typically very uninterpretable. There aren't specific clusters of neurons that map to one concept or another, everything kind of does everything.
- Supply5411 3y agoI wonder if an expert can "impose" weights onto a model and the model will opt to continue with them when it resumes training. For example, in the vision example, the expert may not know where "orangeness" currently exists, but if they impose their own collection of weight adjustments that represent orangeness, will the model continue to use these weights as the path of least resistance when continuing to optimize? Just spitballing, but if we can't pick out which neurons do what, the alternative would seem to be to encourage the model to adopt a control interface of neurons.
- astrange 3y agoThat would make it less efficient - since learning is compression, a less compressed model will also learn less at the same size.
- Jensson 3y agoHumans have much more compressed models, trying to transfer human learning to machine learning could potentially be a way to get more efficient models. The way we do that currently is by labeling data for training, but maybe there are better ways to do it. Like some semi code to write with hints for the model. Like, instead of labeled data, could have a series of "lectures" of labeled data that would lead to a good end state, instead of training on all the data in parallel. You don't teach a child calculus by showing them a million calculus problems after all, you ramp up starting with simple numbers and then slowly ramping up with more concepts. But to do that we would need to change how we train models. Edit: By doing it that way you could see the skill of the model after each lecture, and update the lecture to try to make the model learn better. Not sure how to do that, but such ways to work with parts of models is a potential way forward.
- utopcell 3y agoDarn it Theia: I can't stop playing your hoverator game!
- dang 3y ago[stub for offtopicness]
- seabass-labrax 3y agoMinor request: can we have 'neural network' or something in the title? This is related to the machine learning 'transformer' architecture, rather than the bundle of coils that couples two circuits electromagnetically.
- sottol 3y ago"no training" gave it away for me.
- seabass-labrax 3y agoI misinterpreted that as "I have no training; I am a beginner" rather than "I am not going to train this thing" :)
- poniko 3y agoThough he was a novis and had no training in the field.
- chungy 3y agoThat's how I interpreted as well. "Electrical transformer without any formal training in electric engineering" is basically how the title read to me. Followed by a lot of confusion when the article was not that. Good on him, it's just... an odd way to phrase it :)
- eichin 3y agoHeh, I went a step further and thought "ooh, a novice EE project, but titling it like that everyone's going to be confused about it involving machine learning" until I realized I was the one that got it backwards...
- tostadora1 3y agoI always wanted to at least have a shallow understanding of Transformers but the paper was way too technical for me. This really helped me understand how they work! Or at least I understood your example, it was very clear. And I also got to brush up my matrix stuff from uni lol. Thanks!
- mode80 3y agoI love Karpathy et al but this is what finally made it click for me: https://youtu.be/kWLed8o5M2Y?si=SJT5_lCJ0hSR7Z_k https://youtu.be/kWLed8o5M2Y?si=SJT5_lCJ0hSR7Z_k
- thomasahle 3y agoI thought I understood transformers well, even though I had never implemented them. Then one day I implemented them, and they didn't work/train nearly as well as the standard pytorch transformer. I eventually realized that I had ignored the dropout, because I thought my data could never overfit. (I trained the transformer to add numbers, and I never showed it the same pair twice.) Turns out dropout has a much bigger role than I had realized. TLDR, just go and implement a transformer. The more from scratch the better. Everyone I know who tried it, ended up learning something they hadn't expected. From how training is parallelized over tokens down to how backprop really works. It's different for every person.
- fransje26 3y agoWould you have any literature to recommend, to help get some insight in how to approach the task?
- juliangoldsmith 3y agoAndrej Karpathy has a series on YouTube where he builds everything up from scratch. He implements a transformer when he builds a GPT-style model: https://www.youtube.com/watch?v=kCc8FmEb1nY https://www.youtube.com/watch?v=kCc8FmEb1nY
- fransje26 3y agoThank you for the tip!
- thomasahle 3y agoThere are a lot of "simple transformer" implementations on github. But I'll recommend Microsofts new Phi 1.5: https://huggingface.co/microsoft/phi-1_5/blob/main/modeling_mixformer_sequential.py https://huggingface.co/microsoft/phi-1_5/blob/main/modeling_... It's well written, and very modern, including rotary embeddings and a kv-cache for inference.
- fransje26 3y ago