# tf.contrib.layers.weighted_sparse_column

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/layers/python/layers/feature_column.py#L872-L915) |

Creates a _SparseColumn by combining sparse_id_column with a weight column.

    tf.contrib.layers.weighted_sparse_column(
        sparse_id_column, weight_column_name, dtype=tf.dtypes.float32
    )

#### Example:

    sparse_feature = sparse_column_with_hash_bucket(column_name="sparse_col",
                                                    hash_bucket_size=1000)
    weighted_feature = weighted_sparse_column(sparse_id_column=sparse_feature,
                                              weight_column_name="weights_col")

This configuration assumes that input dictionary of model contains the
following two items:

- (key="sparse_col", value=sparse_tensor) where sparse_tensor is a SparseTensor.
- (key="weights_col", value=weights_tensor) where weights_tensor is a SparseTensor. Following are assumed to be true:
  - sparse_tensor.indices = weights_tensor.indices
  - sparse_tensor.dense_shape = weights_tensor.dense_shape

<br />

<br />

<br />

| ## Args ||
|---|---|
| `sparse_id_column` | A `_SparseColumn` which is created by `sparse_column_with_*` functions. |
| `weight_column_name` | A string defining a sparse column name which represents weight or value of the corresponding sparse id feature. |
| `dtype` | Type of weights, such as [`tf.float32`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf#float32). Only floating and integer weights are supported. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A _WeightedSparseColumn composed of two sparse features: one represents id, the other represents weight (value) of the id feature in that example. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | if dtype is not convertible to float. |

<br />