elasticdl icon indicating copy to clipboard operation
elasticdl copied to clipboard

support CategoryCrossing preprocessing layer

Open QiJune opened this issue 5 years ago • 0 comments

CategoryCrossing(PreprocessingLayer):
"""This layer transforms multiple categorical inputs to categorical outputs
   by Cartesian product, and hash the output if necessary.
   If any of the inputs is sparse, then all outputs will be sparse. Otherwise, all outputs will be dense."""

  def __init__(self, depth=None, num_bins=None, name=None, **kwargs):
    """Constructs a CategoryCrossing layer.
    Args:
      depth: depth of input crossing. By default None, all inputs are crossed
             into one output. It can be an int or tuple/list of ints, where inputs are
             combined into all combinations of output with degree of `depth`. For example,
             with inputs `a`, `b` and `c`, `depth=2` means the output will be [ab;ac;bc]
      num_bins: Number of hash bins. By default None, no hashing is performed.
      name: Name to give to the layer.
      **kwargs: Keyword arguments to construct a layer.

    Input: a list of int tensors of shape `[batch_size, d1, ..., dm]`
    Output: a single int tensor of shape `[batch_size, d1, ..., dm]`

    Example:
      If the layer receives two inputs, `a=[[1, 2]]` and `b=[[1, 3]]`, and
      if depth is 2, then the output will be a string tensor `[[b'1_X_1',
      b'1_X_3', b'2_X_1', b'2_X_3']]` if not hashed, or integer tensor
      `[[hash(b'1_X_1'), hash(b'1_X_3'), hash(b'2_X_1'), hash(b'2_X_3')]]` if hashed.
    """
    pass

QiJune avatar Apr 13 '20 12:04 QiJune