Documentation
¶
Index ¶
- Variables
- type EncodeOption
- type Encoding
- type Offset
- type Tokenizer
- func FromBytes(data []byte, opts ...TokenizerOption) (*Tokenizer, error)
- func FromBytesWithTruncation(data []byte, maxLen uint32, dir TruncationDirection) (*Tokenizer, error)
- func FromFile(path string) (*Tokenizer, error)
- func FromPretrained(modelID string, opts ...TokenizerConfigOption) (*Tokenizer, error)
- func FromTiktoken(modelPath, configPath, pattern string) (*Tokenizer, error)
- func (t *Tokenizer) Close() error
- func (t *Tokenizer) Decode(tokenIDs []uint32, skipSpecialTokens bool) string
- func (t *Tokenizer) DecodeErr(tokenIDs []uint32, skipSpecialTokens bool) (string, error)
- func (t *Tokenizer) Encode(str string, addSpecialTokens bool) ([]uint32, []string)
- func (t *Tokenizer) EncodeErr(str string, addSpecialTokens bool) ([]uint32, []string, error)
- func (t *Tokenizer) EncodeWithOptions(str string, addSpecialTokens bool, opts ...EncodeOption) Encoding
- func (t *Tokenizer) EncodeWithOptionsErr(str string, addSpecialTokens bool, opts ...EncodeOption) (Encoding, error)
- func (t *Tokenizer) VocabSize() uint32
- type TokenizerConfigOption
- type TokenizerOption
- type TruncationDirection
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrTokenizerClosed = errors.New("tokenizer is nil or closed")
Functions ¶
This section is empty.
Types ¶
type EncodeOption ¶ added in v0.7.0
type EncodeOption func(eo *encodeOpts)
func WithReturnAllAttributes ¶ added in v0.7.0
func WithReturnAllAttributes() EncodeOption
func WithReturnAttentionMask ¶ added in v0.7.0
func WithReturnAttentionMask() EncodeOption
func WithReturnOffsets ¶ added in v0.9.0
func WithReturnOffsets() EncodeOption
func WithReturnSpecialTokensMask ¶ added in v0.7.0
func WithReturnSpecialTokensMask() EncodeOption
func WithReturnTokens ¶ added in v0.7.0
func WithReturnTokens() EncodeOption
func WithReturnTypeIDs ¶ added in v0.7.0
func WithReturnTypeIDs() EncodeOption
type Tokenizer ¶
type Tokenizer struct {
// contains filtered or unexported fields
}
func FromBytes ¶ added in v0.2.0
func FromBytes(data []byte, opts ...TokenizerOption) (*Tokenizer, error)
func FromBytesWithTruncation ¶ added in v0.4.0
func FromBytesWithTruncation(data []byte, maxLen uint32, dir TruncationDirection) (*Tokenizer, error)
func FromPretrained ¶ added in v1.20.2
func FromPretrained(modelID string, opts ...TokenizerConfigOption) (*Tokenizer, error)
FromPretrained downloads necessary files and initializes the tokenizer. Parameters:
- modelID: The Hugging Face model identifier (e.g., "bert-base-uncased").
- WithCacheDir(path): Optional. If provided, files will be downloaded to this folder.
- WithAuthToken(token): Optional. If provided, it will be used to authenticate requests.
func FromTiktoken ¶ added in v1.21.0
FromTiktoken creates a tokenizer from tiktoken model and config files
func (*Tokenizer) EncodeWithOptions ¶ added in v0.7.0
func (t *Tokenizer) EncodeWithOptions(str string, addSpecialTokens bool, opts ...EncodeOption) Encoding
func (*Tokenizer) EncodeWithOptionsErr ¶ added in v1.26.0
type TokenizerConfigOption ¶ added in v1.20.2
type TokenizerConfigOption func(cfg *tokenizerConfig)
func WithAuthToken ¶ added in v1.20.2
func WithAuthToken(token string) TokenizerConfigOption
func WithCacheDir ¶ added in v1.20.2
func WithCacheDir(path string) TokenizerConfigOption
type TokenizerOption ¶ added in v0.7.1
type TokenizerOption func(to *tokenizerOpts)
func WithEncodeSpecialTokens ¶ added in v0.7.1
func WithEncodeSpecialTokens() TokenizerOption
type TruncationDirection ¶ added in v0.4.0
type TruncationDirection int
const ( TruncationDirectionLeft TruncationDirection = iota TruncationDirectionRight )
Click to show internal directories.
Click to hide internal directories.