Add files via upload
This commit is contained in:
parent
0978bb2f1d
commit
1284bb346b
238 changed files with 13931 additions and 3 deletions
34
easyjailbreak/selector/RandomSelector.py
Normal file
34
easyjailbreak/selector/RandomSelector.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
"""
|
||||
RandomSelectPolicy class
|
||||
============================
|
||||
"""
|
||||
import random
|
||||
from easyjailbreak.selector import SelectPolicy
|
||||
from easyjailbreak.datasets import JailbreakDataset
|
||||
|
||||
__all__ = ["RandomSelectPolicy"]
|
||||
|
||||
class RandomSelectPolicy(SelectPolicy):
|
||||
"""
|
||||
A selection policy that randomly selects an instance from a JailbreakDataset.
|
||||
It extends the SelectPolicy abstract base class, providing a concrete implementation
|
||||
for the random selection strategy.
|
||||
"""
|
||||
|
||||
def __init__(self, Datasets: JailbreakDataset):
|
||||
"""
|
||||
Initializes the RandomSelectPolicy with a given JailbreakDataset.
|
||||
|
||||
:param ~JailbreakDataset Datasets: The dataset from which instances will be randomly selected.
|
||||
"""
|
||||
super().__init__(Datasets)
|
||||
|
||||
def select(self) -> JailbreakDataset:
|
||||
"""
|
||||
Selects an instance randomly from the dataset and increments its visited count.
|
||||
|
||||
:return ~JailbreakDataset: The randomly selected instance from the dataset.
|
||||
"""
|
||||
seed = random.choice(self.Datasets._dataset)
|
||||
seed.visited_num += 1
|
||||
return JailbreakDataset([seed])
|
||||
Loading…
Add table
Add a link
Reference in a new issue