What's the difference between shared embedding and embedding with multi-hot input in Keras

Suppose the input is a index of 3 items such as (1,2,3), I want to get 3 embedding vector corresponding to the 3 items and then get the average of 3 vectors. Here are two method:

method 1:

item1_input = Input(shape=(1,), dtype='int32', name = 'item1_input')
item2_input = Input(shape=(1,), dtype='int32', name = 'item2_input')
item3_input = Input(shape=(1,), dtype='int32', name = 'item3_input')

Embedding_Item = Embedding(input_dim = num_items, output_dim = layers[0]/2, name = 'item_embedding',init = init_normal, W_regularizer = l2(reg_layers[0]), input_length=1)

item1_latent = Flatten()(Embedding_Item(item1_input))
item2_latent = Flatten()(Embedding_Item(item2_input))
item3_latent = Flatten()(Embedding_Item(item3_input))

itemset_latent = merge([item1_latent, item2_latent, item3_latent], mode = 'ave')

which uses a shared embbedings to get 3 vectors.

method 2:

item_input = Input(shape=(3,), dtype='int32', name = 'item_input')

Embedding_Item = Embedding(input_dim = num_items+1, output_dim = layers[0]/2, name = 'item_embedding',
                              init = init_normal, W_regularizer = l2(reg_layers[0]), input_length=3, mask_zero=True)


item_zeroed = ZeroMaskedEntries()(Embedding_Item(item_input))
lambda_mean = Lambda(mask_aware_mean,mask_aware_mean_output_shape)(item_zeroed)

which use a lambda layer to get the average value of the 3 item embeddings from the same embedding layer.(copied from the question Average of non-zero word embeddings [https://github.com/keras-team/keras/issues/1579])

Question: Is there any difference between the two method? What's the differences if there exits?

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值