-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathIntegerLookup.go
executable file
·177 lines (151 loc) · 3.96 KB
/
IntegerLookup.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package layer
import tf "github.com/galeone/tensorflow/tensorflow/go"
type LIntegerLookup struct {
dtype DataType
inputs []Layer
invert bool
maskToken interface{}
maxTokens interface{}
name string
numOovIndices float64
oovToken float64
outputMode string
padToMaxTokens bool
shape tf.Shape
sparse bool
trainable bool
vocabulary interface{}
layerWeights []*tf.Tensor
}
func IntegerLookup() *LIntegerLookup {
return &LIntegerLookup{
dtype: Int64,
invert: false,
maskToken: nil,
maxTokens: nil,
name: UniqueName("integer_lookup"),
numOovIndices: 1,
oovToken: -1,
outputMode: "int",
padToMaxTokens: false,
sparse: false,
trainable: true,
vocabulary: nil,
}
}
func (l *LIntegerLookup) SetDtype(dtype DataType) *LIntegerLookup {
l.dtype = dtype
return l
}
func (l *LIntegerLookup) SetInvert(invert bool) *LIntegerLookup {
l.invert = invert
return l
}
func (l *LIntegerLookup) SetMaskToken(maskToken interface{}) *LIntegerLookup {
l.maskToken = maskToken
return l
}
func (l *LIntegerLookup) SetMaxTokens(maxTokens interface{}) *LIntegerLookup {
l.maxTokens = maxTokens
return l
}
func (l *LIntegerLookup) SetName(name string) *LIntegerLookup {
l.name = name
return l
}
func (l *LIntegerLookup) SetNumOovIndices(numOovIndices float64) *LIntegerLookup {
l.numOovIndices = numOovIndices
return l
}
func (l *LIntegerLookup) SetOovToken(oovToken float64) *LIntegerLookup {
l.oovToken = oovToken
return l
}
func (l *LIntegerLookup) SetOutputMode(outputMode string) *LIntegerLookup {
l.outputMode = outputMode
return l
}
func (l *LIntegerLookup) SetPadToMaxTokens(padToMaxTokens bool) *LIntegerLookup {
l.padToMaxTokens = padToMaxTokens
return l
}
func (l *LIntegerLookup) SetShape(shape tf.Shape) *LIntegerLookup {
l.shape = shape
return l
}
func (l *LIntegerLookup) SetSparse(sparse bool) *LIntegerLookup {
l.sparse = sparse
return l
}
func (l *LIntegerLookup) SetTrainable(trainable bool) *LIntegerLookup {
l.trainable = trainable
return l
}
func (l *LIntegerLookup) SetVocabulary(vocabulary interface{}) *LIntegerLookup {
l.vocabulary = vocabulary
return l
}
func (l *LIntegerLookup) SetLayerWeights(layerWeights []*tf.Tensor) *LIntegerLookup {
l.layerWeights = layerWeights
return l
}
func (l *LIntegerLookup) GetShape() tf.Shape {
return l.shape
}
func (l *LIntegerLookup) GetDtype() DataType {
return l.dtype
}
func (l *LIntegerLookup) SetInputs(inputs ...Layer) Layer {
l.inputs = inputs
return l
}
func (l *LIntegerLookup) GetInputs() []Layer {
return l.inputs
}
func (l *LIntegerLookup) GetName() string {
return l.name
}
func (l *LIntegerLookup) GetLayerWeights() []*tf.Tensor {
return l.layerWeights
}
type jsonConfigLIntegerLookup struct {
ClassName string `json:"class_name"`
Name string `json:"name"`
Config map[string]interface{} `json:"config"`
InboundNodes [][][]interface{} `json:"inbound_nodes"`
}
func (l *LIntegerLookup) GetKerasLayerConfig() interface{} {
inboundNodes := [][][]interface{}{
{},
}
for _, input := range l.inputs {
inboundNodes[0] = append(inboundNodes[0], []interface{}{
input.GetName(),
0,
0,
map[string]bool{},
})
}
return jsonConfigLIntegerLookup{
ClassName: "IntegerLookup",
Name: l.name,
Config: map[string]interface{}{
"dtype": l.dtype.String(),
"invert": l.invert,
"mask_token": l.maskToken,
"max_tokens": l.maxTokens,
"name": l.name,
"num_oov_indices": l.numOovIndices,
"oov_token": l.oovToken,
"output_mode": l.outputMode,
"pad_to_max_tokens": l.padToMaxTokens,
"sparse": l.sparse,
"trainable": l.trainable,
"vocabulary": l.vocabulary,
},
InboundNodes: inboundNodes,
}
}
func (l *LIntegerLookup) GetCustomLayerDefinition() string {
return ``
}