shenweichen / DeepMatch

A deep matching model library for recommendations & advertising. It's easy to train models and to export representation vectors which can be used for ANN search.
https://deepmatch.readthedocs.io/en/latest/
Apache License 2.0
2.22k stars 530 forks source link

同想问下youtubednn下EmbeddingIndex的用法 #52

Closed xxxftian closed 2 years ago

xxxftian commented 3 years ago

Describe the question(问题描述) class EmbeddingIndex(Layer):

def __init__(self, index, **kwargs):
    self.index = index
    super(EmbeddingIndex, self).__init__(**kwargs)

def build(self, input_shape):
    super(EmbeddingIndex, self).build(
        input_shape)  # Be sure to call this somewhere!

def call(self, x, **kwargs):
    return tf.constant(self.index)

def get_config(self, ):
    config = {'index': self.index, }
    base_config = super(EmbeddingIndex, self).get_config()
    return dict(list(base_config.items()) + list(config.items()))

看起来该层只是返回了index的list,但是实际中如果不使用EmbeddingIndex直接获取index的list,会报出mask的某种错误,具体如下:TypeError: Layer sampled_softmax_layer does not support masking, but was passed an input_mask: [<tf.Tensor 'sparse_seq_emb_hist_item_id_1/NotEqual:0' shape=(14781,) dtype=bool>, None, None]

有没有大佬分析一下

Operating environment(运行环境):

ninesky110 commented 3 years ago

我也有点疑问

FanWan commented 3 years ago

感觉就是把index转成了tensor 吗 ?没看出有其他的用途啊