Skip to main content

We changed two labels. Why did the software give the old ones back?

Two cases, A and B, get their labels from a file. A starts with label 0 and B with label 1. We swap the labels, save the file in the same place and ask the program to label the cases again. Back come 0 for A and 1 for B.

Hugging Face Datasets can save the result of earlier work so it doesn’t have to do the work twice. That saved result is called a cache. In version 4.8.5, passing along the same filename let the program reuse the old results even after the answers inside the file had changed.

The operation we tested, Dataset.map, applies a function to the cases in a dataset. Our function, the piece of code that assigned the labels, received the location of a lookup file and read the label next to each case ID. The edited file held new answers. From the outside, though, the function was still getting exactly the same argument: the path to that file. Cache documentation · Recorded results

Which call picked up the edit?

We saved a dataset containing A and B, opened it again and ran the function. The first run saved its result under an automatically generated name. An ordinary or ‘default’ call could reuse that result. A forced call would run the lookup again. Then we changed only the JSON lookup file, swapping the labels to A = 1 and B = 0. The first four rows follow calls that gave the function the same path. The last row comes from a separate comparison in which we handed the function the actual labels.

Labels returned for A and B before the edit, after it and after a forced run
CallLabel for case ALabel for case B
Default before edit01
Default after edit01
After edit with load_from_cache_file=False10
Default after forced run10
Separate test with the updated labels passed directly10

The first ordinary call after the edit brought back the old A and B. The program reused the same cache file. Even its contents, checked byte for byte, hadn’t changed. We then forced the function to run. It wrote new results at the same cache location, so the next ordinary call returned the new A and B too.

What would tell the software that these were different jobs? To generate the default cache filename in this disk-backed test, it combines a fingerprint (an identifying marker) of the input dataset with information about the function and its arguments. Giving it the same path left that information unchanged. In the separate test, we read the lookup file first and passed the labels themselves to the function. The original mapping gave A = 0 and B = 1. The edited mapping gave A = 1 and B = 0. They produced different fingerprints and different cache files. Dataset.map implementation tested

When the labels have to change with the file

For a small lookup, read it first and pass the resulting mapping through fn_kwargs, the arguments to the function. Save the lookup’s revision or checksum (an identifier calculated from its contents) with the labeled data so someone can identify which answers you used.

For a one-time refresh, load_from_cache_file=False tells the program to run the function again. Verify the labels it returns. If both versions need to survive, use fixed revisions of the lookup and save each processed dataset separately. Cache management guide

Repeat the two-case check

Save the replay script and its dependency lockfile in the same folder. With Python 3.12.15 and the Python environment tool uv, run uv run --no-project --locked replay.py. The script creates the cases and lookup files on your computer. Compare the JSON it prints with the saved two-case results.