Spaces:
Runtime error
Runtime error
Antoine Chaffin
commited on
Commit
•
27f0bd3
1
Parent(s):
255310c
Remove prompt
Browse files- watermark.py +2 -19
watermark.py
CHANGED
@@ -8,11 +8,6 @@ from scipy.special import gamma, gammainc, gammaincc, betainc
|
|
8 |
from scipy.optimize import fminbound
|
9 |
import numpy as np
|
10 |
|
11 |
-
|
12 |
-
DEFAULT_SYSTEM_PROMPT = """\
|
13 |
-
You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
|
14 |
-
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.\
|
15 |
-
"""
|
16 |
device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')
|
17 |
|
18 |
def hash_tokens(input_ids: torch.LongTensor, key: int):
|
@@ -144,25 +139,13 @@ class Watermarker(object):
|
|
144 |
return decoded_texts
|
145 |
|
146 |
|
147 |
-
|
148 |
-
def get_prompt(self, message: str) -> str:
|
149 |
-
texts = [f'<s>[INST] <<SYS>>\n{DEFAULT_SYSTEM_PROMPT}\n<</SYS>>\n\n']
|
150 |
-
# The first user input is _not_ stripped
|
151 |
-
texts.append(f'{message} [/INST]')
|
152 |
-
return ''.join(texts)
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
def detect(self, attacked_texts, key=42, method='aaronson', gamma=0.5, prompts=None):
|
157 |
if(prompts==None):
|
158 |
prompts = [""] * len(attacked_texts)
|
159 |
-
else:
|
160 |
-
for i in range(len(prompts)):
|
161 |
-
prompts[i] = self.get_prompt(prompts[i])
|
162 |
-
print(prompts)
|
163 |
generator = self.generator
|
164 |
|
165 |
-
|
|
|
166 |
|
167 |
cdfs = []
|
168 |
ms = []
|
|
|
8 |
from scipy.optimize import fminbound
|
9 |
import numpy as np
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')
|
12 |
|
13 |
def hash_tokens(input_ids: torch.LongTensor, key: int):
|
|
|
139 |
return decoded_texts
|
140 |
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
def detect(self, attacked_texts, key=42, method='aaronson', gamma=0.5, prompts=None):
|
143 |
if(prompts==None):
|
144 |
prompts = [""] * len(attacked_texts)
|
|
|
|
|
|
|
|
|
145 |
generator = self.generator
|
146 |
|
147 |
+
print("attacked_texts = ", attacked_texts)
|
148 |
+
print("prompts = ", prompts")
|
149 |
|
150 |
cdfs = []
|
151 |
ms = []
|