waterfall 0.1.4__py3-none-any.whl → 0.1.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- waterfall/watermark.py +11 -6
- {waterfall-0.1.4.dist-info → waterfall-0.1.6.dist-info}/METADATA +2 -2
- {waterfall-0.1.4.dist-info → waterfall-0.1.6.dist-info}/RECORD +6 -6
- {waterfall-0.1.4.dist-info → waterfall-0.1.6.dist-info}/WHEEL +0 -0
- {waterfall-0.1.4.dist-info → waterfall-0.1.6.dist-info}/entry_points.txt +0 -0
- {waterfall-0.1.4.dist-info → waterfall-0.1.6.dist-info}/licenses/LICENSE +0 -0
waterfall/watermark.py
CHANGED
|
@@ -3,6 +3,7 @@ import logging
|
|
|
3
3
|
import os
|
|
4
4
|
import gc
|
|
5
5
|
import torch
|
|
6
|
+
import numpy as np
|
|
6
7
|
from typing import List, Literal, Optional, Tuple
|
|
7
8
|
|
|
8
9
|
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
@@ -81,8 +82,9 @@ def watermark(
|
|
|
81
82
|
def verify_texts(texts: List[str], id: int,
|
|
82
83
|
watermarker: Optional[Watermarker] = None,
|
|
83
84
|
k_p: Optional[int] = None,
|
|
84
|
-
model_path: Optional[str] = "meta-llama/Llama-3.1-8B-Instruct"
|
|
85
|
-
|
|
85
|
+
model_path: Optional[str] = "meta-llama/Llama-3.1-8B-Instruct",
|
|
86
|
+
return_extracted_k_p: bool = False
|
|
87
|
+
) -> np.ndarray | Tuple[np.ndarray,np.ndarray]:
|
|
86
88
|
"""Returns the q_score and extracted k_p"""
|
|
87
89
|
|
|
88
90
|
if watermarker is None:
|
|
@@ -93,7 +95,11 @@ def verify_texts(texts: List[str], id: int,
|
|
|
93
95
|
if k_p is None:
|
|
94
96
|
k_p = watermarker.k_p
|
|
95
97
|
|
|
96
|
-
verify_results = watermarker.verify(texts, id=[id], k_p=[k_p], return_extracted_k_p=
|
|
98
|
+
verify_results = watermarker.verify(texts, id=[id], k_p=[k_p], return_extracted_k_p=return_extracted_k_p) # results are [text x id x k_p]
|
|
99
|
+
|
|
100
|
+
if not return_extracted_k_p:
|
|
101
|
+
return verify_results[:,0,0]
|
|
102
|
+
|
|
97
103
|
q_score = verify_results["q_score"]
|
|
98
104
|
k_p_extracted = verify_results["k_p_extracted"]
|
|
99
105
|
|
|
@@ -161,13 +167,12 @@ def watermark_texts(
|
|
|
161
167
|
|
|
162
168
|
if isinstance(waterfall_cached_watermarking_model, PreTrainedModel) and waterfall_cached_watermarking_model.name_or_path != model_path:
|
|
163
169
|
device = waterfall_cached_watermarking_model.device.type
|
|
164
|
-
|
|
170
|
+
waterfall_cached_watermarking_model = None
|
|
165
171
|
gc.collect()
|
|
166
172
|
if device == "cuda":
|
|
167
173
|
torch.cuda.empty_cache()
|
|
168
174
|
elif device == "mps":
|
|
169
175
|
torch.mps.empty_cache()
|
|
170
|
-
waterfall_cached_watermarking_model = None
|
|
171
176
|
|
|
172
177
|
if waterfall_cached_watermarking_model is None:
|
|
173
178
|
waterfall_cached_watermarking_model = AutoModelForCausalLM.from_pretrained(
|
|
@@ -308,7 +313,7 @@ def main():
|
|
|
308
313
|
)
|
|
309
314
|
|
|
310
315
|
# watermarker = Watermarker(tokenizer=tokenizer, model=None, id=id, k_p=k_p, watermarkingFnClass=watermarkingFnClass) # If only verifying the watermark, do not need to instantiate the model
|
|
311
|
-
q_scores, extracted_k_ps = verify_texts(T_os + T_ws, id, watermarker, k_p=k_p)
|
|
316
|
+
q_scores, extracted_k_ps = verify_texts(T_os + T_ws, id, watermarker, k_p=k_p, return_extracted_k_p=True)
|
|
312
317
|
|
|
313
318
|
for i in range(len(T_os)):
|
|
314
319
|
# Handle the case where this is being run
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: waterfall
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Summary: Scalable Framework for Robust Text Watermarking and Provenance for LLMs
|
|
5
5
|
Project-URL: Homepage, https://github.com/aoi3142/Waterfall
|
|
6
6
|
Project-URL: Issues, https://github.com/aoi3142/Waterfall/issues
|
|
@@ -141,7 +141,7 @@ from waterfall.watermark import verify_texts
|
|
|
141
141
|
id = 1 # specify your watermarking ID
|
|
142
142
|
test_texts = ["...", "..."] # Suspected texts to verify
|
|
143
143
|
|
|
144
|
-
watermark_strength = verify_texts(test_texts, id)
|
|
144
|
+
watermark_strength = verify_texts(test_texts, id) # np array of floats
|
|
145
145
|
```
|
|
146
146
|
|
|
147
147
|
## Code structure
|
|
@@ -4,9 +4,9 @@ waterfall/WatermarkingFnFourier.py,sha256=QYayAQYwi1dQkDIyqmvhU568VhrVYTVy47HkI8
|
|
|
4
4
|
waterfall/WatermarkingFnSquare.py,sha256=2PAO05DdKT02npo7GDf_82D520nP7kGAWK6H4E4JMt4,1638
|
|
5
5
|
waterfall/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
6
|
waterfall/permute.py,sha256=RwxOHFhx_VSOhhFwy5s79YgwTUBkfW2-LCCXYR3VT2o,2582
|
|
7
|
-
waterfall/watermark.py,sha256=
|
|
8
|
-
waterfall-0.1.
|
|
9
|
-
waterfall-0.1.
|
|
10
|
-
waterfall-0.1.
|
|
11
|
-
waterfall-0.1.
|
|
12
|
-
waterfall-0.1.
|
|
7
|
+
waterfall/watermark.py,sha256=W5jYGqYGOXXO-KLPKzJoin5zC_Xb6Xk9BzsAA9-LKXA,13494
|
|
8
|
+
waterfall-0.1.6.dist-info/METADATA,sha256=inB0EWGyaAkNQo4CUSke5Bh4Vr07AuVPU9jmKB0gU3U,8714
|
|
9
|
+
waterfall-0.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
10
|
+
waterfall-0.1.6.dist-info/entry_points.txt,sha256=XXnUzuWXu2nc9j4WAll9tq6HyodN_8WJLjeG0O4Y2Gw,60
|
|
11
|
+
waterfall-0.1.6.dist-info/licenses/LICENSE,sha256=zAtaO-k41Q-Q4Etl4bzuh7pgNJsPH-dYfzvznRa0OvM,11341
|
|
12
|
+
waterfall-0.1.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|