waterfall 0.1.4__py3-none-any.whl → 0.1.5__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 +9 -5
- {waterfall-0.1.4.dist-info → waterfall-0.1.5.dist-info}/METADATA +2 -2
- {waterfall-0.1.4.dist-info → waterfall-0.1.5.dist-info}/RECORD +6 -6
- {waterfall-0.1.4.dist-info → waterfall-0.1.5.dist-info}/WHEEL +0 -0
- {waterfall-0.1.4.dist-info → waterfall-0.1.5.dist-info}/entry_points.txt +0 -0
- {waterfall-0.1.4.dist-info → waterfall-0.1.5.dist-info}/licenses/LICENSE +0 -0
waterfall/watermark.py
CHANGED
|
@@ -81,7 +81,8 @@ def watermark(
|
|
|
81
81
|
def verify_texts(texts: List[str], id: int,
|
|
82
82
|
watermarker: Optional[Watermarker] = None,
|
|
83
83
|
k_p: Optional[int] = None,
|
|
84
|
-
model_path: Optional[str] = "meta-llama/Llama-3.1-8B-Instruct"
|
|
84
|
+
model_path: Optional[str] = "meta-llama/Llama-3.1-8B-Instruct",
|
|
85
|
+
return_extracted_k_p: bool = False
|
|
85
86
|
) -> Tuple[float,float]:
|
|
86
87
|
"""Returns the q_score and extracted k_p"""
|
|
87
88
|
|
|
@@ -93,7 +94,11 @@ def verify_texts(texts: List[str], id: int,
|
|
|
93
94
|
if k_p is None:
|
|
94
95
|
k_p = watermarker.k_p
|
|
95
96
|
|
|
96
|
-
verify_results = watermarker.verify(texts, id=[id], k_p=[k_p], return_extracted_k_p=
|
|
97
|
+
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]
|
|
98
|
+
|
|
99
|
+
if not return_extracted_k_p:
|
|
100
|
+
return verify_results[:,0,0]
|
|
101
|
+
|
|
97
102
|
q_score = verify_results["q_score"]
|
|
98
103
|
k_p_extracted = verify_results["k_p_extracted"]
|
|
99
104
|
|
|
@@ -161,13 +166,12 @@ def watermark_texts(
|
|
|
161
166
|
|
|
162
167
|
if isinstance(waterfall_cached_watermarking_model, PreTrainedModel) and waterfall_cached_watermarking_model.name_or_path != model_path:
|
|
163
168
|
device = waterfall_cached_watermarking_model.device.type
|
|
164
|
-
|
|
169
|
+
waterfall_cached_watermarking_model = None
|
|
165
170
|
gc.collect()
|
|
166
171
|
if device == "cuda":
|
|
167
172
|
torch.cuda.empty_cache()
|
|
168
173
|
elif device == "mps":
|
|
169
174
|
torch.mps.empty_cache()
|
|
170
|
-
waterfall_cached_watermarking_model = None
|
|
171
175
|
|
|
172
176
|
if waterfall_cached_watermarking_model is None:
|
|
173
177
|
waterfall_cached_watermarking_model = AutoModelForCausalLM.from_pretrained(
|
|
@@ -308,7 +312,7 @@ def main():
|
|
|
308
312
|
)
|
|
309
313
|
|
|
310
314
|
# 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)
|
|
315
|
+
q_scores, extracted_k_ps = verify_texts(T_os + T_ws, id, watermarker, k_p=k_p, return_extracted_k_p=True)
|
|
312
316
|
|
|
313
317
|
for i in range(len(T_os)):
|
|
314
318
|
# 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.5
|
|
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=d93C_DjnO2flLHZkRAC_L749CcUjIIGT9yPR91KkjOk,13452
|
|
8
|
+
waterfall-0.1.5.dist-info/METADATA,sha256=aCbjPA6TZwVNcgrX9m0YDsaLcamx7-dayxKkjJmGUcA,8714
|
|
9
|
+
waterfall-0.1.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
10
|
+
waterfall-0.1.5.dist-info/entry_points.txt,sha256=XXnUzuWXu2nc9j4WAll9tq6HyodN_8WJLjeG0O4Y2Gw,60
|
|
11
|
+
waterfall-0.1.5.dist-info/licenses/LICENSE,sha256=zAtaO-k41Q-Q4Etl4bzuh7pgNJsPH-dYfzvznRa0OvM,11341
|
|
12
|
+
waterfall-0.1.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|