# 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](https://huggingface.co/docs/datasets/en/about_cache) · [Recorded results](https://sapien1.com/research/check-dataset-map-lookup-cache-evidence/observations.json)

## 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**

| Call | Label for case A | Label for case B |
| --- | ---: | ---: |
| Default before edit | `0` | `1` |
| Default after edit | `0` | `1` |
| After edit with `load_from_cache_file=False` | `1` | `0` |
| Default after forced run | `1` | `0` |
| Separate test with the updated labels passed directly | `1` | `0` |

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](https://github.com/huggingface/datasets/blob/a015b2fa5c1a6cda677fa46f20a54773258553ac/src/datasets/arrow_dataset.py#L3429-L3468)

## 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](https://huggingface.co/docs/datasets/en/cache)

## Repeat the two-case check

Save the [replay script](https://sapien1.com/research/check-dataset-map-lookup-cache-evidence/replay.py) and its [dependency lockfile](https://sapien1.com/research/check-dataset-map-lookup-cache-evidence/replay.py.lock) 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](https://sapien1.com/research/check-dataset-map-lookup-cache-evidence/observations.json).

## Related research

- [We asked for one coding test. The software opened a newer one.](https://sapien1.com/research/check-humaneval-plus-files)
- [How a database backup paired a new score with an old limit](https://sapien1.com/research/check-sqlite-dump-snapshots)

[Files and record IDs](https://sapien1.com/research#files)
