A tf.contrib.layers style input layer builder based on FeatureColumns.
tf.contrib.layers.input_from_feature_columns( columns_to_tensors, feature_columns, weight_collections=None, trainable=True, scope=None, cols_to_outs=None )
Generally a single example in training data is described with feature columns. At the first layer of the model, this column oriented data should be converted to a single tensor. Each feature column needs a different kind of operation during this conversion. For example sparse features need a totally different handling than continuous features.
# Building model for training columns_to_tensor = tf.io.parse_example(...) first_layer = input_from_feature_columns( columns_to_tensors=columns_to_tensor, feature_columns=feature_columns) second_layer = fully_connected(inputs=first_layer, ...) ...
where feature_columns can be defined as follows:
sparse_feature = sparse_column_with_hash_bucket( column_name="sparse_col", ...) sparse_feature_emb = embedding_column(sparse_id_column=sparse_feature, ...) real_valued_feature = real_valued_column(...) real_valued_buckets = bucketized_column( source_column=real_valued_feature, ...) feature_columns=[sparse_feature_emb, real_valued_buckets]
columns_to_tensors: A mapping from feature column to tensors. 'string' key means a base feature (not-transformed). It can have FeatureColumn as a key too. That means that FeatureColumn is already transformed by input pipeline.
feature_columns: A set containing all the feature columns. All items in the set should be instances of classes derived by FeatureColumn.
weight_collections: List of graph collections to which weights are added.
Truealso add variables to the graph collection
scope: Optional scope for variable_scope.
cols_to_outs: Optional dict from feature column to output tensor, which is concatenated into the returned tensor.
A Tensor which can be consumed by hidden layers in the neural network.
ValueError: if FeatureColumn cannot be consumed by a neural network.