![]() |
Uses a Module to construct dense representations from sparse text features.
hub.sparse_text_embedding_column(
key, module_spec, combiner, default_value, trainable=False
)
The input to this feature column is a batch of multiple strings with arbitrary size, assuming the input is a SparseTensor.
This type of feature column is typically suited for modules that operate on pre-tokenized text to produce token level embeddings which are combined with the combiner into a text embedding. The combiner always treats the tokens as a bag of words rather than a sequence.
The output (i.e., transformed input layer) is a DenseTensor, with shape [batch_size, num_embedding_dim].
For Example:
comment = hub.sparse_text_embedding_column("comment", "/tmp/text_module")
feature_columns = [comment, ...]
...
features = {
"comment": tf.SparseTensor(indices=[[0, 0], [1, 2]],
values=['sparse', 'embedding'],
dense_shape=[3, 4]),
...
}
estimator = tf.estimator.DNNClassifier(hidden_units, feature_columns)
Returns | |
---|---|
_DenseColumn that converts from text input.
|
Raises | |
---|---|
ValueError
|
if module_spec is not suitable for use in this feature column. |
ValueError
|
if combiner not in ('mean', 'sqrtn', 'sum'). |