Prompt Engineering
Use this sub-skill when an agent needs to turn class labels into CLIP text prompts, tokenize them safely, build zero-shot classifier weights, or diagnose prompt/template failures.
Route
- Start with
references/prompting-workflows.md for class taxonomies, template design, prompt ensembling, normalized text features, and top-k zero-shot scoring.
- Use
references/tokenization.md before generating large prompt sets or when clip.tokenize raises context-length errors.
- Use
references/troubleshooting.md for unsafe category design, malformed templates, device mismatches, unnormalized features, and multilingual/English limitations.
- Use
scripts/build_zeroshot_classifier.py when you need a reusable helper for expanding templates, dry-run tokenization, or building normalized classifier weights from a loaded CLIP model.
Boundaries
- Model selection,
clip.load, image preprocessing, and image-text inference setup belong in ../model-loading-inference/.
- Linear probes, cached image feature evaluation, and dataset-scale benchmark loops belong in
../feature-evaluation/.
- Dataset downloads mentioned in source docs are reference-only; do not make prompt workflows depend on downloading raw datasets by default.
Minimal Safe Flow
- Define a fixed English class taxonomy with non-overlapping labels and avoid sensitive or deployment-risk categories unless the user explicitly asks for a research-only audit.
- Choose templates containing exactly one
{} placeholder, such as a photo of a {}. or domain-specific variants like a photo of a {}, a type of bird.
- Dry-run tokenize the expanded prompts with
clip.tokenize(..., context_length=77, truncate=False) before running model inference.
- Encode prompt batches with a loaded CLIP model, normalize every prompt embedding, average templates per class, normalize the averaged class vector, then stack weights as
[text_feature_dim, num_classes].
- For image classification, normalize image features and compute
100.0 * image_features @ zeroshot_weights; treat softmax/top-k scores as relative to the candidate class list, not calibrated real-world confidence.
Helper Script
Dry-run prompt tokenization without loading or downloading model checkpoints:
python sub-skills/prompt-engineering/scripts/build_zeroshot_classifier.py \
--class-name cat --class-name "electric ray" \
--template "a photo of a {}." \
--dry-run-tokenize
Build classifier weights only when a model load is explicitly requested or a caller imports build_zeroshot_classifier(model, class_names, templates) with an already loaded model. See references/prompting-workflows.md for the importable contract.
1---2name: prompt-engineering3description: "Build CLIP zero-shot class prompts, tokenizer-safe templates, and4 normalized text classifier weights."5disable-model-invocation: true6metadata:7 source: https://skillmd.com/skills/vectorspacelab/prompt-engineering8 disco-role: operating9license: MIT10---1112# Prompt Engineering1314Use this sub-skill when an agent needs to turn class labels into CLIP text prompts, tokenize them safely, build zero-shot classifier weights, or diagnose prompt/template failures.1516## Route1718- Start with `references/prompting-workflows.md` for class taxonomies, template design, prompt ensembling, normalized text features, and top-k zero-shot scoring.19- Use `references/tokenization.md` before generating large prompt sets or when `clip.tokenize` raises context-length errors.20- Use `references/troubleshooting.md` for unsafe category design, malformed templates, device mismatches, unnormalized features, and multilingual/English limitations.21- Use `scripts/build_zeroshot_classifier.py` when you need a reusable helper for expanding templates, dry-run tokenization, or building normalized classifier weights from a loaded CLIP model.2223## Boundaries2425- Model selection, `clip.load`, image preprocessing, and image-text inference setup belong in `../model-loading-inference/`.26- Linear probes, cached image feature evaluation, and dataset-scale benchmark loops belong in `../feature-evaluation/`.27- Dataset downloads mentioned in source docs are reference-only; do not make prompt workflows depend on downloading raw datasets by default.2829## Minimal Safe Flow30311. Define a fixed English class taxonomy with non-overlapping labels and avoid sensitive or deployment-risk categories unless the user explicitly asks for a research-only audit.322. Choose templates containing exactly one `{}` placeholder, such as `a photo of a {}.` or domain-specific variants like `a photo of a {}, a type of bird.`333. Dry-run tokenize the expanded prompts with `clip.tokenize(..., context_length=77, truncate=False)` before running model inference.344. Encode prompt batches with a loaded CLIP model, normalize every prompt embedding, average templates per class, normalize the averaged class vector, then stack weights as `[text_feature_dim, num_classes]`.355. For image classification, normalize image features and compute `100.0 * image_features @ zeroshot_weights`; treat softmax/top-k scores as relative to the candidate class list, not calibrated real-world confidence.3637## Helper Script3839Dry-run prompt tokenization without loading or downloading model checkpoints:4041```bash42python sub-skills/prompt-engineering/scripts/build_zeroshot_classifier.py \43 --class-name cat --class-name "electric ray" \44 --template "a photo of a {}." \45 --dry-run-tokenize46```4748Build classifier weights only when a model load is explicitly requested or a caller imports `build_zeroshot_classifier(model, class_names, templates)` with an already loaded model. See `references/prompting-workflows.md` for the importable contract.