-
Notifications
You must be signed in to change notification settings - Fork 16
/
modeling_test.go
83 lines (76 loc) · 2.13 KB
/
modeling_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
77
78
79
80
81
82
83
package transformer_test
import (
"reflect"
"testing"
"github.com/sugarme/transformer"
"github.com/sugarme/transformer/bert"
)
// With model name
func TestModelFromPretrained_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)
}
}
// With local file
/*
* // No custom params
* func TestModelFromPretrained(t *testing.T) {
* // bertURL := transformer.AllPretrainedConfigs["bert-base-uncased"]
* url := "https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-uncased-config.json"
*
* var config *bert.BertConfig = new(bert.BertConfig)
* err := transformer.LoadConfig(config, url, 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 TestModelFromPretrained_CustomParams(t *testing.T) {
* url := "https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-uncased-config.json"
*
* params := map[string]interface{}{
* "VocabSize": int64(2000),
* "NumLabels": int64(4),
* }
*
* var config *bert.BertConfig = new(bert.BertConfig)
* err := transformer.LoadConfig(config, url, 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)
* }
* } */