From text to training target: word division, tab move and confusion
Manually perform a subword merge, draw a self-return to the label position, and calculate negative logarithms and confusion using a fixed probability.
Learning objectives and first steps3 objectives 2 first repairs
Try to do it after reading
- Distinguishing Bytes, Characters, token and Phrase Index
- Resume BPE merge with next-token tab move
- Explain language model objectives, loss mask And confused caliber
Suggested first
- Cross entropy and Softmax
- Transformer and Causal mask
Why does the same sentence have a different context
"The text has 1,000 words" does not directly tell us how long the model needs to be entered. The model handles separated token output from tokenizer; Chinese characters, English words, spaces, punctuations and even byte segments may affect severing. The same technical document is replaced by a tokenizer, which can change the way the length is separated from rare terms, thus affecting training costs, context cut-off and service budgets.
Before reading this chapter, it is necessary to know how cross entropy is lost from the predicted probabilities and how causal mask limits its current position. This chapter does not train real words, but rather displays algorithms with a clear little word and then connects the token sequence to the predicted target. (a) Distinguishing first four things: normative decision-making on how to deal with the text form; (a) Pre-design the preliminary boundary; Subword algorithm determines the snippet combination; Special token and chat templates determine the structure of the session. Together, they constitute repossessable input agreements.
A very small BPE merge
Set the language as low Twicelower Come on once. In order to avoid mixing the boundary between words into an example, each word is first de-characterized with an independent endpoint. First neighboring pairs,l o and o w The weighted frequency is three; It was therefore necessary to establish parallel rules. This case has agreed to select a smaller dictionary order first l o, generate a fragment loMerge lo w Got it lowI don't know. The byte encoding, standardization and parallelization rules of the actual tokenizer cannot be replaced by this toy example.
The consolidated tables have a sequential rule, and the reasoning cannot be re-stating the global frequency at each time in the new text. Training materials to determine which of the combined entries to the glossary; Apply the saved rules when encoded. Original token ID Just a line index, numbering close does not represent semantic closeness. The shape embedded in the matrix E is the word table size V x hidden dimension d, and the corresponding line is detected with ID before a continuous vector is obtained.BPE course for HF The distinction between training and coding can be verified.
SentencePiece is a splitting tool system for original sentences and cannot simply be used as the "name of another BPE". The specific model may have different sub-word algorithms; Normative configurations are also model assets.SentencePiece original paper To understand this border. The actual recovery must save tokenizer files, versions, special ID and chat templates, otherwise the same set of parameters may see different input.
Where's the self-regression projection
Set Input As [BOS, 我, 爱, 猫]I don't know. Position zero predicts "me" according to BOS, and the next position advances according to "love" based on prefixed predictions. Training can be used to calculate all positions in parallel, but the visible range of each location is still limited by causal mask; Parallelity does not mean reading future answers. logits returned to the model is usually B x T x V with a label B x T; Specific training equipment may be moved internally and cannot be moved externally.
For the active target position pool I, the mean token appears to be taken from the negative logarithm; Logarithms are calculated at the natural level and the unit of loss can write nats/ token. Confusion is an index of average loss. When comparing across tokenizer, token units in the denominator are different and the lower values cannot be interpreted directly into stronger models; Fixed text distribution and border processing are also required.
Take two active targets, right? token The probability is 0.5 and 0.25. The total negative logarithm is 0.693147+1.386294 = 2.079442, average 1.039721, confused about 2.8284227. If two additional padding locations are added, the denominator should remain two active targets; The erroneous division by four would make the loss look better, without improving the forecast. When the effective target is zero, samples should be stopped and checked instead of continuing training after zero.
Three types of targets cannot be confused with visible ranges
Predict the next token from the regression target; (a) The BERT-style mask target restores the hidden position in the input with both sides; Noise text from T5 to the text target converts the missing fragments to the target sequence. They determine what models can read, where they will be supervised and how they will be used downstream. The full bidirectional input of BERT cannot be used directly for self-retroactivity assessment for claiming no leakage. You can read it separately BERT and T5 Check the original settings and this chapter does not repeat their historical scores.
Recompute and Project Error
import mathprobs = [.5, .25]valid = [True, True]losses = [-math.log(p) for p, ok in zip(probs, valid) if ok]assert lossesloss = sum(losses) / len(losses)print(round(loss, 6), round(math.exp(loss), 6))# 1.039721 2.828427This standard Python has been implemented and only the probability and loss arithmetic has been validated. Framework training not implemented. When actually checking, print a sample decoding input, label, neglect position and template, and do not focus on the total loss. Common errors include the head of the assistant answer token Blocked, user text as the answer to be learned, puzzled the document with no intention of allowing cross-document reading, tokenizer Added two BOS 。 If you replace a glossary, check the number of header lines embedded with the output and whether new lines need to be retrained.
Check understanding
token ID A hundred words. ID Is the word for 200 closer to zero?
There is no such meaning. ID is a discrete index and semantic relationships are derived from the vectors and networks learned. Entering ID directly into a linear model will introduce an additional unsupported distance structure.
What if the BPE is the same frequency as the two groups in the training?
It is necessary to use established parallel rules and preserve the product, otherwise it may be possible to obtain a different order of consolidation. The true recovery should restore the tokenizer asset instead of merely recording the size of the word sheet.
Why is the first "I" label for BOS output?
Next item after the prefix for learning from the regression model. If the “I” location is used to predict the “I” without any change, the model may read its own input, change the problem and cause leakage.
After the length of padding, the loss drops. What should we suspect first?
Checks whether the denominators have wrongly used the total length after filling and whether the neglect position is really excluded. The correct average token loss should remain unchanged when the probability of validity of token remains unchanged.
Does the confusion of 2:08 mean that less than three words are available for each step?
It is not the size of the phrase or the number of candidates. It is a geometric mean of the probability of the correct target and is used to summarize the prediction of uncertainty; It is still possible to allocate probabilities on a large list of words at each step.
Two sets of the same text, tokenizer, can you be more perplexed than token?
Usually not. The unit changes, the particle size changes. A common calibre of tokenizer should be fixed with the evaluation text or be compared with a strictly defined byte level.
Check date 2026-10-29; The BERT page is v2, the T5 page is v4 and the HF course is dynamic. Keep reading Pre-training and data, expands the single series to auditable data and arithmetical books.
Sources and reconciliations
Definitions, methods and interfaces are available.
- Hugging Face LLM Course — Byte-Pair Encoding tokenization
- SentencePiece — A simple and language independent subword tokenizer
- BERT — Pre-training of Deep Bidirectional Transformers
- Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer
Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.