"model/tests/matomo.js" did not exist on "4f091f6583359381fd640b15d9614ebb8169de1c"
Commit d81313dd authored by Maciej Skorski's avatar Maciej Skorski

adding code and simple tests

parent 488b5a19
# Fast Word2Vec TF # Fast Word2Vec TF
Fast implementation of Word2Vec in Tensorflow Fast implementation of Word2Vec in Tensorflow
## Run Tests
fast_TF_Word2Vec$python3 -m model.tests.test
\ No newline at end of file
from .core.model import *
import tensorflow as tf
def logp(x,y,embedx,embedy,device='/device:GPU:0'):
with tf.device(device):
# embeded vectors: x is central and y is context
y_embed = tf.gather(embedy,y) # (N_BATCH,N_DIM)
x_embed = tf.gather(embedx,x) # (N_BATCH,N_DIM)
# logprob of (y,x) and of (x,)
yx_logp = tf.squeeze( tf.matmul(tf.expand_dims(x_embed,1),tf.expand_dims(y_embed,-1)) ) # (N_BATCH,)
x_logp = tf.matmul(embedy,tf.transpose(x_embed)) # (N_WORDS,N_BATCH)
x_logp = tf.reduce_logsumexp(x_logp,axis=0) # (N_BATCH,)
# logprob of (y|x)
y_x_logp = yx_logp - x_logp # (N_BATCH,1)
logp = tf.reduce_mean(y_x_logp)
return logp
\ No newline at end of file
import unittest
from ..core.model import *
class TestTensorflowSetup(unittest.TestCase):
def test_version2x(self):
self.assertTrue(tf.version.VERSION.startswith('2'))
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment