utc

package module
v0.0.0-...-bfb5344 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: MIT Imports: 9 Imported by: 0

README

utc

Go Reference

Go Inference API for UTC (Universal Text Classification).

Installation

  1. Install utc

    $ go get -u github.com/go-aie/utc
    
  2. Install Paddle Inference Go API

Documentation

Check out the documentation.

Testing

Generate the inference model:

$ python3 cli/cli.py download

Run tests:

$ go test -v -race | grep -E 'go|Test'
=== RUN   TestBuildInputsWithPrompt
--- PASS: TestBuildInputsWithPrompt (0.00s)
=== RUN   TestPromptTokenizer_Encode
--- PASS: TestPromptTokenizer_Encode (0.01s)
=== RUN   TestUTC_Run
--- PASS: TestUTC_Run (2.89s)
ok      github.com/go-aie/utc   3.748s

License

MIT

Documentation

Index

Constants

View Source
const (
	PadToken   = "[PAD]"
	OMaskToken = "[O-MASK]"
	ClsToken   = "[CLS]"
	SepToken   = "[SEP]"
)
View Source
const (
	DefaultMaxOptions = 10
)

DefaultMaxOptions is the default value for some template attributes.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasePrompt

type BasePrompt struct {
	Position  int
	TokenType int
	Truncate  bool
}

func (BasePrompt) DoTruncate

func (p BasePrompt) DoTruncate() bool

func (BasePrompt) Positions

func (p BasePrompt) Positions() int

func (BasePrompt) TokenTypes

func (p BasePrompt) TokenTypes() int

type ChoicesPrompt

type ChoicesPrompt struct {
	BasePrompt

	AddOMask  bool
	AddPrompt bool
	Length    int
}

func (ChoicesPrompt) BuildText

func (p ChoicesPrompt) BuildText(e Example) string

type Config

type Config struct {
	ModelPath, ParamsPath string
	VocabFile             string
	DoLowerCase           bool
	MaxSeqLength          int
	ForCN                 bool
	// The maximum number of predictors for concurrent inferences.
	// Defaults to the value of runtime.NumCPU.
	MaxConcurrency int
}

type Encoding

type Encoding struct {
	SoftTokenIDs   []int
	InputIDs       []int
	PositionIDs    []int
	TokenTypeIDs   []int
	AttentionMask  *paddle.Matrix[float32]
	OMaskPositions []int
	ClsPositions   int
}

type ErnieTokenizer

type ErnieTokenizer struct {
	*aietokenizer.Tokenizer
}

func NewErnieTokenizer

func NewErnieTokenizer(vocabFile string, lowerCase bool) (*ErnieTokenizer, error)

func (*ErnieTokenizer) AddSpecialTokenIDs

func (t *ErnieTokenizer) AddSpecialTokenIDs(tokenIDsA, tokenIDsB []int, clsTokenID, sepTokenID int) []int

func (*ErnieTokenizer) ClsTokenID

func (t *ErnieTokenizer) ClsTokenID() int

func (*ErnieTokenizer) OMaskTokenID

func (t *ErnieTokenizer) OMaskTokenID() int

func (*ErnieTokenizer) PadTokenID

func (t *ErnieTokenizer) PadTokenID() int

func (*ErnieTokenizer) SepTokenID

func (t *ErnieTokenizer) SepTokenID() int

type Example

type Example struct {
	TextA    string
	TextB    string
	Question string
	Choices  []string
}

type Input

type Input struct {
	Text       string
	Positions  int
	TokenTypes int
	DoTruncate bool
}

func BuildInputsWithPrompt

func BuildInputsWithPrompt(e Example, ps ...Prompt) []Input

type Prediction

type Prediction struct {
	Text   string
	Scores map[string]float32
}

func (Prediction) Best

func (p Prediction) Best() (label string, score float32)

type Prompt

type Prompt interface {
	BuildText(Example) string
	Positions() int
	TokenTypes() int
	DoTruncate() bool
}

type PromptTokenizer

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

func NewPromptTokenizer

func NewPromptTokenizer(vocabFile string, doLowerCase bool, maxSeqLength int) (*PromptTokenizer, error)

func (*PromptTokenizer) Encode

func (t *PromptTokenizer) Encode(inputs []Input) Encoding

type SepPrompt

type SepPrompt struct {
	BasePrompt

	Sep string
}

func (SepPrompt) BuildText

func (p SepPrompt) BuildText(e Example) string

type TextPrompt

type TextPrompt struct {
	BasePrompt

	Text string
}

func (TextPrompt) BuildText

func (p TextPrompt) BuildText(e Example) string

type UTC

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

func NewUTC

func NewUTC(cfg *Config) *UTC

func (*UTC) Run

func (u *UTC) Run(schema []string, texts []string) []Prediction

Jump to

Keyboard shortcuts

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