Exemplo n.º 1
0
    def __init__(
        self,
        in_channel=1,
        rnn_hidden_size=200,
        decoder_size=128,
        is_test=False,
    ):
        super(Encoder, self).__init__()
        self.rnn_hidden_size = rnn_hidden_size

        self.backbone = CNN(in_ch=in_channel, is_test=is_test)

        para_attr = fluid.ParamAttr(
            initializer=fluid.initializer.Normal(0.0, 0.02))
        bias_attr = fluid.ParamAttr(initializer=fluid.initializer.Normal(
            0.0, 0.02),
                                    learning_rate=2.0)
        self.gru_fwd = RNN(cell=GRUCell(input_size=128 * 6,
                                        hidden_size=rnn_hidden_size,
                                        param_attr=para_attr,
                                        bias_attr=bias_attr,
                                        candidate_activation='relu'),
                           is_reverse=False,
                           time_major=False)
        self.gru_bwd = RNN(cell=GRUCell(input_size=128 * 6,
                                        hidden_size=rnn_hidden_size,
                                        param_attr=para_attr,
                                        bias_attr=bias_attr,
                                        candidate_activation='relu'),
                           is_reverse=True,
                           time_major=False)
        self.encoded_proj_fc = fluid.dygraph.Linear(rnn_hidden_size * 2,
                                                    decoder_size,
                                                    bias_attr=False)
Exemplo n.º 2
0
 def __init__(self,
              vocab_size,
              embed_dim,
              hidden_size,
              num_layers,
              dropout_prob=0.,
              init_scale=0.1):
     super(Encoder, self).__init__()
     self.embedder = Embedding(
         size=[vocab_size, embed_dim],
         param_attr=ParamAttr(initializer=UniformInitializer(
             low=-init_scale, high=init_scale)))
     self.stack_lstm = RNN(EncoderCell(num_layers, embed_dim, hidden_size,
                                       dropout_prob, init_scale),
                           is_reverse=False,
                           time_major=False)
Exemplo n.º 3
0
 def __init__(self,
              vocab_size,
              embed_dim,
              hidden_size,
              num_layers,
              dropout_prob=0.,
              init_scale=0.1):
     super(Decoder, self).__init__()
     self.embedder = Embedding(
         size=[vocab_size, embed_dim],
         param_attr=ParamAttr(initializer=UniformInitializer(
             low=-init_scale, high=init_scale)))
     self.lstm_attention = RNN(DecoderCell(
         num_layers, embed_dim, hidden_size, dropout_prob, init_scale),
                               is_reverse=False,
                               time_major=False)
     self.output_layer = Linear(
         hidden_size,
         vocab_size,
         param_attr=ParamAttr(initializer=UniformInitializer(
             low=-init_scale, high=init_scale)),
         bias_attr=False)
Exemplo n.º 4
0
 def __init__(self, num_classes, emb_dim, encoder_size, decoder_size):
     super(Decoder, self).__init__()
     self.decoder_attention = RNN(DecoderCell(encoder_size, decoder_size))
     self.fc = fluid.dygraph.Linear(decoder_size,
                                    num_classes + 2,
                                    act='softmax')