diff options
author | Lester Solbakken <lesters@yahoo-inc.com> | 2016-09-14 14:09:40 +0200 |
---|---|---|
committer | Lester Solbakken <lesters@yahoo-inc.com> | 2016-09-14 14:09:40 +0200 |
commit | e4e489dfdca58eaf500b81de121d76b98a008423 (patch) | |
tree | d58c9aee3de6e048ff6b341e3f056ec27873742d /sample-apps/blog-recommendation | |
parent | 55d5cf52ffb53f9f91a336b7f5f64e73a07864e5 (diff) |
Change to matmul for tensor concatenation
Diffstat (limited to 'sample-apps/blog-recommendation')
3 files changed, 50 insertions, 13 deletions
diff --git a/sample-apps/blog-recommendation/src/main/application/constants/input_transform_1.json b/sample-apps/blog-recommendation/src/main/application/constants/input_transform_1.json new file mode 100644 index 00000000000..c28dbf49ddf --- /dev/null +++ b/sample-apps/blog-recommendation/src/main/application/constants/input_transform_1.json @@ -0,0 +1,14 @@ +{ + "cells": [ + { "address": { "user_item_cf": "0", "input": "10"}, "value": 1.0 }, + { "address": { "user_item_cf": "1", "input": "11"}, "value": 1.0 }, + { "address": { "user_item_cf": "2", "input": "12"}, "value": 1.0 }, + { "address": { "user_item_cf": "3", "input": "13"}, "value": 1.0 }, + { "address": { "user_item_cf": "4", "input": "14"}, "value": 1.0 }, + { "address": { "user_item_cf": "5", "input": "15"}, "value": 1.0 }, + { "address": { "user_item_cf": "6", "input": "16"}, "value": 1.0 }, + { "address": { "user_item_cf": "7", "input": "17"}, "value": 1.0 }, + { "address": { "user_item_cf": "8", "input": "18"}, "value": 1.0 }, + { "address": { "user_item_cf": "9", "input": "19"}, "value": 1.0 } + ] +} diff --git a/sample-apps/blog-recommendation/src/main/application/constants/input_transform_2.json b/sample-apps/blog-recommendation/src/main/application/constants/input_transform_2.json new file mode 100644 index 00000000000..e4d5d88baf8 --- /dev/null +++ b/sample-apps/blog-recommendation/src/main/application/constants/input_transform_2.json @@ -0,0 +1,14 @@ +{ + "cells": [ + { "address": { "user_item_cf": "0", "input": "0"}, "value": 1.0 }, + { "address": { "user_item_cf": "1", "input": "1"}, "value": 1.0 }, + { "address": { "user_item_cf": "2", "input": "2"}, "value": 1.0 }, + { "address": { "user_item_cf": "3", "input": "3"}, "value": 1.0 }, + { "address": { "user_item_cf": "4", "input": "4"}, "value": 1.0 }, + { "address": { "user_item_cf": "5", "input": "5"}, "value": 1.0 }, + { "address": { "user_item_cf": "6", "input": "6"}, "value": 1.0 }, + { "address": { "user_item_cf": "7", "input": "7"}, "value": 1.0 }, + { "address": { "user_item_cf": "8", "input": "8"}, "value": 1.0 }, + { "address": { "user_item_cf": "9", "input": "9"}, "value": 1.0 } + ] +} 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 d7d15045d9c..9011a559f1e 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 @@ -65,7 +65,7 @@ search blog_post { constant W_hidden { file: constants/W_hidden.json - type: tensor(user_item_cf[20],hidden[40]) # user_item_cf + type: tensor(input[20],hidden[40]) # user_item_cf } constant b_hidden { @@ -75,17 +75,26 @@ search blog_post { constant W_final { file: constants/W_final.json - type: tensor(hidden[40],prob_success[1]) + type: tensor(hidden[40], final[1]) } constant b_final { file: constants/b_final.json - type: tensor(prob_success[1]) + type: tensor(final[1]) } - # Temporary hack: requires x and y to be 0 padded - macro concat(x, y) { - expression: x + y + constant input_transform_1 { + file: constants/input_transform_1.json + type: tensor(user_item_cf[10], input[20]) + } + + constant input_transform_2 { + file: constants/input_transform_2.json + type: tensor(user_item_cf[10], input[20]) + } + + macro matmul(x, y, dim) { + expression: sum(x * y, dim) } # Not valid. Needs to be a predefined function. @@ -98,17 +107,17 @@ search blog_post { 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 + # The input to the neural network is the concatenation of the document and query vectors macro nn_input() { - expression: concat(attribute(user_item_cf), query(user_item_cf)) + expression { + matmul(attribute(user_item_cf), constant(input_transform_1), "user_item_cf") + + + matmul(query(user_item_cf), constant(input_transform_2), "user_item_cf") + } } macro hidden_layer() { - expression: relu(matmul(nn_input, constant(W_hidden), "user_item_cf") + constant(b_hidden)) + expression: relu(matmul(nn_input, constant(W_hidden), "input") + constant(b_hidden)) } macro final_layer() { |