forked from sugarme/transformer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
75 lines (60 loc) · 1.7 KB
/
config_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
package transformer_test
import (
"reflect"
"testing"
"github.com/sugarme/transformer"
"github.com/sugarme/transformer/bert"
)
// With model name
func TestConfigFromPretrained_ModelName(t *testing.T) {
modelName := "bert-base-uncased"
var config *bert.BertConfig = new(bert.BertConfig)
err := transformer.LoadConfig(config, modelName, nil)
if err != nil {
t.Error(err)
}
wantVocabSize := int64(30522)
gotVocabSize := config.VocabSize
if !reflect.DeepEqual(wantVocabSize, gotVocabSize) {
t.Errorf("Want: %v\n", wantVocabSize)
t.Errorf("Got: %v\n", gotVocabSize)
}
}
// No custom params
func TestConfigFromPretrained(t *testing.T) {
var config *bert.BertConfig = new(bert.BertConfig)
err := transformer.LoadConfig(config, "bert-base-uncased", nil)
if err != nil {
t.Error(err)
}
wantVocabSize := int64(30522)
gotVocabSize := config.VocabSize
if !reflect.DeepEqual(wantVocabSize, gotVocabSize) {
t.Errorf("Want: %v\n", wantVocabSize)
t.Errorf("Got: %v\n", gotVocabSize)
}
}
// With custom params
func TestConfigFromPretrained_CustomParams(t *testing.T) {
params := map[string]interface{}{
"VocabSize": int64(2000),
"NumLabels": int64(4),
}
var config *bert.BertConfig = new(bert.BertConfig)
err := transformer.LoadConfig(config, "bert-base-uncased", params)
if err != nil {
t.Error(err)
}
wantVocabSize := int64(2000)
gotVocabSize := config.VocabSize
if !reflect.DeepEqual(wantVocabSize, gotVocabSize) {
t.Errorf("Want: %v\n", wantVocabSize)
t.Errorf("Got: %v\n", gotVocabSize)
}
wantNumLabels := int64(4)
gotNumLabels := config.NumLabels
if !reflect.DeepEqual(wantNumLabels, gotNumLabels) {
t.Errorf("Want: %v\n", wantNumLabels)
t.Errorf("Got: %v\n", gotNumLabels)
}
}