Skip to content

Commit 4c5b8dc

Browse files
authored
Merge pull request #819 from liuyuyan2717/fix-issue-791
Fix #791: HuggingFaceDataset doesn't shuffle the dataset
2 parents 8219b05 + e311c75 commit 4c5b8dc

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

textattack/datasets/huggingface_dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def __init__(
149149

150150
self.shuffled = shuffle
151151
if shuffle:
152-
self._dataset.shuffle()
152+
self._dataset = self._dataset.shuffle()
153153

154154
def _format_as_dict(self, example):
155155
input_dict = collections.OrderedDict(
@@ -190,5 +190,5 @@ def __getitem__(self, i):
190190
]
191191

192192
def shuffle(self):
193-
self._dataset.shuffle()
193+
self._dataset = self._dataset.shuffle()
194194
self.shuffled = True

textattack/transformations/word_swaps/word_swap_change_number.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _alter_number(self, num):
104104
"""Helper function of _get_new_number, replace a number with another
105105
random number within the range of self.max_change."""
106106
if num not in [0, 2, 4]:
107-
change = int(num * self.max_change) + 1
107+
change = abs(int(num * self.max_change)) + 1
108108
if num >= 0:
109109
num_list = np.random.randint(max(num - change, 1), num + change, self.n)
110110
else:

0 commit comments

Comments
 (0)