01

Colour and roasting

Green coffee beans are roasted to develop their flavour and aroma. As roasting continues, the beans darken from light brown to very dark brown. Roasters use colour, along with temperature and time, to judge the roast. Instruments that measure bean colour under controlled light are used in the coffee industry.

02

A model that reads colour

Imagine a computer vision model trained to predict the roast level of beans from photographs. It learns to associate darker beans with darker roasts. This could help roasters check batches quickly, or help shops describe their coffee.

03

Two causes of darkness

A photograph can look dark for two very different reasons. The beans may be darkly roasted, or the image may be underexposed, taken in dim or warm light. A model that only sees pixel colours cannot easily tell the difference unless it is given a way to compare.

04

A neutral reference

One solution is to include a neutral grey or white reference card in every photograph. Because its true colour is known, it shows how the lighting and camera have affected the image. The bean colours can then be corrected, or compared against the reference, making measurements more consistent.

05

A stated light

Labels should describe the visible colour of beans under a specified light source, such as a standard daylight lamp. If photographs are taken under warm lamps, the beans may appear more orange or darker. Recording and controlling the light makes colour labels meaningful.

06

Batches share conditions

Beans from the same roast batch were heated together and share many characteristics: colour, size, shine and even small defects. If some beans from a batch are used for training and others for testing, the model may recognise the batch rather than learn roast colour in general.

07

Hold out whole batches

A more demanding test keeps entire roast batches out of training, using them only for testing. The model then has to judge beans from roasts it has never seen. This better shows whether it will work on new batches in a real roastery.

08

Inflated accuracy

Splitting individual beans from the same batch between training and testing is a form of data leakage. The test results may look excellent, but performance on truly new roasts could be much worse. Grouping data by batch is a simple way to avoid this.

09

Arabica and robusta

Coffee beans come mainly from two species, arabica and robusta, which differ in size, shape and caffeine content. Robusta beans contain roughly twice as much caffeine. A model trained mostly on one type may not judge the other correctly, so the test set should include the varieties it will meet.

10

Responsible testing

The NIST AI Risk Management Framework encourages developers to understand the limits of their systems and to test them on realistic data. For a roast-colour model, that means new batches, different lights and different bean types.

11

Light, medium, dark

Roasters often describe roasts as light, medium or dark. Light roasts keep more of the bean's original flavours, while dark roasts develop bitter, smoky notes and oily surfaces. Shiny oil on dark beans can reflect light in photographs, making them look lighter in places. A model must cope with these reflections too.

12

Cameras and white balance

Cameras adjust colours automatically, which can make the same beans look different from shot to shot.

13

Batch records

Roasters keep records of each batch, which make grouping photographs easy.

14

Try the arithmetic

If a model scores 95 per cent when beans from the same batches appear in training and testing, but 78 per cent on held-out batches, the 17-point gap shows how much leakage inflated the first score.

15

The idea to take away

A dark photograph can come from the roast or the exposure. Use a neutral reference and label colour under a stated light. Hold out whole roast batches, so near-identical beans do not inflate the model's accuracy.

FOLLOW THE EVIDENCE

Sources & further reading

Figures in the example are illustrative. Photograph: Roasted coffee beans.jpg by MarkSweep, Public domain, via Wikimedia Commons; cropped and resized. Reference organisations do not endorse this website.