def __init__(self, num_layers, hidden_size, dropout_prob=0.):
     self.num_layers = num_layers
     self.hidden_size = hidden_size
     self.dropout_prob = dropout_prob
     self.lstm_cells = [
         layers.LSTMCell(hidden_size) for i in range(num_layers)
     ]
Esempio n. 2
0
 def __init__(self,
              num_layers,
              hidden_size,
              dropout_prob=0.,
              forget_bias=0.):
     self.num_layers = num_layers
     self.hidden_size = hidden_size
     self.dropout_prob = dropout_prob
     self.lstm_cells = []
     for i in range(num_layers):
         self.lstm_cells.append(
             layers.LSTMCell(
                 hidden_size,
                 forget_bias=forget_bias,
                 param_attr=fluid.ParamAttr(
                     initializer=fluid.initializer.
                     UniformInitializer(low=-init_scale,
                                        high=init_scale))))
Esempio n. 3
0
    def __init__(self,
                 hidden_size,
                 cell_type="lstm",
                 dropout=0.0,
                 init_scale=-1,
                 name="BasicRNNCell"):
        """init of class

        Args:
            hidden_size (TYPE): NULL
            cell_type (str): lstm|gru
            dropout (TYPE): Default is 0.0
            init_scale (TYPE): Default is -1
            name (TYPE): Default is "BasicRNNCell"

        """
        super(BasicRNNCell, self).__init__()

        self._hidden_size = hidden_size
        self._cell_type = cell_type.lower()
        self._dropout = dropout
        self._init_scale = init_scale
        self._name = name

        param = fluid.ParamAttr(initializer=nn_utils.uniform(self._init_scale))
        bias = fluid.ParamAttr(initializer=nn_utils.zero)
        if self._cell_type == 'lstm':
            self._cell = layers.LSTMCell(self._hidden_size,
                                         param,
                                         bias,
                                         name=self._name)
        elif self._cell_type == 'gru':
            self._cell = layers.GRUCell(self._hidden_size,
                                        param,
                                        bias,
                                        name=self._name)
        else:
            raise ValueError(
                "cell type only supported <lstm|gru>, but got %s" %
                (cell_type))
Esempio n. 4
0
    def __init__(self,
                 hidden_size,
                 dropout=0.,
                 init_scale=-1,
                 name="rnn_decode_cell"):
        """init of class

        Args:
            hidden_size (TYPE): NULL
            dropout (TYPE): Default is 0.
            init_scale (TYPE): Default is -1, means paddle default initializer is used.
            name (str): param name scope

        """
        super(RNNDecodeCell, self).__init__()

        self._hidden_size = hidden_size
        self._dropout = dropout
        self._init_scale = init_scale
        self._name = name

        param = fluid.ParamAttr(initializer=nn_utils.uniform(self._init_scale))
        bias = fluid.ParamAttr(initializer=nn_utils.zero)
        self.rnn_cell = layers.LSTMCell(hidden_size, param, bias, name=name)