Class that holds arguments for watermark generation and should be passed into `GenerationConfig` during `generate`. See [this paper](https://www.nature.com/articles/s41586-024-08025-4) for more details on the arguments. Args: ngram_len (`int`): Ngram length.
| 1499 | |
| 1500 | @dataclass |
| 1501 | class SynthIDTextWatermarkingConfig(BaseWatermarkingConfig): |
| 1502 | """ |
| 1503 | Class that holds arguments for watermark generation and should be passed into `GenerationConfig` during `generate`. |
| 1504 | See [this paper](https://www.nature.com/articles/s41586-024-08025-4) for more details on the arguments. |
| 1505 | |
| 1506 | Args: |
| 1507 | ngram_len (`int`): |
| 1508 | Ngram length. |
| 1509 | keys (`List[int]`): |
| 1510 | A sequence of watermarking keys, one for each depth. |
| 1511 | context_history_size (`int`, *optional*, defaults to 1024): |
| 1512 | Size of the tensor to keep track of seen contexts. |
| 1513 | sampling_table_seed (`int`, *optional*, defaults to 0): |
| 1514 | Random seed to generate the sampling table. |
| 1515 | sampling_table_size (`int`, *optional*, defaults to 65536): |
| 1516 | Size of the sampling table. |
| 1517 | skip_first_ngram_calls (`bool`, *optional*, defaults to `False`): |
| 1518 | Whether to skip first ngram calls. |
| 1519 | debug_mode (`bool`, optional, *optional*, defaults to `False`): |
| 1520 | Logits are modified to uniform one got before watermarking modification is applied. This is to test the |
| 1521 | implementation. |
| 1522 | |
| 1523 | Examples: |
| 1524 | ```python |
| 1525 | >>> from transformers import AutoModelForCausalLM, AutoTokenizer, SynthIDTextWatermarkingConfig |
| 1526 | |
| 1527 | >>> tokenizer = AutoTokenizer.from_pretrained('google/gemma-2-2b', padding_side="left") |
| 1528 | >>> model = AutoModelForCausalLM.from_pretrained('google/gemma-2-2b') |
| 1529 | |
| 1530 | >>> # SynthID Text configuration |
| 1531 | >>> watermarking_config = SynthIDTextWatermarkingConfig( |
| 1532 | ... keys=[654, 400, 836, 123, 340, 443, 597, 160, 57], |
| 1533 | ... ngram_len=5, |
| 1534 | ... ) |
| 1535 | |
| 1536 | >>> # Generation with watermarking |
| 1537 | >>> tokenized_prompts = tokenizer(["Once upon a time, "], return_tensors="pt", padding=True) |
| 1538 | >>> output_sequences = model.generate( |
| 1539 | ... **tokenized_prompts, watermarking_config=watermarking_config, do_sample=True, max_new_tokens=10 |
| 1540 | ... ) |
| 1541 | >>> watermarked_text = tokenizer.batch_decode(output_sequences, skip_special_tokens=True) |
| 1542 | ``` |
| 1543 | """ |
| 1544 | |
| 1545 | def __init__( |
| 1546 | self, |
| 1547 | ngram_len: int, |
| 1548 | keys: List[int], |
| 1549 | context_history_size: int = 1024, |
| 1550 | sampling_table_seed: int = 0, |
| 1551 | sampling_table_size: int = 2**16, |
| 1552 | skip_first_ngram_calls: bool = False, |
| 1553 | debug_mode: bool = False, |
| 1554 | ): |
| 1555 | self.ngram_len = ngram_len |
| 1556 | self.keys = keys |
| 1557 | self.sampling_table_size = sampling_table_size |
| 1558 | self.sampling_table_seed = sampling_table_seed |
nothing calls this directly
no outgoing calls
no test coverage detected