Exemplo n.º 1
0
// Lots of goofing around
// Initially intended to match the Python test.py
// From https://github.com/JohnLangford/vowpal_wabbit/blob/master/python/test.py
func main() {
	h := vw.Initialize("-q st --noconstant --quiet")
	//example := ReadExample(vw, "1 |s p^the_man w^the w^man |t p^un_homme w^un w^homme")
	example := vw.ReadExample(h, "1 |x a b")
	score := vw.Learn(h, example)
	ex2 := vw.ReadExample(h, "1 |x a b |y c")
	vw.Learn(h, ex2)
	fmt.Printf("[1 Learns] Pred = %v\n", ex2.GetPrediction())
	vw.Learn(h, ex2)
	fmt.Printf("[2 Learns] Pred = %v\n", ex2.GetPrediction())
	vw.Learn(h, ex2)
	fmt.Printf("[3 Learns] Pred = %v\n", ex2.GetPrediction())
	vw.Learn(h, ex2)
	fmt.Printf("[4 Learns] Pred = %v\n", ex2.GetPrediction())
	pred := ex2.GetPrediction()
	imp := ex2.GetImportance()
	featHash := h.HashFeature("a", 42)
	fmt.Printf("Num Features: %v\n", ex2.GetNumFeatures())
	fmt.Printf("Loss: %v\n", ex2.GetLoss())
	fmt.Printf("GetSimpleLabelPrediction: %v\n", ex2.GetSimpleLabelPrediction())
	fmt.Printf("GetSimpleLabelLabel: %v\n", ex2.GetSimpleLabelLabel())
	//fmt.Printf("GetUpdatedPrediction: %v\n", ex2.GetUpdatedPrediction())
	fmt.Printf("GetSumLoss: %v\n", h.GetSumLoss())
	h.Finish()
	fmt.Printf("Score = %v Pred: %v Importance: %v FeatHash: %v\n", score, pred, imp, featHash)
}
Exemplo n.º 2
0
func main() {
	h := vw.Initialize("-q st --noconstant")

	iters := 20
	for i := 0; i < iters; i++ {
		good_score := h.LearnString("1 | good")
		bad_score := h.LearnString("-1 | bad")
		fmt.Printf("I: %2d GoodScore: %6.3f BadScore: %6.3f\n", i, good_score, bad_score)
	}

	fmt.Printf("Should be good (1): %v\n", h.LearnString("-1 1 | good"))
	fmt.Printf("Should be bad (-1): %v\n", h.LearnString("-1 1 | bad"))

	h.Finish()
}