aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/derived/neuralnet/neuralnet.sd
blob: 371857be58b33794a78cd95fa30ad5722b61ea23 (plain) (blame)
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
schema neuralnet {

    document neuralnet {

        field uniqueRCount type double {
            indexing: attribute
        }

        field pinned type int {
            indexing: attribute
        }

        field createdAt type long {
            indexing: attribute
        }

        field updatedAt type long {
            indexing: attribute
        }

        field uvCount type int {
            indexing: attribute
        }

        field dvCount type int {
            indexing: attribute
        }

        field aVoteCount type int {
            indexing: attribute
        }

        field rCount type int {
            indexing: attribute
        }

        field uniqueRACount type int {
            indexing: attribute
        }

        field rTo type string {
            indexing: attribute
        }

        field markedAsAAt type long {
            indexing: attribute
        }

        field normalizedTextScore type float {
            indexing: attribute
        }

        field t type float {
            indexing: attribute
        }

        field relevance type float {
            indexing: attribute
        }

        field normalizedCS type float {
            indexing: attribute
        }

        field laAt type long {
            indexing: attribute
        }

        field hsScore type double {
            indexing: attribute
        }

    }

    rank-profile defaultRankProfile inherits default {

        constants {
            maxSignedSixtyFourBitInteger: 9223372036854775807
        }

         function log10_1p(x) {
            expression: log10(x+1)
        }

        function textScoreToUse() {
            expression: if(isNan(attribute(normalizedTextScore)) == 1, 0, attribute(normalizedTextScore))
        }

        function rCountToUse() {
            expression: if(isNan(attribute(rCount)) == 1, 0, if(attribute(rCount) < 0, 0, attribute(rCount)))
        }

        function uniqueRCountToUse() {
            expression: if(isNan(attribute(uniqueRCount)) == 1, 0, if(attribute(uniqueRACount) < 0, 0, attribute(uniqueRACount)))
        }

        function uvCountToUse() {
            expression: if(isNan(attribute(uvCount)) == 1, 0, if(attribute(uvCount) < 0, 0, attribute(uvCount)))
        }

        function dvCountToUse() {
            expression: if(isNan(attribute(dvCount)) == 1, 0, if(attribute(dvCount) < 0, 0, attribute(dvCount)))
        }

        function aVoteCountToUse() {
            expression: if(isNan(attribute(aVoteCount)) == 1, 0, if(attribute(aVoteCount) < 0, 0, attribute(aVoteCount)))
        }

        function totalPR() {
            expression: uniqueRCountToUse + query(voteToRRatio) * (uvCountToUse - dvCountToUse) - aVoteCountToUse
        }

        function totalvote() {
            expression: query(reportaweight) * aVoteCountToUse + dvCountToUse + query(rweight) * uniqueRCountToUse + uvCountToUse
        }

        function phat() {
            expression: if (totalvote == 0, 0, ( query(rweight) * uniqueRCountToUse + uvCountToUse) / totalvote)
        }

        function nCScoreToUse() {
            expression: if (totalPR > 0, log10(totalPR), 0)
        }

        function hsScoreToUse() {
            expression: attribute(hsScore)
        }

        function tScoreToUse() {
            expression: if (isNan(attribute(t)) == 1, 0.6, attribute(t))
        }

        function relevanceScoreToUse() {
            expression: if (isNan(attribute(relevance)) == 1, 0.254, attribute(relevance))
        }

        function freshnessToUse() {
            expression: if (freshness(createdAt).logscale < 0.01, 0.01, freshness(createdAt).logscale)
        }

        function rankedAt() {
            expression: now
        }

        function createdAtToUse() {
            expression: if(isNan(attribute(createdAt)) == 1, rankedAt, attribute(createdAt))
        }

        function laAtToUse() {
            expression: if(isNan(attribute(laAt)) == 1, attribute(createdAt), attribute(laAt))
        }

        function markedAsAAtToUse() {
            expression: if(isNan(attribute(markedAsAAt)) == 1, maxSignedSixtyFourBitInteger, attribute(markedAsAAt))
        }

        function tdToUse() {
            expression: pow(2, 0 - ((rankedAt - createdAtToUse) / query(decay)))
        }

        function commentOverallScore() {
            expression: query(textweight) * textScoreToUse  + query(communityweight) * nCScoreToUse
        }

        function pinScore() {
            expression: if(isNan(attribute(pinned)) == 1, 0, query(pinweight) * attribute(pinned))
        }

        function freshnessRank() {
            expression: nativeRank + freshness(createdAt)
        }

        first-phase {
            expression: nativeRank
        }

    }

    rank-profile neuralNetworkProfile inherits defaultRankProfile {
        function nn_input() {
            expression {
                concat(log10_1p(aVoteCountToUse),
                concat(log10_1p(dvCountToUse),
                concat(log10_1p(uniqueRCountToUse),
                concat(log10_1p(uvCountToUse),
                concat(phat,
                concat(log10_1p(totalvote),
                concat(hsScoreToUse,
                concat(tdToUse,
                tScoreToUse, x), x), x), x), x), x), x), x)
            }
        }

        function get_model_weights(field) {
            expression: if(query(field) == 0, constant(field), query(field))
        }

        function layer_0() {
            expression: elu(xw_plus_b(nn_input, get_model_weights(W_0), get_model_weights(b_0), x))
        }
        function layer_1() {
            expression: elu(xw_plus_b(layer_0, get_model_weights(W_1), get_model_weights(b_1), hidden))
        }
        function layer_out() {
            expression: sum(xw_plus_b(layer_1, get_model_weights(W_out), get_model_weights(b_out), out))
        }
        first-phase {
            expression: freshnessRank
        }
        second-phase {
            expression: layer_out
            rerank-count: 2000
        }

    }

    constant W_0 {
        file: neural-network-201805/W_0.json
        type: tensor(x[9],hidden[9])
    }
    constant b_0 {
        file: neural-network-201805/b_0.json
        type: tensor(hidden[9])
    }
    constant W_1 {
        file: neural-network-201805/W_1.json
        type: tensor(hidden[9],out[9])
    }
    constant b_1 {
        file: neural-network-201805/b_1.json
        type: tensor(out[9])
    }
    constant W_out {
        file: neural-network-201805/W_out.json
        type: tensor(out[9])
    }
    constant b_out {
        file: neural-network-201805/b_out.json
        type: tensor(out[1])
    }

}