背景
使用feature_column可以非常方便的实现shared_embedding
tf.feature_column.shared_embedding_columns(shared_column_list, iembedding_size)
但是换成keras后,没有相应的接口。
查找资料,实现了共享embedding
核心代码
from keras.layers import Input, Embedding
first_input = Input(shape = (your_shape_tuple) )
second_input = Input(shape = (your_shape_tuple) )
...
embedding_layer = Embedding(embedding_size)
first_input_encoded = embedding_layer(first_input)
second_input_encoded = embedding_layer(second_input)
Embedding的实现
import tensorflow as tf
t