Skip to content

Commit

Permalink
LIT: Avoid equivalent shuffles in Scrambler
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 642683304
  • Loading branch information
RyanMullins authored and LIT team committed Jun 12, 2024
1 parent a59641c commit 0d8c0d9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lit_nlp/components/scrambler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# ==============================================================================
"""Simple scrambling test generator."""

import copy
import random
from typing import Optional

Expand All @@ -30,8 +31,12 @@

def _scramble(val: str) -> str:
words = val.split(' ')
random.shuffle(words)
return ' '.join(words)
shuffled = copy.deepcopy(words)
while True:
random.shuffle(shuffled)
if shuffled != words:
break
return ' '.join(shuffled)


class Scrambler(lit_components.Generator):
Expand Down

0 comments on commit 0d8c0d9

Please sign in to comment.