Documentation
¶
Index ¶
- Constants
- Variables
- func SprintScores(scores []float64, ts []transition) string
- type Model
- type Move
- type NNConfig
- type NonProjectiveError
- type Parser
- type Performance
- type TarpitError
- type Trainer
- func (t *Trainer) Clusters() (map[string]lingo.Cluster, error)
- func (t *Trainer) Cost() <-chan float64
- func (t *Trainer) Init() (err error)
- func (t *Trainer) Lemmatize(a string, pt lingo.POSTag) ([]string, error)
- func (t *Trainer) Perf() <-chan Performance
- func (t *Trainer) Stem(a string) (string, error)
- func (t *Trainer) Train(epochs int) error
- func (t *Trainer) TrainWithoutCrossValidation(epochs int) error
- type TrainerConsOpt
- func WithCluster(c map[string]lingo.Cluster) TrainerConsOpt
- func WithConfig(conf NNConfig) TrainerConsOpt
- func WithCorpus(c *corpus.Corpus) TrainerConsOpt
- func WithCrossValidationSet(st []treebank.SentenceTag) TrainerConsOpt
- func WithGeneratedCorpus(sts ...treebank.SentenceTag) TrainerConsOpt
- func WithLemmatizer(l lingo.Lemmatizer) TrainerConsOpt
- func WithStemmer(s lingo.Stemmer) TrainerConsOpt
- func WithTrainingModel(m *Model) TrainerConsOpt
- func WithTrainingSet(st []treebank.SentenceTag) TrainerConsOpt
Constants ¶
const ( POS_OFFSET int = 18 DEP_OFFSET = 36 STACK_OFFSET = 6 STACK_NUMBER = 6 )
const BUILD_DEBUG = "PARSER: RELEASE BUILD"
const BUILD_DIAG = "Non-Diagnostic Build"
const DEBUG = false
const (
DOES_NOT_EXIST head = iota - 1
)
const (
MAXFEATURE feature
)
Variables ¶
var ALLMOVES = [...]Move{Left, Right, Shift}
ALLMOVES is the set of all possible moves
var KnownWords *corpus.Corpus // package provided global
var MAXTRANSITION int
var READMEMSTATS = false
var TABCOUNT uint32 = 0
Functions ¶
func SprintScores ¶
Types ¶
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model holds the neural network that a DependencyParser uses. To train, use a Trainer
func LoadReader ¶
func LoadReader(rd io.ReadCloser) (*Model, error)
func (*Model) POSTagEmbeddings ¶
func (*Model) SaveWriter ¶
func (m *Model) SaveWriter(f io.WriteCloser) error
func (*Model) WordEmbeddings ¶
type Move ¶
type Move byte
Move is an action that the dependency parser can take - whether to Shift, Attach-Left, or AttachRight
type NNConfig ¶
type NNConfig struct { BatchSize int // 10000 Dropout float64 // 0.5 AdaEps float64 // 1e-6 AdaAlpha float64 //0.02 Reg float64 // 1e-8 HiddenSize int // 200 EmbeddingSize int // 50 NumPrecomputed int //100000 EvalPerIteration int // 100 ClearGradientsPerIteration int // 0 Dtype tensor.Dtype }
NNConfig configures the neural network
var DefaultNNConfig NNConfig
DefaultNNConfig is the default config that is passed in, for initialization purposses.
type NonProjectiveError ¶
type NonProjectiveError struct{ *lingo.Dependency }
NonProjective error is the error that is emitted when the dependency tree is not projective (that is to say the children cross lines)
func (NonProjectiveError) Error ¶
func (err NonProjectiveError) Error() string
type Parser ¶
type Parser struct { Input chan lingo.AnnotatedSentence Output chan *lingo.Dependency Error chan error *Model }
Parser is the object that performs the dependency parsing It contains a neural network, which is the core of it.
The same object can be used to train the NN
func (*Parser) Run ¶
func (d *Parser) Run()
Run is used when using the NN to parse a sentence. For training, see Train()
func (*Parser) SprintFeatures ¶
type Performance ¶
type Performance struct { Iter int // which training iteration is this? UAS float64 // Unlabelled Attachment Score LAS float64 // Labeled Attachment Score UEM float64 // Unlabelled Exact Match Root float64 // Correct Roots Ratio }
Performance is a tuple that holds performance information from a training session
func Evaluate ¶
func Evaluate(predictedTrees, goldTrees []*lingo.Dependency) Performance
Evaluate compares predicted trees with the gold standard trees and returns a Performance. It panics if the number of predicted trees and the number of gold trees aren't the same
func (Performance) String ¶
func (p Performance) String() string
type TarpitError ¶
type TarpitError struct {
// contains filtered or unexported fields
}
TarpitError is an error when the arc-standard is stuck. It implements GoStringer, which when called will output the state as a string. It also implements lingo.Sentencer, so the offending sentence can easily be retrieved
func (TarpitError) Error ¶
func (err TarpitError) Error() string
type Trainer ¶
type Trainer struct { *Model // Training configuration EvalPerIter int // for cross validation - evaluate results every n epochs PassDirect bool // Pass on the costs directly to the cost channel? If false, an average will be used SaveBest string // SaveBest is the filename that will be saved. If it's empty then the best-while-training will not be saved // contains filtered or unexported fields }
Trainer trains a model
func NewTrainer ¶
func NewTrainer(opts ...TrainerConsOpt) *Trainer
NewTrainer creates a new Trainer.
func (*Trainer) Cost ¶
Cost returns a channel of costs for monitoring the training. If the PassDirect field in the trainer is set to true then the costs are directly returned. Otherwise the costs are averaged over the epoch.
func (*Trainer) Init ¶
Init initializes the DependencyParser with a corpus and a neural network config
func (*Trainer) Perf ¶
func (t *Trainer) Perf() <-chan Performance
Perf returns a channel of Performance for monitoring the training.
func (*Trainer) Train ¶
Train trains a model.
If a cross validation set is provided, it will automatically train with the cross validation set
func (*Trainer) TrainWithoutCrossValidation ¶
TrainWithoutCrossValidation trains a model without cross validation.
type TrainerConsOpt ¶
type TrainerConsOpt func(t *Trainer)
TrainerConsOpt is a construction option for trainer
func WithCluster ¶
func WithCluster(c map[string]lingo.Cluster) TrainerConsOpt
WithCluster sets the brown cluster options for the DependencyParser
func WithConfig ¶
func WithConfig(conf NNConfig) TrainerConsOpt
WithConfig sets up a *Trainer with a NNConfig
func WithCorpus ¶
func WithCorpus(c *corpus.Corpus) TrainerConsOpt
WithCorpus creates a Trainer with a corpus
func WithCrossValidationSet ¶
func WithCrossValidationSet(st []treebank.SentenceTag) TrainerConsOpt
WithCrossValidationSet creates a trainer with a cross validation set
func WithGeneratedCorpus ¶
func WithGeneratedCorpus(sts ...treebank.SentenceTag) TrainerConsOpt
WithGeneratedCorpus creates a Trainer's corpus from a list of SentenceTags. The corpus will be generated from the SentenceTags
func WithLemmatizer ¶
func WithLemmatizer(l lingo.Lemmatizer) TrainerConsOpt
WithLemmatizer sets the lemmatizer option on the Trainer
func WithStemmer ¶
func WithStemmer(s lingo.Stemmer) TrainerConsOpt
WithStemmer sets up the stemmer option on the DependencyParser
func WithTrainingModel ¶
func WithTrainingModel(m *Model) TrainerConsOpt
WithTrainingModel loads a trainer with a model
func WithTrainingSet ¶
func WithTrainingSet(st []treebank.SentenceTag) TrainerConsOpt
WithTrainingSet creates a trainer with a training set