Almost all generative language models use a decoder-only transformer architecture, making the decoder-only transformer one of the most influential architectures in modern AI. Let’s take a deeper look at an implementation to understand exactly how it works…
Implementation credits: The implementation of a decoder-only transformer we will examine in this post is taken from the NanoGPT repository, created by Andrej Karpathy. This repository implements pretraining of a (large) language model—GPT-2 in particular—in only ~600 lines of code. It is an awesome learning resource.
Block definition: Each block of the decoder-only transformer contains causal self-attention and a feed-forward transformation. Given an input, we apply layer normalization and causal self-attention, followed by a residual connection. Then, we apply layer normalization again, followed by a feed-forward layer and another residual connection. The decoder-only architecture has several blocks; e.g., GPT/GPT-2 has 12 total blocks.
Embedding layers: The decoder-only model has two different embedding layers that it defines. The first embedding layer stores token embeddings for all tokens within the tokenizer’s vocabulary. The other embedding layer stores all positional embeddings used in creating the model’s input.
Forward pass: Assuming we receive a tokenized sequence as input, we first retrieve all token embeddings and add positional embeddings to these token embeddings. After (optionally) applying dropout, we pass these token embeddings through the transformer blocks, then apply a final layer normalization. From here, we can either predict next tokens over all tokens in the sequence (pretraining) or on the last token (inference). Next tokens are predicted using a linear projection that outputs a vector with the same size as the vocabulary.
Generating text: If we want to generate a textual sequence, we just perform the forward pass defined above. However, we keep iteratively predicting the next token for the last token within the input sequence, adding it to our input sequence and repeating. This autoregressive process allows us to generate an entire sequence of text by just iteratively extending our input sequence by a single token.
Configuration: Notably, all of the settings within the architecture described above depend upon configured hyperparameters. For example, we can define the size of the token embeddings, the total number of blocks, the size of the model’s context window, and more by just tweaking the model’s configuration. To create a much larger language model, we typically just increase the embedding dimension and total number of layers. This approach is followed by most modern LLMs to increase model’s total number of parameters.
@_jasonwei We give the same emotional connection experience focusing on virtual YouTuber and anime fandom at @YoDayo_Home you can make images and chat with your favorite anime characters there
Vector databases & embeddings are the current hot thing in AI.
Pinecone, a vector DB company, just raised $100M at ~1b valuation.
Shopify, Brex, Hubspot and others use them for their AI apps
But what are they, how do they work and why are they SO crucial in AI? Let's find out
@kirbyman01@Snap@a16z So for social game apps that give away free credits to new users and daily credits etc. How do these apps solve the retention when their users are making multiple accounts to avoid paying for in-app credits?
We launched a new feature to make your own waifus with our AI!! We gives everyone 150 free tries so enjoy! This generative AI feature is available for both web and iOS users!!