Upload DPST.py with huggingface_hub
Browse files
DPST.py
CHANGED
|
@@ -245,7 +245,7 @@ class DPST():
|
|
| 245 |
ordered.append(f)
|
| 246 |
return ordered
|
| 247 |
|
| 248 |
-
def privatize(self, texts, epsilon=10, DP=True):
|
| 249 |
results = []
|
| 250 |
for i, t in tqdm(enumerate(texts), total=len(texts)):
|
| 251 |
triples = self.get_triples_ie(t)
|
|
@@ -253,6 +253,9 @@ class DPST():
|
|
| 253 |
results.append(t)
|
| 254 |
continue
|
| 255 |
|
|
|
|
|
|
|
|
|
|
| 256 |
if DP == True:
|
| 257 |
eps = epsilon / len(triples)
|
| 258 |
query_vectors = self.model.encode(triples, task="text-matching", truncate_dim=32, max_length=64)
|
|
@@ -267,6 +270,9 @@ class DPST():
|
|
| 267 |
candidates.append(near)
|
| 268 |
private_triples = [self.exponential(c, eps) for c in candidates]
|
| 269 |
|
|
|
|
|
|
|
|
|
|
| 270 |
final = []
|
| 271 |
for p in private_triples:
|
| 272 |
m = p.split(" | ")
|
|
@@ -289,5 +295,5 @@ class DPST():
|
|
| 289 |
generated = generated.split("Output text: ")[-1].strip().replace("\n", "")
|
| 290 |
generated = generated.split("USER:")[0].strip().replace("\n", "")
|
| 291 |
generated = generated.split("\t")[0].split("ASSISTANT")[0].split("USER")[0].split("###")[0].split("Note:")[0].split("Explanation:")[0].split("```")[0].split("EXPECTED_OUTPUT")[0]
|
| 292 |
-
results.append(generated.strip())
|
| 293 |
return results
|
|
|
|
| 245 |
ordered.append(f)
|
| 246 |
return ordered
|
| 247 |
|
| 248 |
+
def privatize(self, texts, epsilon=10, DP=True, verbose=False):
|
| 249 |
results = []
|
| 250 |
for i, t in tqdm(enumerate(texts), total=len(texts)):
|
| 251 |
triples = self.get_triples_ie(t)
|
|
|
|
| 253 |
results.append(t)
|
| 254 |
continue
|
| 255 |
|
| 256 |
+
if verbose:
|
| 257 |
+
print(f"\n Extracted Triples : {triples}")
|
| 258 |
+
|
| 259 |
if DP == True:
|
| 260 |
eps = epsilon / len(triples)
|
| 261 |
query_vectors = self.model.encode(triples, task="text-matching", truncate_dim=32, max_length=64)
|
|
|
|
| 270 |
candidates.append(near)
|
| 271 |
private_triples = [self.exponential(c, eps) for c in candidates]
|
| 272 |
|
| 273 |
+
if verbose:
|
| 274 |
+
print(f" Private Triples : {private_triples}")
|
| 275 |
+
|
| 276 |
final = []
|
| 277 |
for p in private_triples:
|
| 278 |
m = p.split(" | ")
|
|
|
|
| 295 |
generated = generated.split("Output text: ")[-1].strip().replace("\n", "")
|
| 296 |
generated = generated.split("USER:")[0].strip().replace("\n", "")
|
| 297 |
generated = generated.split("\t")[0].split("ASSISTANT")[0].split("USER")[0].split("###")[0].split("Note:")[0].split("Explanation:")[0].split("```")[0].split("EXPECTED_OUTPUT")[0]
|
| 298 |
+
results.append(generated.strip())
|
| 299 |
return results
|