Generative AI & LLM Engineering Foundations

Datasets That Can Disagree With You

Split related examples together, define loss targets deliberately, and prevent evaluation leakage.

In this chapter

  • Create grouped training and evaluation splits
  • Explain supervised loss masks
  • Keep ambiguous labels visible
An auditable training boundary
  1. Synthetic conversations
  2. Group and label policy
  3. Training partition
  4. Frozen evaluation partition
  5. Versioned dataset manifest

The group, not the individual row, is the unit of separation when examples share an origin.

A split is an experimental boundary

Suppose one fictional customer conversation produces five paraphrased training examples. If four enter training and one enters evaluation, the held-out example is not meaningfully independent. Group related messages by conversation, incident, source document, or generation seed before splitting. A random row split can look balanced while leaking almost identical content into both sides.

Define the label policy before collecting a large dataset. A message about an invoice page that will not load could be billing or reliability depending on the operational contract. Write the boundary explicitly, retain ambiguous cases for review, and record disagreements. A model cannot repair a training objective that tells it two incompatible things without explanation. Synthetic examples are useful for mechanics, but do not establish performance on real customer language.

Choose which positions contribute to loss

In supervised language-model adaptation, some token positions can be excluded from the training loss. For example, a prompt may provide context while only the desired response is scored. Padding positions should not become meaningful targets. Masking a position from loss does not remove it from the model's input; attention masking is a different operation. Accidentally scoring prompt text can change the training objective in ways that aggregate loss obscures.

python
import hashlib
import math

examples = [('thread-a', 'invoice issue'), ('thread-a', 'same incident'), ('thread-b', 'login issue')]
def split(group):
    number = int(hashlib.sha256(group.encode()).hexdigest()[:8], 16)
    return 'evaluation' if number % 5 == 0 else 'training'
assert split(examples[0][0]) == split(examples[1][0])

correct_token_probabilities = [0.9, 0.2, 0.8]
loss_mask = [0, 1, 1]
selected = [-math.log(p) for p, use in zip(correct_token_probabilities, loss_mask) if use]
print('Masked mean loss:', round(sum(selected) / len(selected), 4))
assert len(selected) == 2

Keep a genuinely independent check

The deterministic hash split makes grouping reproducible, but does not guarantee category balance. Inspect counts and adjust the dataset construction process if a rare category disappears from evaluation. Do not keep changing the split until the model looks good. For time-dependent use cases, a chronological holdout can reveal changes that a random split misses.

Store dataset version, group identifiers, label policy, and exclusion reasons in a manifest. Keep sensitive text out of casual experiment logs. When reporting results, distinguish a synthetic smoke test from a representative benchmark. If the final holdout influences prompt or hyperparameter choices, retire it as a final test and obtain another independent evaluation set before claiming generalization.

Build a grouped split manifest

  • Create twelve synthetic conversations, with two paraphrases each and three support categories.
  • Assign all paraphrases of one conversation to the same split and list category counts.
  • Write a response-only loss-mask example and separately document how padding would be handled.

Expected checks

  • No conversation identifier appears in both splits.
  • All evaluated categories have examples or an explicit coverage limitation.
  • The explanation distinguishes loss masking from removing input context and from attention masking.

Check your understanding

Why should paraphrases from the same conversation stay together?

  • To prevent closely related content leaking across the evaluation boundary
  • To guarantee equal category frequencies
  • To make the loss exactly zero
Answer explanation

Grouped splitting protects independence; category balance and learning quality still need separate checks.

Official tools & further reading

The curriculum

  1. From Tokens to Context — Free preview

    Use a tiny attention calculation to distinguish model representations from understanding, memory, and truth.

  2. Datasets That Can Disagree With You — Free preview

    Split related examples together, define loss targets deliberately, and prevent evaluation leakage.

  3. Adapt With a Measured Budget — Sign-in access

    Understand low-rank updates and quantization costs before choosing optional hardware-heavy experiments.

  4. Make Baselines Hard to Beat — Sign-in access

    Compare candidates using category-level errors, abstentions, and a frozen evaluation protocol.

  5. Proposals Before Actions — Free preview

    Keep model-generated suggestions separate from authorized tool execution and durable workflow state.

  6. Latency Has Components — Sign-in access

    Measure request stages and design caches that respect versions, identity, and changing access rules.

  7. Observe Without Exposing — Sign-in access

    Use telemetry and rollout gates to detect failures while limiting unnecessary collection of user content.

  8. Release Signal Bench — Sign-in access

    Integrate the offline classifier, review workflow, measurements, and compatible rollback into a demonstrable capstone.