In a Transformer-based large language model, the vocabulary is not explicitly carried forward layer to layer. Instead, the model uses a learned embedding matrix to represent the input tokens, and this embedding matrix is used throughout the model.
Token embeddings
The token embeddings are learned during training and are stored in a matrix called the embedding matrix. This matrix has a shape like (vocab_size, embedding_dim), where vocab_size is the number of unique tokens in the model's vocabulary, and embedding_dim is the dimensionality of the embedding space.
When a token is input to the model, it is looked up in the embedding matrix to retrieve its corresponding embedding vector. This embedding vector is then used as input to the first layer of the model.
Layer-wise transformations
In each layer of the model, the input embedding vector is transformed using a set of learnable weights and biases. These transformations are designed to capture complex relationships between the input tokens and to generate a sequence of vectors that represent the input text.
The transformations in each layer are applied to the entire sequence of vectors, not just the individual token embeddings. This means that the model can capture long-range dependencies and contextual relationships between tokens.
No explicit vocabulary carry-forward
The vocabulary is not explicitly carried forward layer to layer. Instead, the model uses the learned embedding matrix to represent the input tokens, and this embedding matrix is used throughout the model.
Logit calculation
The final layer of the model, often called the output layer, takes the output of the previous layers and generates a logit vector for each token in the vocabulary. The logit vector represents the model's predicted probability distribution over the vocabulary.
The logit calculation involves a linear transformation of the output of the previous layers, followed by a softmax activation function. The softmax function maps the logit vector to a probability distribution over the vocabulary.
Vocabulary size
The vocabulary size is a hyperparameter that is set before training the model. The model is trained to predict the next token in a sequence, given the context of the previous tokens. The vocabulary size determines the number of possible output tokens that the model can predict.
In summary, the model's vocabulary is not explicitly carried forward layer to layer. Instead, the model uses a learned embedding matrix to represent the input tokens, and this embedding matrix is used throughout the model. The logit calculation in the final layer generates a probability distribution over the vocabulary, based on the output of the previous layers.