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
|
search blog_post {
document blog_post {
field date_gmt type string {
indexing: summary
}
field language type string {
indexing: summary
}
field author type string {
indexing: summary
}
field url type string {
indexing: summary
}
field title type string {
indexing: summary | index
}
field blog type string {
indexing: summary
}
field post_id type string {
indexing: summary
}
field tags type array<string> {
indexing: summary
}
field blogname type string {
indexing: summary
}
field content type string {
indexing: summary | index
}
field categories type array<string> {
indexing: summary | index
}
field user_item_cf type tensor {
indexing: summary | attribute
attribute: tensor(user_item_cf[10])
}
field has_user_item_cf type byte {
indexing: summary | attribute
attribute: fast-search
}
}
rank-profile tensor {
first-phase {
expression {
sum(query(user_item_cf) * attribute(user_item_cf))
}
}
}
constant W_hidden {
file: constants/W_hidden.json
type: tensor(user_item_cf[20],hidden[40]) # user_item_cf
}
constant b_hidden {
file: constants/b_hidden.json
type: tensor(hidden[40])
}
constant W_final {
file: constants/W_final.json
type: tensor(hidden[40],prob_success[1])
}
constant b_final {
file: constants/b_final.json
type: tensor(prob_success[1])
}
# Temporary hack: requires x and y to be 0 padded
macro concat(x, y) {
expression: x + y
}
# Not valid. Needs to be a predefined function.
macro relu(x) {
expression: max(0, x) # 0 should be a constant tensor with 0 values
}
# Not valid. Needs to be predefined function.
macro sigmoid(x) {
expression: 1 / (1 + exp(-x))
}
macro matmul(x, y, dim) {
expression: sum(x * y, dim)
}
# The input to the neural network is the concatenation of the query and document vectors
macro nn_input() {
expression: concat(attribute(user_item_cf), query(user_item_cf))
}
macro hidden_layer() {
expression: relu(matmul(nn_input, constant(W_hidden), "user_item_cf") + constant(b_hidden))
}
macro final_layer() {
expression: sigmoid(matmul(hidden_layer, constant(W_final), "hidden") + constant(b_final))
}
rank-profile nn_tensor {
first-phase {
expression {
sum(final_layer)
}
}
}
}
|