Skip to content

Commit

Permalink
Generate: consolidate output classes (huggingface#28494)
Browse files Browse the repository at this point in the history
  • Loading branch information
gante authored and wgifford committed Jan 21, 2024
1 parent 7827e41 commit bde8185
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 458 deletions.
22 changes: 5 additions & 17 deletions docs/source/en/internal/generation_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ inputs = tokenizer("Hello, my dog is cute and ", return_tensors="pt")
generation_output = model.generate(**inputs, return_dict_in_generate=True, output_scores=True)
```

The `generation_output` object is a [`~generation.GreedySearchDecoderOnlyOutput`], as we can
The `generation_output` object is a [`~generation.GenerateDecoderOnlyOutput`], as we can
see in the documentation of that class below, it means it has the following attributes:

- `sequences`: the generated sequences of tokens
Expand Down Expand Up @@ -77,25 +77,13 @@ We document here all output types.

### PyTorch

[[autodoc]] generation.GreedySearchEncoderDecoderOutput
[[autodoc]] generation.GenerateDecoderOnlyOutput

[[autodoc]] generation.GreedySearchDecoderOnlyOutput
[[autodoc]] generation.GenerateEncoderDecoderOutput

[[autodoc]] generation.SampleEncoderDecoderOutput
[[autodoc]] generation.GenerateBeamDecoderOnlyOutput

[[autodoc]] generation.SampleDecoderOnlyOutput

[[autodoc]] generation.BeamSearchEncoderDecoderOutput

[[autodoc]] generation.BeamSearchDecoderOnlyOutput

[[autodoc]] generation.BeamSampleEncoderDecoderOutput

[[autodoc]] generation.BeamSampleDecoderOnlyOutput

[[autodoc]] generation.ContrastiveSearchEncoderDecoderOutput

[[autodoc]] generation.ContrastiveSearchDecoderOnlyOutput
[[autodoc]] generation.GenerateBeamEncoderDecoderOutput

### TensorFlow

Expand Down
22 changes: 5 additions & 17 deletions docs/source/ja/internal/generation_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ inputs = tokenizer("Hello, my dog is cute and ", return_tensors="pt")
generation_output = model.generate(**inputs, return_dict_in_generate=True, output_scores=True)
```

`generation_output` オブジェクトは、できる限り [`~generation.GreedySearchDecoderOnlyOutput`] です。
`generation_output` オブジェクトは、できる限り [`~generation.GenerateDecoderOnlyOutput`] です。
以下のそのクラスのドキュメントを参照してください。これは、次の属性があることを意味します。

- `sequences`: 生成されたトークンのシーケンス
Expand Down Expand Up @@ -76,25 +76,13 @@ generation_output[:2]

### PyTorch

[[autodoc]] generation.GreedySearchEncoderDecoderOutput
[[autodoc]] generation.GenerateDecoderOnlyOutput

[[autodoc]] generation.GreedySearchDecoderOnlyOutput
[[autodoc]] generation.GenerateEncoderDecoderOutput

[[autodoc]] generation.SampleEncoderDecoderOutput
[[autodoc]] generation.GenerateBeamDecoderOnlyOutput

[[autodoc]] generation.SampleDecoderOnlyOutput

[[autodoc]] generation.BeamSearchEncoderDecoderOutput

[[autodoc]] generation.BeamSearchDecoderOnlyOutput

[[autodoc]] generation.BeamSampleEncoderDecoderOutput

[[autodoc]] generation.BeamSampleDecoderOnlyOutput

[[autodoc]] generation.ContrastiveSearchEncoderDecoderOutput

[[autodoc]] generation.ContrastiveSearchDecoderOnlyOutput
[[autodoc]] generation.GenerateBeamEncoderDecoderOutput

### TensorFlow

Expand Down
22 changes: 5 additions & 17 deletions docs/source/zh/internal/generation_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ inputs = tokenizer("Hello, my dog is cute and ", return_tensors="pt")
generation_output = model.generate(**inputs, return_dict_in_generate=True, output_scores=True)
```

`generation_output` 的对象是 [`~generation.GreedySearchDecoderOnlyOutput`] 的一个实例,从该类的文档中我们可以看到,这意味着它具有以下属性:
`generation_output` 的对象是 [`~generation.GenerateDecoderOnlyOutput`] 的一个实例,从该类的文档中我们可以看到,这意味着它具有以下属性:

- `sequences`: 生成的tokens序列
- `scores`(可选): 每个生成步骤的语言建模头的预测分数
Expand All @@ -70,25 +70,13 @@ generation_output[:2]

### PyTorch

[[autodoc]] generation.GreedySearchEncoderDecoderOutput
[[autodoc]] generation.GenerateDecoderOnlyOutput

[[autodoc]] generation.GreedySearchDecoderOnlyOutput
[[autodoc]] generation.GenerateEncoderDecoderOutput

[[autodoc]] generation.SampleEncoderDecoderOutput
[[autodoc]] generation.GenerateBeamDecoderOnlyOutput

[[autodoc]] generation.SampleDecoderOnlyOutput

[[autodoc]] generation.BeamSearchEncoderDecoderOutput

[[autodoc]] generation.BeamSearchDecoderOnlyOutput

[[autodoc]] generation.BeamSampleEncoderDecoderOutput

[[autodoc]] generation.BeamSampleDecoderOnlyOutput

[[autodoc]] generation.ContrastiveSearchEncoderDecoderOutput

[[autodoc]] generation.ContrastiveSearchDecoderOnlyOutput
[[autodoc]] generation.GenerateBeamEncoderDecoderOutput

### TensorFlow

Expand Down
8 changes: 8 additions & 0 deletions src/transformers/generation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
"BeamSampleDecoderOnlyOutput",
"ContrastiveSearchEncoderDecoderOutput",
"ContrastiveSearchDecoderOnlyOutput",
"GenerateBeamDecoderOnlyOutput",
"GenerateBeamEncoderDecoderOutput",
"GenerateDecoderOnlyOutput",
"GenerateEncoderDecoderOutput",
]

try:
Expand Down Expand Up @@ -222,6 +226,10 @@
BeamSearchEncoderDecoderOutput,
ContrastiveSearchDecoderOnlyOutput,
ContrastiveSearchEncoderDecoderOutput,
GenerateBeamDecoderOnlyOutput,
GenerateBeamEncoderDecoderOutput,
GenerateDecoderOnlyOutput,
GenerateEncoderDecoderOutput,
GenerationMixin,
GreedySearchDecoderOnlyOutput,
GreedySearchEncoderDecoderOutput,
Expand Down
Loading

0 comments on commit bde8185

Please sign in to comment.