vw

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2020 License: MIT Imports: 3 Imported by: 2

README

Build Status GoDoc

go-vowpal-wabbit

Vowpal Wabbit bindings for Golang

import "github.com/orktes/go-vowpal-wabbit"

Usage

Library depends on the Vowpal Wabbit shared library. To install the shared lib please follow VW installation instruction.

API is designed to closely resemble the C API of Vowpal Wabbit with minor changes done to make it more convinient to be used from go. Library is not thread safe and additional locking is required if libary is being called from multiple goroutines.

Minimalistic example

import (
    wabbit "github.com/orktes/go-vowpal-wabbit"
)

func main() {
	vw, _ := wabbit.New("-q st --noconstant --quiet")
	defer vw.Finish()

	// Learn an example
	ex, _ := vw.ReadExample("1 |s p^the_man w^the w^man |t p^un_homme w^un w^homme")
	vw.Learn(ex)

	// Predict with features
	ex, _ = vw.ReadExample("|s p^the_man w^the w^man |t p^un_homme w^un w^homme")
	res := vw.Predict(ex)

	fmt.Printf("Prediction: %f", res)
	// Output: Prediction: 0.855723
}

TODO

  • Handle exceptions from VW
  • Add pooling for example creation (json & dsjson)

Documentation

Overview

Package vw implements golang bindings for Vowpal Wabbit Online Learning library. API is designed to closely resemble the C API of Vowpal Wabbit with minor changes done to make it more convinient to be used from go. Library is not thread safe and additional locking is required if libary is being called from multiple goroutines.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

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

Error errors returned by vowpal wabbig functions

func (*Error) Error

func (te *Error) Error() string

type Example

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

Example a single Vowpal Wabbit example

func (*Example) Finish

func (ex *Example) Finish()

Finish finishes the example

func (*Example) GetAction

func (ex *Example) GetAction(i int) int

GetAction returns the action for index

func (*Example) GetActionScore

func (ex *Example) GetActionScore(i int) float32

GetActionScore returns action score for index

func (*Example) GetActionScoreLength

func (ex *Example) GetActionScoreLength() int

GetActionScoreLength get action score length

func (*Example) GetActionScores

func (ex *Example) GetActionScores() []float32

GetActionScores returns all action scores as a slice

func (*Example) GetActions

func (ex *Example) GetActions() []int

GetActions returns all actions as a slice

func (*Example) GetCBCost added in v0.0.4

func (ex *Example) GetCBCost(i int) int

GetCBCost get cb cost length

func (*Example) GetCBCostLength added in v0.0.4

func (ex *Example) GetCBCostLength() int

GetCBCostLength get cb cost length

func (*Example) GetConfidence

func (ex *Example) GetConfidence() float32

GetConfidence returns confidence

func (*Example) GetCostSensitivePrediction

func (ex *Example) GetCostSensitivePrediction() float32

GetCostSensitivePrediction returns initial

func (*Example) GetFeatureNumber

func (ex *Example) GetFeatureNumber() int

GetFeatureNumber returns number of features

func (*Example) GetImportance

func (ex *Example) GetImportance() float32

GetImportance returns importance

func (*Example) GetInitial

func (ex *Example) GetInitial() float32

GetInitial returns initial

func (*Example) GetLabel

func (ex *Example) GetLabel() float32

GetLabel returns label

func (*Example) GetLoss added in v0.0.4

func (ex *Example) GetLoss() float32

GetLoss returns loss for the example

func (*Example) GetMultiClassPrediction added in v0.0.4

func (ex *Example) GetMultiClassPrediction() int

GetMultiClassPrediction returns prediction value for a multiclass prediction

func (*Example) GetPrediction

func (ex *Example) GetPrediction() float32

GetPrediction returns prediction

func (*Example) GetScalar added in v0.0.4

func (ex *Example) GetScalar(i int) float32

GetScalar returns the length of scalar predictions in the example

func (*Example) GetScalarLength added in v0.0.4

func (ex *Example) GetScalarLength() int

GetScalarLength returns the length of scalar predictions in the example

func (*Example) GetTag

func (ex *Example) GetTag() string

GetTag returns tag

func (*Example) GetTagLength

func (ex *Example) GetTagLength() int

GetTagLength returns tag length

func (*Example) GetTopicPrediction

func (ex *Example) GetTopicPrediction(i int) float32

GetTopicPrediction returns topic prediction for index

type ExampleList

type ExampleList []*Example

ExampleList a slice of examples

func (ExampleList) Finish

func (el ExampleList) Finish()

Finish all examples in the list

type PerformanceStatistics

type PerformanceStatistics struct {
	// Index of current pass
	CurrentPass uint64
	// The total number of features
	NumberOfFeatures uint64
	// Total number of examples
	NumberOfExamples uint64
	// The weighted sum of examples.
	WeightedExampleSum float64
	// The weighted sum of labels.
	WeightedLabelSum float64
	// The average loss since instance creation.
	AverageLoss float64
	// The best constant since instance creation.
	BestConstant float64
	// The best constant loss since instance creation.
	BestConstantLoss float64
}

PerformanceStatistics contains model performance stats

type VW

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

VW struct for a single Vowpal Wabbit model

Example
vw, _ := New("-q st --noconstant --quiet")
defer vw.Finish()

// Learn an example
ex, _ := vw.ReadExample("1 |s p^the_man w^the w^man |t p^un_homme w^un w^homme")
vw.Learn(ex)

// Predict with features
ex, _ = vw.ReadExample("|s p^the_man w^the w^man |t p^un_homme w^un w^homme")
res := vw.Predict(ex)

fmt.Printf("Prediction: %f", res)
Output:
Prediction: 0.855723

func New

func New(args string) (*VW, error)

New returns a new Vowpal Wabbit instance with given arguments

func NewWithModelData

func NewWithModelData(args string, modelData []byte) (*VW, error)

NewWithModelData returns new Vowpal Wabbit instance with model data

func NewWithSeed

func NewWithSeed(seedModel *VW, extraArgs string) (*VW, error)

NewWithSeed returns a new Vowpal Wabbit instance seeded with another model

func (*VW) CopyModelData

func (vw *VW) CopyModelData() []byte

CopyModelData returns model data as a byte slice

func (*VW) EndOfPass

func (vw *VW) EndOfPass() error

EndOfPass ends current pass and syncs metrics

func (*VW) EndParser

func (vw *VW) EndParser() error

EndParser ends the parser

func (*VW) Finish

func (vw *VW) Finish()

Finish stops VW (and, eg, write weights to disk)

func (*VW) FinishPasses

func (vw *VW) FinishPasses() error

FinishPasses finalize passes

func (*VW) Learn

func (vw *VW) Learn(ex *Example) float32

Learn learns a single example and returns the score

func (*VW) MultiLineLearn

func (vw *VW) MultiLineLearn(exs []*Example) error

MultiLineLearn learns from a list of example and returns the score

func (*VW) MultiLinePredict

func (vw *VW) MultiLinePredict(exs []*Example) error

MultiLinePredict predic using a list of examples

func (*VW) PerformanceStatistics

func (vw *VW) PerformanceStatistics() (PerformanceStatistics, error)

PerformanceStatistics writes current performance stats

func (*VW) Predict

func (vw *VW) Predict(ex *Example) float32

Predict returns a prediction using the example

func (*VW) PredictCostSensitive

func (vw *VW) PredictCostSensitive(ex *Example) float32

PredictCostSensitive returns a cost sensitive prediction using the example

func (*VW) ReadDecisionServiceJSON

func (vw *VW) ReadDecisionServiceJSON(json string) (ExampleList, error)

ReadDecisionServiceJSON reads examples from Decision Service JSON format

func (*VW) ReadDecisionServiceJSONFromBytes

func (vw *VW) ReadDecisionServiceJSONFromBytes(json []byte) (ExampleList, error)

ReadDecisionServiceJSONFromBytes like ReadDecisionServiceJSON but takes in a byte slice (need to be null terminated)

func (*VW) ReadExample

func (vw *VW) ReadExample(example string) (*Example, error)

ReadExample parses a single text based example

func (*VW) ReadJSON

func (vw *VW) ReadJSON(json string) (ExampleList, error)

ReadJSON reads examples from format

func (*VW) SaveModel

func (vw *VW) SaveModel()

SaveModel saves model to file given during construction

func (*VW) StartParser

func (vw *VW) StartParser() error

StartParser starts the parser

func (*VW) SyncStats

func (vw *VW) SyncStats() error

SyncStats syncs stats from the learner (should be called before vw.PerformanceStatistics)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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