{"action":"created","issue":{"url":"https://api.github.com/repos/fchollet/keras/issues/878","labels_url":"https://api.github.com/repos/fchollet/keras/issues/878/labels{/name}","comments_url":"https://api.github.com/repos/fchollet/keras/issues/878/comments","events_url":"https://api.github.com/repos/fchollet/keras/issues/878/events","html_url":"https://github.com/fchollet/keras/issues/878","id":112958157,"number":878,"title":"What would be the output shape of cosine/dot product merge of 2 layers?","user":{"login":"farizrahman4u","id":11006006,"avatar_url":"https://avatars.githubusercontent.com/u/11006006?v=3","gravatar_id":"","url":"https://api.github.com/users/farizrahman4u","html_url":"https://github.com/farizrahman4u","followers_url":"https://api.github.com/users/farizrahman4u/followers","following_url":"https://api.github.com/users/farizrahman4u/following{/other_user}","gists_url":"https://api.github.com/users/farizrahman4u/gists{/gist_id}","starred_url":"https://api.github.com/users/farizrahman4u/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/farizrahman4u/subscriptions","organizations_url":"https://api.github.com/users/farizrahman4u/orgs","repos_url":"https://api.github.com/users/farizrahman4u/repos","events_url":"https://api.github.com/users/farizrahman4u/events{/privacy}","received_events_url":"https://api.github.com/users/farizrahman4u/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-23T05:55:57Z","updated_at":"2015-10-23T09:26:07Z","closed_at":null,"body":"I am trying to add 2 new merge modes, cosine and dot:\r\n\r\n#cosine merge:\r\n\r\nelif self.mode == 'cos':\r\n            l1 = self.layers[0].get_output(train)\r\n            l2 = self.layers[1].get_output(train)\r\n            output, _ = theano.scan(lambda v1,v2 : T.dot(v1,v2)/T.sqrt(T.dot(v1,v1) * T.dot(v2,v2)) , sequences= [r1, r2], outputs_info = None)\r\n            return output            \r\n\r\n\r\n#dot merge:\r\nelif self.mode == 'dot':\r\n            l1 = self.layers[0].get_output(train)\r\n            l2 = self.layers[1].get_output(train)\r\n            output, _ = theano.scan(lambda v1,v2 : T.dot(v1,v2), sequences= [r1, r2], outputs_info = None)\r\n            return output            \r\nelse:\r\n            raise Exception('Unknown merge mode')\r\n\r\n\r\nWhat would be their corresponding output shapes?"},"comment":{"url":"https://api.github.com/repos/fchollet/keras/issues/comments/150526571","html_url":"https://github.com/fchollet/keras/issues/878#issuecomment-150526571","issue_url":"https://api.github.com/repos/fchollet/keras/issues/878","id":150526571,"user":{"login":"dbonadiman","id":1776151,"avatar_url":"https://avatars.githubusercontent.com/u/1776151?v=3","gravatar_id":"","url":"https://api.github.com/users/dbonadiman","html_url":"https://github.com/dbonadiman","followers_url":"https://api.github.com/users/dbonadiman/followers","following_url":"https://api.github.com/users/dbonadiman/following{/other_user}","gists_url":"https://api.github.com/users/dbonadiman/gists{/gist_id}","starred_url":"https://api.github.com/users/dbonadiman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbonadiman/subscriptions","organizations_url":"https://api.github.com/users/dbonadiman/orgs","repos_url":"https://api.github.com/users/dbonadiman/repos","events_url":"https://api.github.com/users/dbonadiman/events{/privacy}","received_events_url":"https://api.github.com/users/dbonadiman/received_events","type":"User","site_admin":false},"created_at":"2015-10-23T09:26:07Z","updated_at":"2015-10-23T09:26:07Z","body":"It depends on the shape of the inputs, however if the input is the output of two  Dense layer the scan dot output is.\r\n\r\n(Batch_size , 1) that is basically the same size of \r\n```\r\noutput_shape = (l1.output_shape[0], 1)\r\n```\r\n\r\nI found really funny that you asked this today just 3 hours later i implemented a first naive implementation of the same thing.\r\nBy the way you can use the batched dot to do the trick and remember to dimshuffle the output since the output shape of the function is always a vector in the form (Batch_size,) but you need (Batch_size, 1).\r\n\r\nHere is my code, is not ready to pull i just checking everything is fine:\r\n\r\nhttps://github.com/dbonadiman/keras/blob/debugging-dot/keras/layers/core.py#L336"}}