AI Hero Club

Train a Language Model from Scratch · Lesson 7

Marked Complete by You0 / 8

Saved in this browser only. Marking a lesson complete does not mean the project has passed verification.

Lesson Outline 7 subsections
Course Contents 8 lessons
Full course plan.
Train a Language Model from Scratch / Learning Plan ↗

LESSON 07 / 8Suggested study 120 minutes

Evaluation and Generation Failures under a Frozen Protocol

When test loss improves but generated text is corrupted, which statistics and output failures should we check separately?

3 Questions for This Lesson
  • Recreate token PPL from the document-by-document NLL with every original bytes of regular paths containing EOS
  • The use of the unigram baseline identification indicator calibre and training statistics
  • Record separately loss, generation number, UTF- 8 legitimacy and observable failure on the freeze model
Course Project ZIP ↓

Task and Prerequisites: Make the Metric Recomputable

The training receipts indicate that the process has been optimized, but no answer has been given to leave the text difficult and generate behaviour. This chapter is about to produce an auditable assessment from the freeze, rather than selecting the best sample. Readers need three pre-chapters of conditionality, logarithms, bytes and regular BPE paths, as well as a non-overlap window for chapter IV. We clearly report on three different categories of subjects: conditions under the freeze parameters predict losses, chains of decoding rules, distributions and task boundaries. Twenty-four and thirty-two fixed widths have been requested before the test to merge and 80 updates, and configurations are selected without testing fractions.

Assessment of the mode.eval and no gradient context to avoid training behaviors and calculation maps; restoration of the original train/eval status after completion, so that regular validation in training does not change the next mode quietly. This experiment dropout and mode switch has a small impact on current values, and the interface contract is still maintained. Each window-by-wind calculation of Loss multiplied the valid target number of the window, resulting in NLL summation, then accumulated document targets and original UTF-8 byte. All text token and EOS are counted once; The output is recorded on a document-by-document basis, so that the overall results can be independently recalculated.

Metric 1: Likelihood and Perplexity

Makes the NLL under the fixed window agreement for the J document to be SjS_j The number of valid targets is: NjN_j The original bytes of the text is BjB_j. The sum and the difference are S, N, B. For the same tokenizer and context, the average NL is S/N; the confusion is its index, which is equal to the number of geometrical averages of the true target probability. “Equivalent Candidates” is just a hunch for this value, and it cannot be inferred that the model was actually evenly selected in several words. Different codes or boundaries change N, even if the same text does not directly cross the PPL.

ℓ‾=∑jSj∑jNj,PPL=exp⁡(ℓ‾),R=∑jSj(∑jBj)log⁡2.\overline\ell=\frac{\sum_jS_j}{\sum_jN_j},\quad \mathrm{PPL}=\exp(\overline\ell),\quad R=\frac{\sum_jS_j}{(\sum_jB_j)\log2}.
R officially refers to the standard token path number of EOS per original byte; it is not the size of the compressed file that has been achieved.

From logarithm to base, divided by nats log⁡2\log2 The BPE may have multiple token sequences decoded into the same text, and this item is only given a score for the norm encoded path, so R is not a negative logarithm of the text edges sought and obtained for all paths. The molecules also contain each EOS charge, and the denominator does not contain BOS/EOS or JSON fields. To compare two tokenizers, at least the same original text, the same border scoring policy, the same window and model budget, and retain this limitation in the name. A uniform denominator does not eliminate all design differences.

Example 1: Cross-Checking Three Numbers

Assuming two tests, the total NLL is six and nine, the total target is two and four, respectively, and the original text is three and seven bytes, respectively. S=15 、 N=6 、 B=10, mean 2. 5 nats/target PPL about 12. 182494 R, about 2. 164043 bits/raw - Byte. Two averages first. 3+2.25)/2 = 2.625, wrongly increasing the weight of short text. The independent check is that the natural logarithm is returned to 2 with a PPL. 5; independent inspection II returns to 15 by R times 10 and log2. This loop accounts for errors in denominators, base shifts, and field units.

The real fixation test for the project was four, each 63 original bytes, 252 bytes; BPE plus EOS total 119, NLL total 401. 284752. The same molecule gets 3. 372141 nats/target The PPL is about 29. 140844 R, about 2. 297347. Each test and validation has only one action template group and still shares the name and end phrases, so this result can only describe the difficulty of setting aside within the manual system. Decimal numbers are derived from calculations and do not represent a small error in estimation; four highly relevant texts do not support the exact conclusion of the natural material population.

A Baseline That Makes a Complex System Interpretable

The first baseline is that all V output categories are uniform and any target loss logV can be checked directly for the code ' s level of numbers. The second baseline is measured by training targets to smooth unigram: the probability of each number is (count+alpha)/( total training target + alpha×V), alpha one). It reflects only the frequency of the training category without reading the context. Validation and testing only check this freezing probability table and cannot be reestimated. Even if BOS had never been a training target, it was still in model V output support, so this baseline also gives BOS smooth probability and makes comparative support consistent; it does not generate BOS as the correct target.

q(v)=ctr(v)+1Ntr+V,Sq(D)=−∑y∈Dlog⁡q(y).q(v)=\frac{c_{tr}(v)+1}{N_{tr}+V},\qquad S_q(\mathcal D)=-\sum_{y\in\mathcal D}\log q(y).
The count includes only the actual target of training pools to be projected, including EOS, excluding BOS; plus a limited NL not seen in Token.

Example 2: Infinite Loss Without Smoothing and Invalid Test-Set Fitting

Toy training targets. [a,a,b,EOS] Four types of support [a,b,c,EOS]. Add the probability of 3/8 、 2/8 、 1/8 、 2/8. Test target [c,EOS] NLL is −log⁡(1/8)−log⁡(2/8)=log⁡32≈3.465736-\log(1/8)-\log(2/8)=\log32\approx3.465736, which is about 1. 732868 per target average. If not smooth, the probability of c is zero and NLL is unlimited; this does not mean that mathematics is broken, but that the baseline gives a zero probability of observing events. If test c is also counted as a frequency of training, the loss becomes smaller, but no longer an effective assessment of missing data.

Baselines are better than nerve models, and they do not have to hide failures: they may mean that model budgets are too small, optimize unstable, window agreements are unfavourable, or data are just frequency-driven. Conversely, it is better than unigram that some context statistics are used, without proving complex reasoning. We do not set selection rules for “You have to be above a threshold to show.” here because that encourages the selection of Seed and test sets.

Standalone ProgramStandard library independent validation: The molecular denominator converts to complete values not found in the category unigram.
import math
S,N,B=15.,6,10
ppl=math.exp(S/N); rate=S/(B*math.log(2))
assert abs(math.log(ppl)-2.5)<1e-12
assert abs(rate*B*math.log(2)-S)<1e-12
train=['a','a','b','EOS']; vocab=['a','b','c','EOS']
q={v:(train.count(v)+1)/(len(train)+len(vocab)) for v in vocab}
nll=-sum(math.log(q[v]) for v in ['c','EOS'])
assert abs(nll-math.log(32))<1e-12
assert abs(sum(q.values())-1)<1e-12
print('PPL',round(ppl,6),'bits/byte',round(rate,6),'smoothed test NLL',round(nll,6))

Generation as a Policy-Dependent Observation

Project generation starts with Bos+prompt text code, takes the final location logits, hides the Bos candidate, allows the biggest selection by greedy, and stops or reaches max_new when EOS is selected. This is not a random sampling from the original model distribution: BOS candidates are banned and anagmax has changed behavior, so that the samples cannot be generated directly as an undistributed statistical estimate. If the context exceeds C, the last C number is taken and recalculated from the position zero, without pretending that the absolute position of learned will grow indefinitely; Generating location is therefore different from the full long context condition.

The same model gives “There's a low loss.” different questions from “greedyFinal Output Readable”. Each step of the scale is evaluated in the true past, and a error that produces its output continues to be considered context. A single error may allow follow-up into a rare area of training, creating duplicates, mixed words or illegal UTF-8. Prompt, generation numbers, EOS stop, and strict UTF-8 success and decoding strategies should be preserved; and evidence of faults in natural language sentences that can be located if only after modifier. Random sampling with temperature or top-k must also be recorded as a new explicit protocol.

The actual fixed experiment prept “Mio.”'s greedy continues to be “The whole bridge wrote about the time.。”, and UTF-8 is legal and stopped with EOS. The end line comes from the training shared template, the first half of the sentence is confused. This supports only a limited conclusion: the model can export a valid byte from the visible segment of the setup and end control observable; it does not support “I learned to write Chinese.”. Even if another prompt occasionally produces a catchphrase, it cannot eliminate the saved failure. There is no independent manual rating agreement for this material, so a subjective perception is not written as an accuracy rate.

Uncertainty, Held-out Groups, and Diagnostic Levels

Average document fluctuations cannot be trusted as separate samples. Our four tests are derived from the same action template, which is strongly correlated; a general Bootstrap sample of four independents underestimates the uncertainty at the level of the template. To estimate cross-modelization, there should be several separate groups that can be re-sampled or cross-checked at the group level and leave additional tests for model selection. The current project does not have enough stand-alone groups to stabilize the overall area, so the report is more honest by document detail and limitations than by decorative “Positive and negative error bar”.

The diagnostic order should go from compacts to statistics: pre-checking of language materials and tokenizer summaries, valid targets against EOS numbers, checking whether the loss is limited, even baselines are aligned, weights are frozen, and finally explaining the train/validation gap. Training of NLs is low and high, can match a limited data overlay, or may leave groups with few training bytes; a file-by-document and category-by-document statistics cannot be used alone to assert a faulty structure. If an assessment is made to achieve a leaking window, even if the curve is not effective, it should first be repaired and all affected results rerun.

Chapter VIII will freeze the same indications and assessment agreements, but only change the width and update the budget to discuss what constitutes controlled scale evidence. It should be possible to recover three indicators independently from evaluation-test.json before entering the next chapter, and explain why they are neither natural language credits nor mathematical fundamentals that necessarily decrease with the number of tokens trained.

The baseline measurements are also stored in the beselines.json. The goal of the fixed tests is 5.669881 per uniform NL, plus a training unit for 4.399566 and a full microdecoder 3. 372141. The three models use the same term table, the same target pool and the same EOS policy, so this is comparable under this agreement: Decoder uses more information than frequency in the training category in this setup. This comparison does not isolate the benefits of a specific structure, as the unigram parameterization is different from the training method; it is only a reference that reveals whether there are obvious problems with the flow line.

Softmax contains the BOS column at the time of the assessment, but its true goal is never to be BOS, but its distribution probability crowds out other categories; it is created with a new limit on the distribution of conditions. So if you want to estimate the quality of the generation strategy strictly, you should sample and rate it according to that strategy; the original teacher-forcing NLL cannot be referred to directly as the performance after binding decoding. This project uses only a gready sample for failure observations and clearly records its strategies and does not make an overall statistical extrapolation of the sample.

If the original bytes of a test text are very short, EOS will have a larger share of R; the same text predicts a higher end cost than a small number of long text in large volumes. Therefore, cross-dataset comparisons also report the distribution of files and lengths, not just total B. Each text of this project has a fixed boundary ratio that is suitable for checking the formula without covering the estimation of the mix of lengths. Keeping document-by-document NLLs and lengths would allow the difference to be examined later.

Probability quality can also be questioned from the point of calibration, but the current project does not achieve a reliable calibration evaluation alone. Low NLL rewards higher probability for real targets and punishes overconfident errors, but does not alone tell us whether the correct rate is matched in a confidence box; “Confidence”, which generates sentences, is not the best probability totoken. For calibration to be studied, it requires an independent definition of target events, compartments, and samples, and avoids choosing temperature on the same small test. Here, the original probabilities are retained, rather than being called reliability of answers or factual accuracy.

Terminal CommandRuns in the downloading of the root directory of the project, installed in a stationary Python environment; this is the project command and not the Python source code.
python run.py evaluate --split test
python baseline.py

TRY IT YOURSELF

Practice I: Back to test indicators

To S=401.28475189208984, N=119, B=252 to write three indicator formulas and orders of magnitude indicating in which quantity EOS is.

Hint 1
Distinguishing units S, N, B, EOS and BOS.
Hint 2
Write S/N, exp(S/N), S/(B log2 in turn; check if the molecular denominator is changed together if the EOS caliber is changed.
Compare with the Solution
Average S/N about 3. 372141, PPL for exp(S/N) about 29. 140844; R for S/(252log2) about 2. 297347. Both NLL and N contain four EOS targets with B only in the text UTF-8 byte. BOS is not counted as N only, target -100 is completely non-scored. If EOS is excluded, the equivalents must be deducted from S with N, not just the denominator.

TRY IT YOURSELF

Practice II: Search for Assessment of Pollution

Some people update the unigram count on each test document before rating it. They say there is no training of neural networks. Why are the results still different from the task in this chapter?

Hint 1
What data are allowed to be read before a freeze forecaster is rated? The absence of neurological updates does not mean that it does not fit.
Hint 2
The whole piece is counted, projected and updated, and the entire freeze is presented in three chronological order, indicating whether they are the same agreement.
Compare with the Solution
The freeze forecaster should rely only on training data; update the test frequency is equivalent to allowing the forecaster to see the event to be evaluated first and change the test conditions. If you read the whole story before counting, the future is also used. If an online self-adaptation protocol is designed, it must be predicted and updated before it can be shared with a decoding formula, and this task should be reported separately; it cannot be commingled into the freeze model.

TRY IT YOURSELF

Practice III: Generates like

Two reasons are given for the simultaneous presence of “AuthenticationNLLDrop、Generating is still bad.” and a diagnosis is given that does not change the test selection.

Hint 1
What is the difference between the prefix source and free generation of the techer forcing? How do frequent endings affect mean values?
Hint 2
Static prompt, retaining the cause of gradual generation and cessation; disassemblysing NLL by location or document and selecting the best sample without testing.
Compare with the Solution
The first is the use of real prefixes, whereby greedy produces cumulative deviations on its own error prefix; and the preservation of the cause of gradual output and cessation is observable. Second, the frequency of sharing ends has dropped by a lot of target losses, but the initial combination is still poorly learned; the NTL is broken down by document or location and the fixed prompt failure can be diagnosed. The diagnosis should not be tested for new prompt or Seed to report only the best samples; the new improvements should return to the training/certification protocol re-experiling.

CHECK YOUR UNDERSTANDING

Check Your Understanding

Answer first, then open the explanation to check your reasoning. These questions help reveal gaps in understanding; independent implementation and transfer require separate evaluation.

1. Could the small PPL model be a direct indicator of the better totokenizer?

Show ExplanationAt a minimum, the original text, bytes and boundary/consequence protocols should be harmonized.
2. Unigram plus a smooth one avoids what?

Show ExplanationIt guarantees the positive probability of each category within limited support, but it does not guarantee a good forecast.
What's the difference between 3. Teacher forcing and free generation?

Show ExplanationThe creation of errors changes the context and appears to improve without ensuring the smoothness of individual greedy samples.
4. What are the conclusions for which the four same templates test?

Show ExplanationThe inner group is restricted by a narrow number of extrapolations, which should be kept on a document-by-document basis.

Manual completion records your progress; it does not certify your project.