All lessons in Vision-Language Models: Build, Evaluate, and Adapt
Build a Visual Test Collection
Generate original images and validate their provenance and split membership.
55 minutes · Free lesson
What you will learn
- Generate and inspect an original image-question collection with explicit ground truth.
- Validate hashes, dimensions, source groups, and split assignments before inference.
- Distinguish a reproducible synthetic fixture from evidence of field performance.
A model demo is easy to repeat when you keep choosing images on which it succeeds. An engineering comparison needs a collection whose answers and selection procedure are inspectable. You will create that collection before running a model so that failures remain visible instead of disappearing from the demo folder.
The workbook generates simple colored squares and circles. Their simplicity is deliberate: if a model fails a relation or invents a triangle, you can inspect the exact input. The fixtures are original synthetic drawings. They do not establish how a system behaves on photographs, overlapping objects, handwriting, or unfamiliar acquisition conditions.
Prepare an isolated working environment
Download the VLM workbook and extract it. Run the following commands from the extracted vision-language-models-labs directory. Use Python 3.12, which is the tested interpreter family. The full dependency installation includes pretrained-model libraries; later commands retrieve model weights separately.
Run
python3.12 -m venv .venvto create a local environment.Run
source .venv/bin/activatein bash or zsh. On Windows PowerShell, use.venv\Scripts\Activate.ps1.Run
python -m pip install -r requirements.txtto install the pinned direct dependencies.Run
python -m unittest discover -s tests -vto check fixture generation, geometry, evaluation, and failure handling.Run
python fixtures.py --out .work/datato create the collection.
Do not reuse an output directory that already contains experiment evidence. The generator refuses to overwrite one. Use a new directory for a changed experiment and record why it differs. Dependency installation needs internet; generation and the default tests do not download data or model weights.
Inspect the records before using them
The collection contains 12 source groups, two layout variants per group, and four questions per image. That produces 24 images and 96 image-question cases. Groups 0–5 are training, 6–8 are validation, and 9–11 are final test. Each source group's related views stay in the same split.
Open several PNGs in an image viewer. Then inspect manifest.json in a text editor. Each case binds an opaque ID, image filename, SHA-256 hash, dimensions, source group, split, task, question, reference answer, and candidate descriptions for the retrieval baseline. The inference engine receives the question and candidates, never the reference answer.
The color question identifies the square rather than the leftmost object. In one layout the square is left of the circle; in the other it is right. This creates a small relation control while retaining the objects and colors. The presence questions include a square that is present and a triangle that is absent. Those particular choices are not an exhaustive hallucination test.
Worked example
Count the independent units in the collection
- There are 12 generated source groups and two views in each group: 12 × 2 = 24 images.
- Each image has four questions: 24 × 4 = 96 cases. Questions sharing an image are not 96 independent scenes.
- Training uses six groups: 6 × 2 × 4 = 48 cases. Validation uses three groups and 24 cases. Final test uses three groups and 24 cases.
- A validation score of 18 correct out of 24 is 75% case accuracy. It is based on only three source groups, so treating all 24 cases as independent field observations would overstate the evidence.
- All groups use the same simple generator family. Group separation prevents a specific within-collection leak; it does not create a new real-world acquisition distribution.
Validate content identity and grouping
The supplied loader checks that case IDs are unique, image bytes match their hashes, decoded dimensions match the manifest, source groups stay in one split, and exact duplicate image hashes do not cross splits. It rejects relative paths that escape the dataset directory. These checks catch several ways a comparison can silently change its inputs.
Run python run.py --data .work/data/manifest.json --out .work/rule-validation.json --engine rule. This executes the narrow pixel baseline and validates the collection as it loads. Then run python evaluate.py --data .work/data/manifest.json --predictions .work/rule-validation.json --out .work/rule-validation-report.json.
Read the slice report, not just the top-level score. The rule recognizes the generator's square and circle geometry. It deliberately returns unknown for triangle detection because that detector is not implemented. Its supported scope is visible in the result. Filling in no merely because the current generator never draws a triangle would bake the answer distribution into the supposed detector.
Break one assumption and observe the rejection
Copy the manifest to a new file in the same directory, then edit a source-group assignment so a group spans training and validation. Running the rule with that manifest should fail before inference. Restore by using the untouched original manifest; do not suppress the loader check.
For another investigation, copy the entire collection to a separate directory and alter one PNG without updating its recorded hash. Loading that collection must reject the mismatch. A new hash can document an intended new image version, but it cannot prove that its reference answer remains correct. Reinspect and relabel any meaning-changing edit.
Our manifest includes reference labels because the exercises must be self-checkable. Final evaluation is a procedural separation, not a security boundary: do not inspect final labels or use final responses to tune your candidate. Once a result influences a change, that split has become development evidence.
Produce the first project artifact
Keep a short fixture report with the generator version, case counts, group assignment, image hashes, inspected examples, and known coverage gaps. Add evidence from one rejected invalid manifest and the baseline report. Do not include an unsupported claim that a passing software check validates a real inspection workflow.
The lab budget includes environment setup, image inspection, a baseline run, two failure investigations, and report writing. A successful generator exit is only the beginning. You must be able to explain why each question is answerable from its image and which conditions the collection never tests.
Exercise
A developer randomly splits the 96 questions into training and test. Why can that leak visual information even when case IDs are unique, and what assignment unit should replace it?
Check your answer
Different questions about the same image, and related views of the same source group, can land in both sets. Unique question IDs do not make their visual information independent. Assign whole source groups to one split before expanding views and questions.
Exercise
The baseline answers square-color, square-left, and square-present correctly on every validation image and returns unknown for triangle-present. Calculate its overall exact accuracy and coverage. Does this establish reliable absence detection?
Check your answer
There are six validation images and four questions per image. Eighteen answers are correct and six are unknown, so exact accuracy and answer coverage are both 18 ÷ 24 = 75%. It establishes no triangle absence-detection capability because that task was not answered.
Exercise
You compress a PNG through another tool and obtain a new hash while the visible scene seems unchanged. What must you record before comparing the new candidate with the prior run?
Check your answer
Retain the original and new bytes, inspect decoded dimensions and pixels, document the transformation, and verify the references still apply. Record a new dataset identity. For a fair model comparison, run both candidates on the same selected version; a changed file hash alone cannot distinguish harmless re-encoding from a meaning-changing edit.
Sources and further reading
The Idefics2 study illustrates why controlled visual preprocessing matters. Winoground motivates relation-sensitive comparisons. The workbook fixtures, validation rules, and questions are original and do not redistribute either benchmark.
Summary
Build inspectable inputs before judging a model. Bind cases to source groups and image hashes, preserve unknowns, and deliberately exercise rejection paths. Synthetic controls support mechanism-level claims; real deployment needs additional acquisition and task evidence.
Next action
Calculate how image size becomes patches and model context, then use the same fixtures to compare a pretrained image–text encoder with the pixel baseline.