-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutils.py
More file actions
31 lines (25 loc) · 906 Bytes
/
utils.py
File metadata and controls
31 lines (25 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
from language_models import HuggingFace
def insert_adv_string(msg, adv):
return msg + adv
def schedule_n_to_change_prob(max_n_to_change, prob, target_model):
if isinstance(target_model.model, HuggingFace):
if 0 <= prob <= 0.01:
n_to_change = max_n_to_change
elif 0.01 < prob <= 0.1:
n_to_change = max_n_to_change // 2
elif 0.1 < prob <= 1.0:
n_to_change = max_n_to_change // 4
else:
raise ValueError(f'Wrong prob {prob}')
else:
if 0 <= prob <= 0.1:
n_to_change = max_n_to_change
elif 0.1 < prob <= 0.5:
n_to_change = max_n_to_change // 2
elif 0.5 < prob <= 1.0:
n_to_change = max_n_to_change // 4
else:
raise ValueError(f'Wrong prob {prob}')
n_to_change = max(n_to_change, 1)
return n_to_change