summaryrefslogtreecommitdiffstats
path: root/sample-apps
diff options
context:
space:
mode:
authorLester Solbakken <lesters@yahoo-inc.com>2016-09-14 12:22:40 +0200
committerLester Solbakken <lesters@yahoo-inc.com>2016-09-14 12:22:40 +0200
commit55d5cf52ffb53f9f91a336b7f5f64e73a07864e5 (patch)
tree7b130b73710811f51c8577783091c9102f77ae71 /sample-apps
parent4bf517333b0616ce3e7947c28afb378cd10fe5c9 (diff)
Update blog post ranking for constant tensor tutorial
Diffstat (limited to 'sample-apps')
-rw-r--r--sample-apps/blog-recommendation/src/main/application/searchdefinitions/blog_post.sd60
1 files changed, 60 insertions, 0 deletions
diff --git a/sample-apps/blog-recommendation/src/main/application/searchdefinitions/blog_post.sd b/sample-apps/blog-recommendation/src/main/application/searchdefinitions/blog_post.sd
index 1b92822e425..d7d15045d9c 100644
--- a/sample-apps/blog-recommendation/src/main/application/searchdefinitions/blog_post.sd
+++ b/sample-apps/blog-recommendation/src/main/application/searchdefinitions/blog_post.sd
@@ -63,4 +63,64 @@ search blog_post {
}
}
+ 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)
+ }
+ }
+ }
+
}