Datasets:

Languages:
English
ArXiv:
Tags:
NLP
License:
jdrechsel commited on
Commit
e8fb32a
·
verified ·
1 Parent(s): 0dead75

Upload biasneutral.py

Browse files
Files changed (1) hide show
  1. biasneutral.py +61 -0
biasneutral.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import DatasetInfo, GeneratorBasedBuilder, Split, SplitGenerator, load_dataset, Features, Value
2
+
3
+
4
+ class BiasneutralDataset(GeneratorBasedBuilder):
5
+ """
6
+ This dataset filters entries from BookCorpus based on provided indices in the BIASNEUTRAL dataset.
7
+ """
8
+
9
+ _CITATION = """
10
+ @misc{drechsel2025gradiendmonosemanticfeaturelearning,
11
+ title={{GRADIEND}: Feature Learning within Neural Networks Exemplified through Biases},
12
+ author={Jonathan Drechsel and Steffen Herbold},
13
+ year={2025},
14
+ eprint={2502.01406},
15
+ archivePrefix={arXiv},
16
+ primaryClass={cs.LG},
17
+ url={https://arxiv.org/abs/2502.01406},
18
+ }
19
+ """
20
+
21
+ def _info(self):
22
+ return DatasetInfo(
23
+ description="This dataset consists of BookCorpus entries containing only gender-neutral words (excluding e.g., he, actor, ...).",
24
+ features=Features({
25
+ "index": Value("int32"),
26
+ "text": Value("string"),
27
+ }),
28
+ supervised_keys=None,
29
+ citation=self._CITATION,
30
+ )
31
+
32
+ def _split_generators(self, dl_manager):
33
+ # URL for your indices file hosted on Hugging Face
34
+ index_file_url = "https://huggingface.co/datasets/aieng-lab/biasneutral/resolve/main/indices.csv"
35
+
36
+ # Download the indices file
37
+ indices_file = dl_manager.download_and_extract(index_file_url)
38
+
39
+ # Load BookCorpus dataset
40
+ print("Loading BookCorpus dataset...")
41
+ bookcorpus = load_dataset('bookcorpus', trust_remote_code=True)['train']
42
+ print("BookCorpus dataset loaded.")
43
+
44
+ return [
45
+ SplitGenerator(name=Split.TRAIN, gen_kwargs={"indices_file": indices_file, "bookcorpus": bookcorpus}),
46
+ ]
47
+
48
+ def _generate_examples(self, indices_file: str, bookcorpus):
49
+ """
50
+ Generate examples by filtering the BookCorpus dataset using provided indices.
51
+ """
52
+
53
+ # Load indices from the file
54
+ with open(indices_file, "r", encoding="utf-8") as f:
55
+ next(f) # Skip header
56
+ indices_set = {int(line.strip().split(",")[0]) for line in f}
57
+
58
+ # Filter BookCorpus based on indices and yield examples
59
+ for idx, sample in enumerate(bookcorpus):
60
+ if idx in indices_set:
61
+ yield idx, {"index": idx, "text": sample['text']}