model

package
v0.5.12 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: MIT Imports: 21 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Forward

func Forward(ctx ml.Context, m Model, opts Options) (ml.Tensor, error)

func Register

func Register(name string, f func(ml.Config) (Model, error))

Register registers a model constructor for the given architecture

Types

type Base

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

Base implements the common fields and methods for all models

func (*Base) Backend

func (m *Base) Backend() ml.Backend

Backend returns the underlying backend that will run the model

func (*Base) Config

func (m *Base) Config() config

type BytePairEncoding

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

func NewBytePairEncoding

func NewBytePairEncoding(pre string, vocab *Vocabulary) BytePairEncoding

func (BytePairEncoding) Decode

func (bpe BytePairEncoding) Decode(ids []int32) (string, error)

func (BytePairEncoding) Encode

func (bpe BytePairEncoding) Encode(s string) ([]int32, error)

func (BytePairEncoding) Is

func (bpe BytePairEncoding) Is(id int32, special Special) bool

type Model

type Model interface {
	Forward(ml.Context, Options) (ml.Tensor, error)

	Backend() ml.Backend
	Config() config
}

Model implements a specific model architecture, defining the forward pass and any model-specific configuration

func New

func New(modelPath string, params ml.BackendParams) (Model, error)

New initializes a new model instance with the provided configuration based on the metadata in the model file

type Options

type Options struct {
	Inputs    []int32
	Positions []int32
	Sequences []int
	Outputs   []int32

	Images []image.Image
}

Options contains the inputs for a model forward pass

type Special

type Special int32
const (
	SpecialBOS Special = iota
	SpecialEOS
)

type Tag

type Tag struct {
	Name      string
	Alternate []string
}

func ParseTags

func ParseTags(s string) (tag Tag)

type TextProcessor

type TextProcessor interface {
	Encode(string) ([]int32, error)
	Decode([]int32) (string, error)
	Is(int32, Special) bool
}

type Vocabulary

type Vocabulary struct {
	Values []string
	Types  []uint32
	Scores []uint32
	Merges []string

	BOS, EOS int32
	// 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) Is

func (v *Vocabulary) Is(id int32, special Special) bool

func (*Vocabulary) Merge

func (v *Vocabulary) Merge(left, right string) int

func (*Vocabulary) SpecialVocabulary

func (v *Vocabulary) SpecialVocabulary() []string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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