lsmpp's picture
Add files using upload-large-folder tool
4cef5ec verified
<!--Copyright 2020 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.
-->
# 생성을 μœ„ν•œ μœ ν‹Έλ¦¬ν‹° [[utilities-for-generation]]
이 νŽ˜μ΄μ§€λŠ” [`~generation.GenerationMixin.generate`]μ—μ„œ μ‚¬μš©λ˜λŠ” λͺ¨λ“  μœ ν‹Έλ¦¬ν‹° ν•¨μˆ˜λ“€μ„ λ‚˜μ—΄ν•©λ‹ˆλ‹€.
## 좜λ ₯을 μƒμ„±ν•˜κΈ° (Generate Outputs) [[generate-outputs]]
[`~generation.GenerationMixin.generate`]의 좜λ ₯은 [`~utils.ModelOutput`]의 ν•˜μœ„ 클래슀의 μΈμŠ€ν„΄μŠ€μž…λ‹ˆλ‹€. 이 좜λ ₯은 [`~generation.GenerationMixin.generate`]μ—μ„œ λ°˜ν™˜λ˜λŠ” λͺ¨λ“  정보λ₯Ό ν¬ν•¨ν•˜λŠ” 데이터 ꡬ쑰체이며, νŠœν”Œ λ˜λŠ” λ”•μ…”λ„ˆλ¦¬λ‘œλ„ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
λ‹€μŒμ€ μ˜ˆμ‹œμž…λ‹ˆλ‹€:
```python
from transformers import GPT2Tokenizer, GPT2LMHeadModel
tokenizer = GPT2Tokenizer.from_pretrained("openai-community/gpt2")
model = GPT2LMHeadModel.from_pretrained("openai-community/gpt2")
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.GenerateDecoderOnlyOutput`]μž…λ‹ˆλ‹€. μ•„λž˜ λ¬Έμ„œμ—μ„œ 확인할 수 μžˆλ“―μ΄, 이 ν΄λž˜μŠ€λŠ” λ‹€μŒκ³Ό 같은 속성을 κ°€μ§€κ³  μžˆμŠ΅λ‹ˆλ‹€:
- `sequences`: μƒμ„±λœ 토큰 μ‹œν€€μŠ€
- `scores` (μ˜΅μ…˜): 각 생성 λ‹¨κ³„μ—μ„œ μ–Έμ–΄ λͺ¨λΈλ§ ν—€λ“œμ˜ 예츑 점수
- `hidden_states` (μ˜΅μ…˜): 각 생성 λ‹¨κ³„μ—μ„œ λͺ¨λΈμ˜ 은닉 μƒνƒœ
- `attentions` (μ˜΅μ…˜): 각 생성 λ‹¨κ³„μ—μ„œ λͺ¨λΈμ˜ μ–΄ν…μ…˜ κ°€μ€‘μΉ˜
`output_scores=True`λ₯Ό μ „λ‹¬ν–ˆκΈ° λ•Œλ¬Έμ— `scores`λŠ” ν¬ν•¨λ˜μ–΄ μžˆμ§€λ§Œ, `output_hidden_states=True` λ˜λŠ” `output_attentions=True`λ₯Ό μ „λ‹¬ν•˜μ§€ μ•Šμ•˜μœΌλ―€λ‘œ `hidden_states`와 `attentions`λŠ” ν¬ν•¨λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.
각 속성은 일반적으둜 μ ‘κ·Όν•  수 있으며, λͺ¨λΈμ΄ ν•΄λ‹Ή 속성을 λ°˜ν™˜ν•˜μ§€ μ•Šμ•˜λ‹€λ©΄ `None`이 λ°˜ν™˜λ©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, `generation_output.scores`λŠ” μ–Έμ–΄ λͺ¨λΈλ§ ν—€λ“œμ—μ„œ μƒμ„±λœ λͺ¨λ“  예츑 점수λ₯Ό ν¬ν•¨ν•˜κ³  있으며, `generation_output.attentions`λŠ” `None`μž…λ‹ˆλ‹€.
`generation_output` 객체λ₯Ό νŠœν”Œλ‘œ μ‚¬μš©ν•  경우, `None` 값이 μ•„λ‹Œ μ†μ„±λ§Œ ν¬ν•¨λ©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, `loss`와 `logits`λΌλŠ” 두 μš”μ†Œκ°€ ν¬ν•¨λœ 경우:
```python
generation_output[:2]
```
μœ„ μ½”λ“œλŠ” `(generation_output.sequences, generation_output.scores)` νŠœν”Œμ„ λ°˜ν™˜ν•©λ‹ˆλ‹€.
`generation_output` 객체λ₯Ό λ”•μ…”λ„ˆλ¦¬λ‘œ μ‚¬μš©ν•  경우, `None` 값이 μ•„λ‹Œ μ†μ„±λ§Œ ν¬ν•¨λ©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄, `sequences`와 `scores`λΌλŠ” 두 개의 ν‚€λ₯Ό κ°€μ§ˆ 수 μžˆμŠ΅λ‹ˆλ‹€.
μ—¬κΈ°μ„œλŠ” λͺ¨λ“  좜λ ₯ μœ ν˜•μ„ λ¬Έμ„œν™”ν•©λ‹ˆλ‹€.
### PyTorch [[transformers.generation.GenerateDecoderOnlyOutput]]
[[autodoc]] generation.GenerateDecoderOnlyOutput
[[autodoc]] generation.GenerateEncoderDecoderOutput
[[autodoc]] generation.GenerateBeamDecoderOnlyOutput
[[autodoc]] generation.GenerateBeamEncoderDecoderOutput
### TensorFlow [[transformers.generation.TFGreedySearchEncoderDecoderOutput]]
[[autodoc]] generation.TFGreedySearchEncoderDecoderOutput
[[autodoc]] generation.TFGreedySearchDecoderOnlyOutput
[[autodoc]] generation.TFSampleEncoderDecoderOutput
[[autodoc]] generation.TFSampleDecoderOnlyOutput
[[autodoc]] generation.TFBeamSearchEncoderDecoderOutput
[[autodoc]] generation.TFBeamSearchDecoderOnlyOutput
[[autodoc]] generation.TFBeamSampleEncoderDecoderOutput
[[autodoc]] generation.TFBeamSampleDecoderOnlyOutput
[[autodoc]] generation.TFContrastiveSearchEncoderDecoderOutput
[[autodoc]] generation.TFContrastiveSearchDecoderOnlyOutput
### FLAX [[transformers.generation.FlaxSampleOutput]]
[[autodoc]] generation.FlaxSampleOutput
[[autodoc]] generation.FlaxGreedySearchOutput
[[autodoc]] generation.FlaxBeamSearchOutput
## LogitsProcessor [[logitsprocessor]]
[`LogitsProcessor`]λŠ” 생성 쀑 μ–Έμ–΄ λͺ¨λΈ ν—€λ“œμ˜ 예츑 점수λ₯Ό μˆ˜μ •ν•˜λŠ” 데 μ‚¬μš©λ©λ‹ˆλ‹€.
### PyTorch [[transformers.AlternatingCodebooksLogitsProcessor]]
[[autodoc]] AlternatingCodebooksLogitsProcessor
- __call__
[[autodoc]] ClassifierFreeGuidanceLogitsProcessor
- __call__
[[autodoc]] EncoderNoRepeatNGramLogitsProcessor
- __call__
[[autodoc]] EncoderRepetitionPenaltyLogitsProcessor
- __call__
[[autodoc]] EpsilonLogitsWarper
- __call__
[[autodoc]] EtaLogitsWarper
- __call__
[[autodoc]] ExponentialDecayLengthPenalty
- __call__
[[autodoc]] ForcedBOSTokenLogitsProcessor
- __call__
[[autodoc]] ForcedEOSTokenLogitsProcessor
- __call__
[[autodoc]] HammingDiversityLogitsProcessor
- __call__
[[autodoc]] InfNanRemoveLogitsProcessor
- __call__
[[autodoc]] LogitNormalization
- __call__
[[autodoc]] LogitsProcessor
- __call__
[[autodoc]] LogitsProcessorList
- __call__
[[autodoc]] MinLengthLogitsProcessor
- __call__
[[autodoc]] MinNewTokensLengthLogitsProcessor
- __call__
[[autodoc]] MinPLogitsWarper
- __call__
[[autodoc]] NoBadWordsLogitsProcessor
- __call__
[[autodoc]] NoRepeatNGramLogitsProcessor
- __call__
[[autodoc]] PrefixConstrainedLogitsProcessor
- __call__
[[autodoc]] RepetitionPenaltyLogitsProcessor
- __call__
[[autodoc]] SequenceBiasLogitsProcessor
- __call__
[[autodoc]] SuppressTokensAtBeginLogitsProcessor
- __call__
[[autodoc]] SuppressTokensLogitsProcessor
- __call__
[[autodoc]] TemperatureLogitsWarper
- __call__
[[autodoc]] TopKLogitsWarper
- __call__
[[autodoc]] TopPLogitsWarper
- __call__
[[autodoc]] TypicalLogitsWarper
- __call__
[[autodoc]] UnbatchedClassifierFreeGuidanceLogitsProcessor
- __call__
[[autodoc]] WhisperTimeStampLogitsProcessor
- __call__
[[autodoc]] WatermarkLogitsProcessor
- __call__
### TensorFlow [[transformers.TFForcedBOSTokenLogitsProcessor]]
[[autodoc]] TFForcedBOSTokenLogitsProcessor
- __call__
[[autodoc]] TFForcedEOSTokenLogitsProcessor
- __call__
[[autodoc]] TFForceTokensLogitsProcessor
- __call__
[[autodoc]] TFLogitsProcessor
- __call__
[[autodoc]] TFLogitsProcessorList
- __call__
[[autodoc]] TFLogitsWarper
- __call__
[[autodoc]] TFMinLengthLogitsProcessor
- __call__
[[autodoc]] TFNoBadWordsLogitsProcessor
- __call__
[[autodoc]] TFNoRepeatNGramLogitsProcessor
- __call__
[[autodoc]] TFRepetitionPenaltyLogitsProcessor
- __call__
[[autodoc]] TFSuppressTokensAtBeginLogitsProcessor
- __call__
[[autodoc]] TFSuppressTokensLogitsProcessor
- __call__
[[autodoc]] TFTemperatureLogitsWarper
- __call__
[[autodoc]] TFTopKLogitsWarper
- __call__
[[autodoc]] TFTopPLogitsWarper
- __call__
### FLAX [[transformers.FlaxForcedBOSTokenLogitsProcessor]]
[[autodoc]] FlaxForcedBOSTokenLogitsProcessor
- __call__
[[autodoc]] FlaxForcedEOSTokenLogitsProcessor
- __call__
[[autodoc]] FlaxForceTokensLogitsProcessor
- __call__
[[autodoc]] FlaxLogitsProcessor
- __call__
[[autodoc]] FlaxLogitsProcessorList
- __call__
[[autodoc]] FlaxLogitsWarper
- __call__
[[autodoc]] FlaxMinLengthLogitsProcessor
- __call__
[[autodoc]] FlaxSuppressTokensAtBeginLogitsProcessor
- __call__
[[autodoc]] FlaxSuppressTokensLogitsProcessor
- __call__
[[autodoc]] FlaxTemperatureLogitsWarper
- __call__
[[autodoc]] FlaxTopKLogitsWarper
- __call__
[[autodoc]] FlaxTopPLogitsWarper
- __call__
[[autodoc]] FlaxWhisperTimeStampLogitsProcessor
- __call__
## StoppingCriteria [[transformers.StoppingCriteria]]
[`StoppingCriteria`]λŠ” 생성이 μ–Έμ œ λ©ˆμΆœμ§€λ₯Ό κ²°μ •ν•˜λŠ” 데 μ‚¬μš©λ©λ‹ˆλ‹€ (EOS 토큰 μ™Έ). 이 κΈ°λŠ₯은 PyTorch κ΅¬ν˜„μ—λ§Œ μ œκ³΅λ©λ‹ˆλ‹€.
[[autodoc]] StoppingCriteria
- __call__
[[autodoc]] StoppingCriteriaList
- __call__
[[autodoc]] MaxLengthCriteria
- __call__
[[autodoc]] MaxTimeCriteria
- __call__
[[autodoc]] StopStringCriteria
- __call__
[[autodoc]] EosTokenCriteria
- __call__
## Constraint [[transformers.Constraint]]
[`Constraint`]λŠ” 생성 좜λ ₯에 νŠΉμ • ν† ν°μ΄λ‚˜ μ‹œν€€μŠ€λ₯Ό κ°•μ œλ‘œ ν¬ν•¨μ‹œν‚€λŠ” 데 μ‚¬μš©λ©λ‹ˆλ‹€. 이 κΈ°λŠ₯은 PyTorch κ΅¬ν˜„μ—λ§Œ μ œκ³΅λ©λ‹ˆλ‹€.
[[autodoc]] Constraint
[[autodoc]] PhrasalConstraint
[[autodoc]] DisjunctiveConstraint
[[autodoc]] ConstraintListState
## λΉ” 검색 (BeamSearch) [[transformers.BeamScorer]]
[[autodoc]] BeamScorer
- process
- finalize
[[autodoc]] BeamSearchScorer
- process
- finalize
[[autodoc]] ConstrainedBeamSearchScorer
- process
- finalize
## 슀트리머 (Streamers) [[transformers.TextStreamer]]
[[autodoc]] TextStreamer
[[autodoc]] TextIteratorStreamer
## μΊμ‹œ (Caches) [[transformers.Cache]]
[[autodoc]] Cache
- update
[[autodoc]] CacheConfig
- update
[[autodoc]] QuantizedCacheConfig
- validate
[[autodoc]] DynamicCache
- update
- get_seq_length
- reorder_cache
- to_legacy_cache
- from_legacy_cache
[[autodoc]] QuantizedCache
- update
- get_seq_length
[[autodoc]] QuantoQuantizedCache
[[autodoc]] HQQQuantizedCache
[[autodoc]] OffloadedCache
- update
- prefetch_layer
- evict_previous_layer
[[autodoc]] StaticCache
- update
- get_seq_length
- reset
[[autodoc]] OffloadedStaticCache
- update
- get_seq_length
- reset
[[autodoc]] HybridCache
- update
- get_seq_length
- reset
[[autodoc]] SlidingWindowCache
- update
- reset
[[autodoc]] EncoderDecoderCache
- get_seq_length
- to_legacy_cache
- from_legacy_cache
- reset
- reorder_cache
[[autodoc]] MambaCache
- update_conv_state
- update_ssm_state
- reset
## μ›Œν„°λ§ˆν¬ μœ ν‹Έλ¦¬ν‹° (Watermark Utils) [[transformers.WatermarkDetector]]
[[autodoc]] WatermarkDetector
- __call__