Tensorflow功能列用于变量值列表 [英] Tensorflow feature column for variable list of values
问题描述
从TensorFlow文档中可以很明显地看出如何使用tf.feature_column.categorical_column_with_vocabulary_list
创建功能列,该功能列将一些字符串作为输入并输出一个热向量.例如
From the TensorFlow docs it's clear how to use tf.feature_column.categorical_column_with_vocabulary_list
to create a feature column which takes as input some string and outputs a one-hot vector. For example
vocabulary_feature_column =
tf.feature_column.categorical_column_with_vocabulary_list(
key="vocab_feature",
vocabulary_list=["kitchenware", "electronics", "sports"])
比方说,"kitchenware"
映射到[1,0,0]
,而"electronics"
映射到[0,1,0]
.我的问题与将字符串列表作为一项功能有关.例如,如果特征值为["kitchenware","electronics"]
,则所需的输出将为[1,1,0]
.输入列表的长度不是固定的,但输出尺寸是固定的.
Let's say "kitchenware"
maps to [1,0,0]
and "electronics"
maps to [0,1,0]
. My question is related to having a list of strings as a feature. For example, if the feature value was ["kitchenware","electronics"]
then the desired output would be [1,1,0]
. The input list length is not fixed but the output dimension is.
用例是一个直接的单词袋型模型(显然具有更大的词汇表!).
The use case is a straight bag-of-words type model (obviously with a much larger vocabulary list!).
实现此目的的正确方法是什么?
What is the correct way to implement this?
推荐答案
您应该使用tf.feature_column.indicator_column 参见 https://www.tensorflow.org/versions/master /api_docs/python/tf/feature_column/indicator_column
you should use tf.feature_column.indicator_column see https://www.tensorflow.org/versions/master/api_docs/python/tf/feature_column/indicator_column
这篇关于Tensorflow功能列用于变量值列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!