-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTextVectorization.go
executable file
·169 lines (144 loc) · 4.22 KB
/
TextVectorization.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
package layer
import tf "github.com/galeone/tensorflow/tensorflow/go"
type LTextVectorization struct {
dtype DataType
inputs []Layer
maxTokens interface{}
name string
ngrams interface{}
outputMode string
outputSequenceLength interface{}
padToMaxTokens bool
shape tf.Shape
split string
standardize string
trainable bool
vocabulary interface{}
layerWeights []*tf.Tensor
}
func TextVectorization() *LTextVectorization {
return <extVectorization{
dtype: String,
maxTokens: nil,
name: UniqueName("text_vectorization"),
ngrams: nil,
outputMode: "int",
outputSequenceLength: nil,
padToMaxTokens: false,
split: "whitespace",
standardize: "lower_and_strip_punctuation",
trainable: true,
vocabulary: nil,
}
}
func (l *LTextVectorization) SetDtype(dtype DataType) *LTextVectorization {
l.dtype = dtype
return l
}
func (l *LTextVectorization) SetMaxTokens(maxTokens interface{}) *LTextVectorization {
l.maxTokens = maxTokens
return l
}
func (l *LTextVectorization) SetName(name string) *LTextVectorization {
l.name = name
return l
}
func (l *LTextVectorization) SetNgrams(ngrams interface{}) *LTextVectorization {
l.ngrams = ngrams
return l
}
func (l *LTextVectorization) SetOutputMode(outputMode string) *LTextVectorization {
l.outputMode = outputMode
return l
}
func (l *LTextVectorization) SetOutputSequenceLength(outputSequenceLength interface{}) *LTextVectorization {
l.outputSequenceLength = outputSequenceLength
return l
}
func (l *LTextVectorization) SetPadToMaxTokens(padToMaxTokens bool) *LTextVectorization {
l.padToMaxTokens = padToMaxTokens
return l
}
func (l *LTextVectorization) SetShape(shape tf.Shape) *LTextVectorization {
l.shape = shape
return l
}
func (l *LTextVectorization) SetSplit(split string) *LTextVectorization {
l.split = split
return l
}
func (l *LTextVectorization) SetStandardize(standardize string) *LTextVectorization {
l.standardize = standardize
return l
}
func (l *LTextVectorization) SetTrainable(trainable bool) *LTextVectorization {
l.trainable = trainable
return l
}
func (l *LTextVectorization) SetVocabulary(vocabulary interface{}) *LTextVectorization {
l.vocabulary = vocabulary
return l
}
func (l *LTextVectorization) SetLayerWeights(layerWeights []*tf.Tensor) *LTextVectorization {
l.layerWeights = layerWeights
return l
}
func (l *LTextVectorization) GetShape() tf.Shape {
return l.shape
}
func (l *LTextVectorization) GetDtype() DataType {
return l.dtype
}
func (l *LTextVectorization) SetInputs(inputs ...Layer) Layer {
l.inputs = inputs
return l
}
func (l *LTextVectorization) GetInputs() []Layer {
return l.inputs
}
func (l *LTextVectorization) GetName() string {
return l.name
}
func (l *LTextVectorization) GetLayerWeights() []*tf.Tensor {
return l.layerWeights
}
type jsonConfigLTextVectorization struct {
ClassName string `json:"class_name"`
Name string `json:"name"`
Config map[string]interface{} `json:"config"`
InboundNodes [][][]interface{} `json:"inbound_nodes"`
}
func (l *LTextVectorization) GetKerasLayerConfig() interface{} {
inboundNodes := [][][]interface{}{
{},
}
for _, input := range l.inputs {
inboundNodes[0] = append(inboundNodes[0], []interface{}{
input.GetName(),
0,
0,
map[string]bool{},
})
}
return jsonConfigLTextVectorization{
ClassName: "TextVectorization",
Name: l.name,
Config: map[string]interface{}{
"dtype": l.dtype.String(),
"max_tokens": l.maxTokens,
"name": l.name,
"ngrams": l.ngrams,
"output_mode": l.outputMode,
"output_sequence_length": l.outputSequenceLength,
"pad_to_max_tokens": l.padToMaxTokens,
"split": l.split,
"standardize": l.standardize,
"trainable": l.trainable,
"vocabulary": l.vocabulary,
},
InboundNodes: inboundNodes,
}
}
func (l *LTextVectorization) GetCustomLayerDefinition() string {
return ``
}