Documentation
¶
Index ¶
- Constants
- Variables
- func Forward(ctx ml.Context, m Model, opts input.Options) (ml.Tensor, error)
- func Register(name string, f func(ml.Config) (Model, error))
- type Base
- type BytePairEncoding
- type Model
- type MultimodalProcessor
- type SentencePieceModel
- type Special
- type Tag
- type TextProcessor
- type Vocabulary
Constants ¶
View Source
const ( TOKEN_TYPE_NORMAL = iota + 1 TOKEN_TYPE_UNKNOWN TOKEN_TYPE_CONTROL TOKEN_TYPE_USER_DEFINED TOKEN_TYPE_UNUSED TOKEN_TYPE_BYTE )
Variables ¶
View Source
var ErrNoVisionModel = errors.New("this model is missing data required for image input")
Functions ¶
Types ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base implements the common fields and methods for all models
type BytePairEncoding ¶
type BytePairEncoding struct {
// contains filtered or unexported fields
}
func NewBytePairEncoding ¶
func NewBytePairEncoding(pre string, vocab *Vocabulary) BytePairEncoding
type Model ¶
type Model interface {
Forward(ml.Context, input.Options) (ml.Tensor, error)
Backend() ml.Backend
Config() config
}
Model implements a specific model architecture, defining the forward pass and any model-specific configuration
type MultimodalProcessor ¶ added in v0.6.0
type MultimodalProcessor interface {
// EncodeMultimodal processes a single input (such as an image) and
// generates an output (typically an embedding) that can be used by the model.
//
// The return value is most typically an ml.Tensor, however, different
// type are possible, such as an object containing a tensor plus
// additional metadata, a slice of tensors or even just the original input.
//
// The result may be cached by the runner.
EncodeMultimodal(ml.Context, []byte) (any, error)
// PostTokenize is called after tokenization to allow the model to edit the
// input stream to correctly arrange multimodal elements.
//
// The input is a slice of tokens with the results of EncodeMultimodal interleaved
// in the order that the user provided them. Each element of the slice will be
// either a single token or single multimodal object.
//
// The model must ensure that inputs are stored according to how they will be
// processed and stored in the cache. For example, Llava-style models should insert
// placeholder tokens equal to the feature size of the corresponding image with
// the image itself attached to and split across these tokens. When Forward is called
// a partial subset of these tokens may be submitted according to the batch size.
//
// This function is also responsible for updating MultimodalHash for any Multimodal
// that is modified to ensure that there is a unique hash value that accurately
// represents the contents.
PostTokenize(ml.Context, []input.Input) ([]input.Input, error)
}
MultimodalProcessor must be implemented by multimodal models.
type SentencePieceModel ¶ added in v0.6.0
type SentencePieceModel struct {
// contains filtered or unexported fields
}
func NewSentencePieceModel ¶ added in v0.6.0
func NewSentencePieceModel(pre string, vocab *Vocabulary) SentencePieceModel
func (SentencePieceModel) Decode ¶ added in v0.6.0
func (spm SentencePieceModel) Decode(ids []int32) (string, error)
type TextProcessor ¶
type TextProcessor interface {
Encode(s string, addSpecial bool) ([]int32, error)
Decode([]int32) (string, error)
Is(int32, Special) bool
}
func NewTextProcessor ¶ added in v0.6.0
func NewTextProcessor(s string) (TextProcessor, error)
type Vocabulary ¶
type Vocabulary struct {
Values []string
Types []uint32
Scores []float32
Merges []string
BOS, EOS, EOT int32
AddBOS, AddEOS, AddEOT bool
// contains filtered or unexported fields
}
func (*Vocabulary) Decode ¶
func (v *Vocabulary) Decode(id int32) string
func (*Vocabulary) Encode ¶
func (v *Vocabulary) Encode(s string) int32
func (*Vocabulary) Merge ¶
func (v *Vocabulary) Merge(left, right string) int
func (*Vocabulary) SpecialVocabulary ¶
func (v *Vocabulary) SpecialVocabulary() []string
Click to show internal directories.
Click to hide internal directories.