# block_zoo.embedding package

## Submodules

## block_zoo.embedding.CNNCharEmbedding module

class `block_zoo.embedding.CNNCharEmbedding.``CNNCharEmbedding`(layer_conf)

  Bases: `block_zoo.BaseLayer.BaseLayer`

  This layer implements the character embedding use CNN :param layer_conf: configuration of CNNCharEmbedding :type layer_conf: CNNCharEmbeddingConf

  `forward`(string)

    Step1: [batch_size, seq_len, char num in words] -> [batch_size, seq_len * char num in words] Step2: lookup embedding matrix -> [batch_size, seq_len * char num in words, embedding_dim] reshape -> [batch_size * seq_len, char num in words, embedding_dim] Step3: after convolution operation, got [batch_size * seq_len, char num related, output_channel_num] Step4: max pooling on axis 1 and -reshape-> [batch_size * seq_len, output_channel_dim] Step5: reshape -> [batch_size, seq_len, output_channel_dim]

    Parameters: | string (Variable) – [[char ids of word1], [char ids of word2], […], …], shape: [batch_size, seq_len, char num in words]
    Returns: | [batch_size, seq_len, output_dim]
    Return type: | Variable

class `block_zoo.embedding.CNNCharEmbedding.``CNNCharEmbeddingConf`(**kwargs)

  Bases: `block_zoo.BaseLayer.BaseConf`

  Configuration of CNNCharEmbedding

  Parameters: | dim (int, optional) – the dimension of character embedding after convolution. Default: 30 embedding_matrix_dim (int, optional) – the dimension of character initialized embedding. Default: 30 stride (int, optional) – Stride of the convolution. Default: 1 padding (int, optional) – Zero-padding added to both sides of the input. Default: 0 window_size (int, optional) – width of convolution kernel. Default: 3 activation (Str, optional) – activation after convolution operation, can set null. Default: ‘ReLU’

  `declare`()

    Define things like “input_ranks” and “num_of_inputs”, which are certain with regard to your layer

    > num_of_input is N(N>0) means this layer accepts N inputs;

    > num_of_input is -1 means this layer accepts any number of inputs;

    > The rank here is not the same as matrix rank:

    > > For a scalar, its rank is 0;

    > > For a vector, its rank is 1;

    > > For a matrix, its rank is 2;

    > > For a cube of numbers, its rank is 3.

    > … For instance, the rank of (batch size, sequence length, hidden_dim) is 3.

    > if num_of_input > 0:

    > > len(input_ranks) should be equal to num_of_input

    > elif num_of_input == -1:

    > > input_ranks should be a list with only one element and the rank of all the inputs should be equal to that element.

    > NOTE: when we build the model, if num_of_input is -1, we would replace it with the real number of inputs and replace input_ranks with a list of real input_ranks.

    Returns: | None

  `default`()

    Define the default hyper parameters here. You can define these hyper parameters in your configuration file as well.

    Returns: | None

  `inference`()

    Inference things like output_dim, which may relies on defined hyper parameter such as hidden dim and input_dim

    Returns: | None

  `verify`()

    Define some necessary varification for your layer when we define the model.

    If you define your own layer and rewrite this funciton, please add “super(YourLayerConf, self).verify()” at the beginning

    Returns: | None

## Module contents