Documentation
¶
Index ¶
Examples ¶
Constants ¶
const ( // DefaultNGramSize is set to 3 (trigram) DefaultNGramSize = 3 // DefaultNGramType is set to word DefaultNGramType = "word" // DefaultSmoothingParameter is set to 1 (common Laplace smoothing value) DefaultSmoothingParameter = 1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bag ¶
type Bag struct {
// contains filtered or unexported fields
}
Bag represents a bag of words (BoW) model
func New ¶
New will initialize and return a new Bag with a provided configuration
Example ¶
var ( cfg Config err error ) // Initialize with default values if exampleBag, err = New(cfg); err != nil { log.Fatal(err) }
Output:
func NewFromTrainingSet ¶
func NewFromTrainingSet(t TrainingSet) (b *Bag, err error)
NewFromTrainingSet will initialize and return a new pre-trained Bag from a provided training set
Example ¶
var ( t TrainingSet err error ) t.Samples = SamplesByLabel{ "positive": { "I love this product, it is amazing!", "I am very happy with this.", "Very good", }, "negative": { "This is the worst thing ever.", "I hate this so much.", "Not good", }, } // Initialize with default values if exampleBag, err = NewFromTrainingSet(t); err != nil { log.Fatal(err) }
Output:
func NewFromTrainingSetFile ¶ added in v0.4.1
NewFromTrainingSetFile will initialize and return a new pre-trained Bag from a provided training set filepath
func (*Bag) GetResults ¶
GetResults will return the classification results for a given input string
Example ¶
exampleResults = exampleBag.GetResults("I am very happy with this product.") fmt.Println("Collection of results", exampleResults)
Output:
func (*Bag) Train ¶
Train will process a given input string and assign it the provided label for training
Example ¶
exampleBag.Train("I love this product, it is amazing!", "positive") exampleBag.Train("This is the worst thing ever.", "negative") exampleBag.Train("I am very happy with this.", "positive") exampleBag.Train("I hate this so much.", "negative") exampleBag.Train("Not good", "negative") exampleBag.Train("Very good", "negative")
Output:
type Config ¶
type Config struct { // NGramSize represents the NGram size (unigram, bigram, trigram, etc - default is trigram) NGramSize int `yaml:"ngram-size"` // NGramType represents the NGram type (word or character - default is word) NGramType string `yaml:"ngram-type"` // SmoothingParameter represents the smoothing value used for the Laplace Smoothing (default is 1) SmoothingParameter float64 `yaml:"smoothing-parameter"` }
type Results ¶
Results (by label) represents the probability of a processed input matching each of the possible labels (classifications)
func (Results) GetHighestProbability ¶
Example ¶
match := exampleResults.GetHighestProbability() fmt.Println("Highest probability", match)
Output:
type Samples ¶
type Samples []string
Samples represents a set of input samples to be used for model training
type SamplesByLabel ¶
SamplesByLabel represents sets of samples keyed by label
type TrainingSet ¶
type TrainingSet struct { Config `yaml:"config"` Samples SamplesByLabel `yaml:"samples"` }
TrainingSet is used to train a bag of words (BoW) model
type Vocabulary ¶
Vocabulary represents number of encounters for a given n-gram as string