Example #1
0
    def build(self, input_shape):
        super(MaximumEntropyMarkovModel, self).build(input_shape)
        output_dim = input_shape[-1]

        if self.hidden_dim is None:
            self.trans = self.add_weight(name='trans',
                                         shape=(output_dim, output_dim),
                                         initializer='glorot_uniform',
                                         trainable=True)
            if self.lr_multiplier != 1:
                K.set_value(self.trans,
                            K.eval(self.trans) / self.lr_multiplier)
                self.trans = self.lr_multiplier * self.trans
        else:
            self.l_trans = self.add_weight(name='l_trans',
                                           shape=(output_dim, self.hidden_dim),
                                           initializer='glorot_uniform',
                                           trainable=True)
            self.r_trans = self.add_weight(name='r_trans',
                                           shape=(output_dim, self.hidden_dim),
                                           initializer='glorot_uniform',
                                           trainable=True)

            if self.lr_multiplier != 1:
                K.set_value(self.l_trans,
                            K.eval(self.l_trans) / self.lr_multiplier)
                self.l_trans = self.lr_multiplier * self.l_trans
                K.set_value(self.r_trans,
                            K.eval(self.r_trans) / self.lr_multiplier)
                self.r_trans = self.lr_multiplier * self.r_trans
Example #2
0
 def build(self, input_shape):
     super(ConditionalRandomField, self).build(input_shape)
     output_dim = input_shape[-1]
     self.trans = self.add_weight(name='trans',
                                  shape=(output_dim, output_dim),
                                  initializer='glorot_uniform',
                                  trainable=True)
     if self.lr_multiplier != 1:
         K.set_value(self.trans, K.eval(self.trans) / self.lr_multiplier)
         self.trans = self.lr_multiplier * self.trans