DrDavis's picture
Upload folder using huggingface_hub
17c6d62 verified

생성을 μœ„ν•œ μœ ν‹Έλ¦¬ν‹° [[utilities-for-generation]]

이 νŽ˜μ΄μ§€λŠ” [~generation.GenerationMixin.generate]μ—μ„œ μ‚¬μš©λ˜λŠ” λͺ¨λ“  μœ ν‹Έλ¦¬ν‹° ν•¨μˆ˜λ“€μ„ λ‚˜μ—΄ν•©λ‹ˆλ‹€.

좜λ ₯을 μƒμ„±ν•˜κΈ° (Generate Outputs) [[generate-outputs]]

[~generation.GenerationMixin.generate]의 좜λ ₯은 [~utils.ModelOutput]의 ν•˜μœ„ 클래슀의 μΈμŠ€ν„΄μŠ€μž…λ‹ˆλ‹€. 이 좜λ ₯은 [~generation.GenerationMixin.generate]μ—μ„œ λ°˜ν™˜λ˜λŠ” λͺ¨λ“  정보λ₯Ό ν¬ν•¨ν•˜λŠ” 데이터 ꡬ쑰체이며, νŠœν”Œ λ˜λŠ” λ”•μ…”λ„ˆλ¦¬λ‘œλ„ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

λ‹€μŒμ€ μ˜ˆμ‹œμž…λ‹ˆλ‹€:

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λΌλŠ” 두 μš”μ†Œκ°€ ν¬ν•¨λœ 경우:

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]] SinkCache - update - get_seq_length - reorder_cache

[[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