MCPcopy Create free account
hub / github.com/bruno686/VisPlay / WatermarkingConfig

Class WatermarkingConfig

configuration_utils.py:1423–1497  ·  view source on GitHub ↗

Class that holds arguments for watermark generation and should be passed into `GenerationConfig` during `generate`. See [this paper](https://arxiv.org/abs/2306.04634) for more details on the arguments. Accepts the following keys: - greenlist_ratio (`float`): Used fo

Source from the content-addressed store, hash-verified

1421
1422@dataclass
1423class WatermarkingConfig(BaseWatermarkingConfig):
1424 """
1425 Class that holds arguments for watermark generation and should be passed into `GenerationConfig` during `generate`.
1426 See [this paper](https://arxiv.org/abs/2306.04634) for more details on the arguments.
1427
1428 Accepts the following keys:
1429 - greenlist_ratio (`float`):
1430 Used for watermarking. The ratio of "green" tokens used to the vocabulary size. Defaults to 0.25.
1431 - bias (`float`):
1432 Used with watermarking. The bias added to the selected "green" tokens' logits. Defaults to 2.0.
1433 - hashing_key (`int`):
1434 Hashing key used for watermarking. Defaults to 15485863 (the millionth prime).
1435 - seeding_scheme (`str`):
1436 Algorithm to use for watermarking. Accepts values:
1437 - "lefthash" (default): "green" tokens selection depend on the last token (Algorithm 2 from the paper)
1438 - "selfhash": "green" tokens selection depends on the current token itself (Algorithm 3 from the paper)
1439 The downside of this scheme is that it considers all possible next tokens and can be slower than "lefthash".
1440 - context_width(`int`):
1441 The context length of previous tokens to use in seeding. Higher context length makes watermarking more robust.
1442 """
1443
1444 def __init__(
1445 self,
1446 greenlist_ratio: Optional[float] = 0.25,
1447 bias: Optional[float] = 2.0,
1448 hashing_key: Optional[int] = 15485863,
1449 seeding_scheme: Optional[str] = "lefthash",
1450 context_width: Optional[int] = 1,
1451 ):
1452 self.greenlist_ratio = greenlist_ratio
1453 self.bias = bias
1454 self.hashing_key = hashing_key
1455 self.seeding_scheme = seeding_scheme
1456 self.context_width = context_width
1457
1458 def validate(self):
1459 watermark_missing_arg_msg = (
1460 "Some of the keys in `watermarking_config` are defined incorrectly. `{key}` should be {correct_value}` "
1461 "but found {found_value}"
1462 )
1463 if self.seeding_scheme not in ["selfhash", "lefthash"]:
1464 raise ValueError(
1465 watermark_missing_arg_msg.format(
1466 key="seeding_scheme",
1467 correct_value="[`selfhash`, `lefthash`]",
1468 found_value=self.seeding_scheme,
1469 ),
1470 )
1471 if not 0.0 <= self.greenlist_ratio <= 1.0:
1472 raise ValueError(
1473 watermark_missing_arg_msg.format(
1474 key="greenlist_ratio",
1475 correct_value="in range between 0.0 and 1.0",
1476 found_value=self.seeding_scheme,
1477 ),
1478 )
1479 if not self.context_width >= 1:
1480 raise ValueError(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected