SynthID: better example (#34372)
* better example * Update src/transformers/generation/configuration_utils.py * Update src/transformers/generation/logits_process.py * nits
This commit is contained in:
@@ -428,13 +428,11 @@ A [`Constraint`] can be used to force the generation to include specific tokens
|
|||||||
- __call__
|
- __call__
|
||||||
|
|
||||||
[[autodoc]] BayesianDetectorConfig
|
[[autodoc]] BayesianDetectorConfig
|
||||||
- __call__
|
|
||||||
|
|
||||||
[[autodoc]] BayesianDetectorModel
|
[[autodoc]] BayesianDetectorModel
|
||||||
- __call__
|
- forward
|
||||||
|
|
||||||
[[autodoc]] SynthIDTextWatermarkingConfig
|
[[autodoc]] SynthIDTextWatermarkingConfig
|
||||||
- __call__
|
|
||||||
|
|
||||||
[[autodoc]] SynthIDTextWatermarkDetector
|
[[autodoc]] SynthIDTextWatermarkDetector
|
||||||
- __call__
|
- __call__
|
||||||
|
|||||||
@@ -1471,8 +1471,8 @@ class SynthIDTextWatermarkingConfig(BaseWatermarkingConfig):
|
|||||||
```python
|
```python
|
||||||
>>> from transformers import AutoModelForCausalLM, AutoTokenizer, SynthIDTextWatermarkingConfig
|
>>> from transformers import AutoModelForCausalLM, AutoTokenizer, SynthIDTextWatermarkingConfig
|
||||||
|
|
||||||
>>> tokenizer = AutoTokenizer.from_pretrained('google/gemma-2-2b-it')
|
>>> tokenizer = AutoTokenizer.from_pretrained('google/gemma-2-2b', padding_side="left")
|
||||||
>>> model = AutoModelForCausalLM.from_pretrained('google/gemma-2-2b-it')
|
>>> model = AutoModelForCausalLM.from_pretrained('google/gemma-2-2b')
|
||||||
|
|
||||||
>>> # SynthID Text configuration
|
>>> # SynthID Text configuration
|
||||||
>>> watermarking_config = SynthIDTextWatermarkingConfig(
|
>>> watermarking_config = SynthIDTextWatermarkingConfig(
|
||||||
@@ -1481,11 +1481,11 @@ class SynthIDTextWatermarkingConfig(BaseWatermarkingConfig):
|
|||||||
... )
|
... )
|
||||||
|
|
||||||
>>> # Generation with watermarking
|
>>> # Generation with watermarking
|
||||||
>>> tokenized_prompts = tokenizer(["your prompts here"])
|
>>> tokenized_prompts = tokenizer(["Once upon a time, "], return_tensors="pt", padding=True)
|
||||||
>>> output_sequences = model.generate(
|
>>> output_sequences = model.generate(
|
||||||
... **tokenized_prompts, watermarking_config=watermarking_config, do_sample=True,
|
... **tokenized_prompts, watermarking_config=watermarking_config, do_sample=True, max_new_tokens=10
|
||||||
... )
|
... )
|
||||||
>>> watermarked_text = tokenizer.batch_decode(output_sequences)
|
>>> watermarked_text = tokenizer.batch_decode(output_sequences, skip_special_tokens=True)
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -2565,8 +2565,8 @@ class SynthIDTextWatermarkLogitsProcessor(LogitsProcessor):
|
|||||||
```python
|
```python
|
||||||
>>> from transformers import AutoModelForCausalLM, AutoTokenizer, SynthIDTextWatermarkingConfig
|
>>> from transformers import AutoModelForCausalLM, AutoTokenizer, SynthIDTextWatermarkingConfig
|
||||||
|
|
||||||
>>> tokenizer = AutoTokenizer.from_pretrained('google/gemma-2-2b-it')
|
>>> tokenizer = AutoTokenizer.from_pretrained('google/gemma-2-2b', padding_side="left")
|
||||||
>>> model = AutoModelForCausalLM.from_pretrained('google/gemma-2-2b-it')
|
>>> model = AutoModelForCausalLM.from_pretrained('google/gemma-2-2b')
|
||||||
|
|
||||||
>>> # SynthID Text configuration
|
>>> # SynthID Text configuration
|
||||||
>>> watermarking_config = SynthIDTextWatermarkingConfig(
|
>>> watermarking_config = SynthIDTextWatermarkingConfig(
|
||||||
@@ -2575,11 +2575,11 @@ class SynthIDTextWatermarkLogitsProcessor(LogitsProcessor):
|
|||||||
... )
|
... )
|
||||||
|
|
||||||
>>> # Generation with watermarking
|
>>> # Generation with watermarking
|
||||||
>>> tokenized_prompts = tokenizer(["your prompts here"])
|
>>> tokenized_prompts = tokenizer(["Once upon a time, "], return_tensors="pt", padding=True)
|
||||||
>>> output_sequences = model.generate(
|
>>> output_sequences = model.generate(
|
||||||
... **tokenized_prompts, watermarking_config=watermarking_config, do_sample=True,
|
... **tokenized_prompts, watermarking_config=watermarking_config, do_sample=True, max_new_tokens=10
|
||||||
... )
|
... )
|
||||||
>>> watermarked_text = tokenizer.batch_decode(output_sequences)
|
>>> watermarked_text = tokenizer.batch_decode(output_sequences, skip_special_tokens=True)
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user