我一直在使用tensorflow中的数据集和feature_columns(https://developers.googleblog.com/2017/11/introducing-tensorflow-feature-columns.html).我发现它们具有分类功能以及从分类功能创建嵌入功能的方法.但是在处理nlp任务时,我们如何创建单个嵌入查找?
例如:考虑文本分类任务.每个数据点都有很多文本列,但它们不是单独的类别.我们如何为所有这些列创建和使用单个嵌入查找?
下面是我目前如何使用嵌入功能的示例.我正在为每列构建一个分类功能,并使用它来创建嵌入.问题是对于不同的列,相同单词的嵌入可能不同.
def create_embedding_features(key, vocab_list=None, embedding_size=20):
cat_feature = \
tf.feature_column.categorical_column_with_vocabulary_list(
key=key,
vocabulary_list = vocab_list
)
embedding_feature = tf.feature_column.embedding_column(
categorical_column = cat_feature,
dimension = embedding_size
)
return embedding_feature
le_features_embd = [create_embedding_features(f, vocab_list=vocab_list)
for f in feature_keys]
Run Code Online (Sandbox Code Playgroud)