forked from taufik-rama/fasttext-go-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fasttext_test.go
76 lines (65 loc) · 1.52 KB
/
fasttext_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package fasttext
import (
"fmt"
"testing"
)
func TestPredict(t *testing.T) {
model, err := New("test_data/clf.bin")
if err != nil {
t.Errorf("error loading model: %v", err)
}
pred := model.Predict("платье", 10, 0.0)
for _, pred := range pred {
t.Logf(pred.Label)
t.Logf(fmt.Sprintf("%f", pred.Prob))
}
}
func TestGetDimension(t *testing.T) {
model, err := New("test_data/model.bin")
if err != nil {
t.Errorf("error loading model: %v", err)
}
d, err := model.GetDimension()
if err != nil {
t.Errorf("error getting dimension: %v", err)
}
if d != 100 {
t.Errorf("wrong dimension")
}
}
func TestSaveModel(t *testing.T) {
var newFileName = "test_data/model_.bin"
model, err := New("test_data/model.bin")
if err != nil {
t.Errorf("error loading model: %v", err)
}
err = model.SaveModel(newFileName)
if err != nil {
t.Errorf("error writing to a file: %v: %v", newFileName, err)
}
}
func TestTrain(t *testing.T) {
var (
modelType = "supervised"
inputFileName = "test_data/train"
outputFileName = "test_data/context"
epoch = 10
wordNGrams = 2
thread = 10
lr = 0.1
)
err := Train(modelType, inputFileName, outputFileName, epoch, wordNGrams, thread, lr)
if err != nil {
t.Errorf("error training model: %v", err)
}
}
func TestQuantize(t *testing.T) {
var (
inputFileName = "test_data/context.bin"
outputFileName = "test_data/context"
)
err := Quantize(inputFileName, outputFileName)
if err != nil {
t.Errorf("error training model: %v", err)
}
}