transform

old TransE-like models
git clone https://esimon.eu/repos/transform.git
Log | Files | Refs | README

commit a716989c34d296492ae87b6e0c1537897b5a62ce
parent b2ffb7551c1382ae3ac9eb72dd569d63f79bb0bd
Author: Étienne Simon <esimon@esimon.eu>
Date:   Fri, 18 Apr 2014 17:49:18 +0200

Add & Fix similarity functions

Diffstat:
Mmodel.py | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/model.py b/model.py @@ -11,10 +11,15 @@ import theano.sparse as S from embeddings import * def L1_norm(l, r): - return T.sum(abs(l-r), axis=1) + return -T.sum(abs(l-r), axis=1) def L2_norm(l, r): - return T.sqrt(T.sum(T.sqr(l-r), axis=1)) + return -T.sqrt(T.sum(T.sqr(l-r), axis=1)) + +def cosine(l, r): + l_norm = T.sum(T.sqr(l), axis=1) + r_norm = T.sum(T.sqr(r), axis=1) + return T.sum(l*r, axis=1) / (l_norm*r_norm) class Model(object): """ Model class.