decoder

package
v0.0.0-...-4d121eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2023 License: BSD-2-Clause Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

func New

func New(m *rwkvlm.Model, opts DecodingOptions) (*Decoder, error)

func (*Decoder) Decode

func (d *Decoder) Decode(ctx context.Context, nt *ag.NodesTracker, input encoder.Result, chGen chan GeneratedToken) error

type DecodingOptions

type DecodingOptions struct {
	// MaxLen is the maximum number of tokens to generate.
	MaxLen int `json:"max_len" yaml:"max_len"`
	// MinLen is the minimum number of tokens to generate.
	MinLen int `json:"min_len" yaml:"min_len"`
	// StopSequencesIDs is a list of token ids that if generated, the generation process will stop.
	StopSequencesIDs [][]int `json:"stop_sequences_ids" yaml:"stop_sequences_ids"`
	// EndTokenID is the end-of-sequence token (default: 0).
	EndTokenID int `json:"end_token_id" yaml:"end_token_id"`
	// SkipEndTokenID when true, the end token is not added to the generated sequence.
	SkipEndTokenID bool `json:"skip_end_token_id" yaml:"skip_end_token_id"`
	// Temperature is the temperature used to control the randomness of the generated text.
	Temp float64 `json:"temp" yaml:"temp"`
	// TopK is the number of tokens to consider when sampling the next token.
	TopK int `json:"top_k" yaml:"top_k"`
	// TopP is the cumulative probability of the tokens to consider when sampling the next token.
	TopP float64 `json:"top_p" yaml:"top_p"`
	// UseSampling uses sampling to generate the next token.
	UseSampling bool `json:"use_sampling" yaml:"use_sampling"`
}

DecodingOptions contains the options for the conditional text generation.

type GeneratedToken

type GeneratedToken struct {
	// TokenID is the ID of the token predicted by the decoder at the current step.
	TokenID int
	// SumNegLogProbs is the sum of the negative log probabilities up to the current step.
	SumNegLogProbs float64
}

GeneratedToken is the result of a single step of the decoder.

type OutputDiversityControlFunc

type OutputDiversityControlFunc func(logits mat.Matrix) (mat.Matrix, error)

OutputDiversityControlFunc performs the pre-processing steps that are used to narrow down the set of candidate items before using greedy decoding or multinomial sampling to generate the final output.

func OutputDiversityControl

func OutputDiversityControl(temp float64, topK int, topP float64) (OutputDiversityControlFunc, error)

OutputDiversityControl returns a function used to select the next token.

func TemperatureFunc

func TemperatureFunc(temperature float64) OutputDiversityControlFunc

TemperatureFunc applies a temperature to a matrix of scores.

func TopKFunc

func TopKFunc(topK int, filterValue float64) OutputDiversityControlFunc

TopKFunc applies a top-k filter to a matrix of scores.

func TopPFunc

func TopPFunc[T float.DType](topP, filterValue T, minSize int) OutputDiversityControlFunc

TopPFunc applies a top-p filter to a matrix of scores. Note that when using beam decoding (with beam > 1) then minSize must be at least 2.

type OutputSelectionFunc

type OutputSelectionFunc func(logits mat.Matrix) (int, float64, error)

func GreedyDecoding

func GreedyDecoding() OutputSelectionFunc

func MultinomialSampling

func MultinomialSampling() OutputSelectionFunc

func OutputSelection

func OutputSelection(sampling bool) OutputSelectionFunc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL