Skip to content

[BUG] data_polluting may keep selected labels unchanged in data hyper-cleaning example #75

Description

@JTFDSD

Required prerequisites

What version of BOAT are you using?

1.0.2

System information

  • OS: Windows 10
  • Python: 3.10.20
  • torch: 2.11.0+cpu
  • torchvision: 0.26.0+cpu
  • boat-torch: 1.0.2, editable install from main source ZIP
  • higher: 0.2.1
  • CUDA: not used in this run

Problem description

I was running the data hyper-cleaning example and checking how the training labels are polluted before BOAT reweights samples. The example calls tr.data_polluting(0.5), so I expected the selected samples to have labels different from their original clean labels.

Some selected labels can remain unchanged. The likely cause is that dirty_set is built correctly, but the assignment samples an integer range instead of sampling from dirty_set.

Reproducible example code

import random
import torch
from examples.data_hyper_cleaning.util_file import Dataset

random.seed(7)
data = torch.arange(100 * 2 * 2).reshape(100, 2, 2)
target = torch.tensor([i % 10 for i in range(100)])
dataset = Dataset(data, target)
dataset.data_polluting(1.0)

unchanged = (dataset.dirty_target == dataset.clean_target).nonzero(as_tuple=False).flatten()
print(len(unchanged), "/", len(target))
print(unchanged[:10].tolist())

Traceback / error log

No traceback. The issue is a behavioral mismatch.
Unchanged labels after data_polluting: 7 / 100
First unchanged indices: [13, 39, 52, 63, 92, 97, 98]
Clean labels at those indices: [3, 9, 2, 3, 2, 7, 8]
Dirty labels at those indices: [3, 9, 2, 3, 2, 7, 8]

Expected behavior

When a sample is selected for pollution, its dirty label should be sampled from the label set excluding the original label. With rho=1.0, every selected dirty label should be different from its clean label.

Additional context

The likely cause is this line in examples/data_hyper_cleaning/util_file.py:

self.dirty_target[i] = random.randint(0, len(dirty_set))

dirty_set excludes the original label, but random.randint samples from an integer range instead of the filtered set. A possible fix is:

self.dirty_target[i] = random.choice(list(dirty_set))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions