问题描述
我正在尝试在Tensorflow 2.3中实现skip-gram模型 可以请人确认我的实现是否良好,或者模型是否存在缺陷?
import tensorflow as tf
class word2vec_tf(tf.keras.Model):
def __init__(self,embedding_size,vocab_size,noise_dist = None,negative_samples = 10):
super(MyModel,self).__init__()
self.embeddings_input = tf.keras.layers.Embedding(vocab_size,embeddings_initializer='uniform',mask_zero=False)
self.embeddings_context = tf.keras.layers.Embedding(vocab_size,mask_zero=False)
self.vocab_size = vocab_size
self.negative_samples = negative_samples
self.noise_dist = noise_dist
def call(self,input_word,context_word):
##### computing out loss #####
emb_input = self.embeddings_input(input_word) # bs,emb_dim
emb_context = self.embeddings_context(context_word) # bs,emb_dim
# POSITIVE SAMPLES
emb_product = tf.keras.layers.dot([emb_input,emb_context],axes=(1,1))# bs
out_loss = tf.squeeze(tf.math.log_sigmoid(emb_product),axis = 1)
return tf.reduce_mean(tf.math.negative(out_loss))
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)