tf.feature_column.crossed_column

Returns a column for performing crosses of categorical features.

Used in the notebooks

Used in the tutorials

Crossed features will be hashed according to hash_bucket_size. Conceptually, the transformation can be thought of as: Hash(cartesian product of features) % hash_bucket_size

For example, if the input features are:

  • SparseTensor referred by first key:

    shape = [2, 2]
    {
        [0, 0]: "a"
        [1, 0]: "b"
        [1, 1]: "c"
    }
    
  • SparseTensor referred by second key:

    shape = [2, 1]
    {
        [0, 0]: "d"
        [1, 0]: "e"
    }
    

then crossed feature will look like:

 shape = [2, 2]
{
    [0, 0]: Hash64("d", Hash64("a")) % hash_bucket_size
    [1, 0]: Hash64("e", Hash64("b")) % hash_bucket_size
    [1, 1]: Hash64("e", Hash64("c")) % hash_bucket_size
}

Here is an example to create a linear model with crosses of string features:

keywords_x_doc_terms = crossed_column(['keywords', 'doc_terms'], 50K)
colu