MetaCyberGuru Academy
A pretrained pipeline is useful only when its training objective, labels and input contract match the decision you need to make.
Learning outcomes
- Translate a product request into one defined NLP task.
- Run classification and extractive question-answering pipelines with explicit checkpoints.
- Select an evaluation and fallback that fit each output contract.
Set a task before choosing a checkpoint
“Use a transformer” is not a task definition. Start with an input, an output and a failure cost. A support team might need one label per message, entities with character spans, an answer copied from a supplied passage, a shorter version of a document or a translation into a named language. Those are different contracts and require different evaluations.
| Task | Returned evidence | First useful metric |
|---|---|---|
| Classification | Label and score | Macro F1 plus confusion matrix |
| Named entity recognition | Entity type and text span | Entity-level precision, recall and F1 |
| Extractive question answering | Answer span from context | Exact match and token F1 |
| Summarization | Generated shorter text | Human factuality and coverage rubric |
| Translation | Generated target-language text | Fluent human review plus a corpus metric |
Read the model card before downloading a checkpoint. Check languages, labels, licence, base architecture, training data notes and known limitations. A high score on an unrelated benchmark does not establish fitness for your users.
Run two different task contracts
Create pipeline_contracts.py. The script uses explicit revisions where a production project should pin an immutable commit. Model downloads require an internet connection and several hundred megabytes of disk space.
python -m pip install "transformers>=4.45" torch
python pipeline_contracts.py# pipeline_contracts.py
from transformers import pipeline
classifier = pipeline(
"text-classification",
model="distilbert/distilbert-base-uncased-finetuned-sst-2-english",
)
qa = pipeline(
"question-answering",
model="distilbert/distilbert-base-cased-distilled-squad",
)
review = "The update is useful, but installation took too long."
policy = "Refund requests are accepted within 14 days of purchase."
classification = classifier(review, truncation=True)[0]
answer = qa(question="How long is the refund window?", context=policy)
assert set(classification) == {"label", "score"}
assert {"answer", "score", "start", "end"}.issubset(answer)
assert policy:answer["end"]] == answer["answer"]
print("classification", classification)
print("answer", answer["answer"], "span", answer["start"], answer["end"])What the output establishes
The classifier returns a task-specific label, while question answering returns a span tied to the supplied context. Scores are model confidence signals, not calibrated probabilities of correctness. Your numbers may vary with library and model revisions. The assertions check the result shape and the extractive span, not product quality.
Use a selection brief
Before a larger experiment, write five lines: user input, required output, unacceptable failure, evaluation set and fallback. Then compare a classical baseline, a frozen transformer and any adapted model on the same held-out examples.
- Use classification when labels are closed and stable.
- Use NER when positions and entity types matter.
- Use extractive QA when the answer must be grounded in a supplied passage.
- Use summarization only with factuality review appropriate to the risk.
- Use translation with fluent reviewers for the actual language pair and domain.
Consider latency, memory and batch size as part of model selection. A smaller checkpoint that meets the quality gate can be a better production choice than a larger model that exceeds the response budget.
Debug task mismatch
| Symptom | Investigation |
|---|---|
| Labels have unfamiliar names | Inspect model.config.id2label and the model card. |
| Input disappears | Log token count, truncation and maximum sequence length. |
| QA answers outside evidence | Confirm you chose extractive QA and verify returned offsets. |
| Good demo, poor user data | Build a domain-specific test set and slice it by language and input type. |
Write a five-task selection brief
For classification, NER, QA, summarization and translation, write one realistic use case and one failure that requires human review. Run at least two pipelines on five licensed examples. Save raw results, model IDs, revisions, runtime and peak memory.
Challenge: add a TF-IDF baseline for classification and explain whether the transformer earns its additional cost.
Knowledge check
Official sources and model references
Save your place
Completion is stored only in this browser on this device.
Share this page
Share this page with the people who will use it next.
Discussion
No comments yet. Add the first useful question or observation.
You must log in to post a comment.