def __init__(
            self,
            vocab_size,
            word_dim,
            hidden_dim,
            label_dim,
            parser_leaf_transformation=BinaryTreeBasedModule.no_transformation,
            parser_trans_hidden_dim=None,
            tree_leaf_transformation=BinaryTreeBasedModule.no_transformation,
            tree_trans_hidden_dim=None,
            baseline_type=no_baseline,
            var_normalization=False):
        super().__init__()
        self.embd_parser = nn.Embedding(vocab_size, word_dim)
        self.parser = BottomUpTreeLstmParser(word_dim, hidden_dim,
                                             parser_leaf_transformation,
                                             parser_trans_hidden_dim)
        self.embd_tree = nn.Embedding(vocab_size, word_dim)
        self.tree_lstm_rnn = BinaryTreeLstmRnn(word_dim, hidden_dim,
                                               tree_leaf_transformation,
                                               tree_trans_hidden_dim)
        self.linear = nn.Linear(in_features=hidden_dim, out_features=label_dim)

        self.baseline_params = ReinforceModel.get_baseline_dict(baseline_type)
        self.var_norm_params = {
            "var_normalization": var_normalization,
            "var": 1.0,
            "alpha": 0.9
        }
        self.criterion = nn.CrossEntropyLoss(reduction='none')
        self.reset_parameters()
示例#2
0
 def __init__(self, vocab_size, word_dim, hidden_dim, label_dim,
              leaf_transformation=BinaryTreeBasedModule.no_transformation, trans_hidden_dim=None):
     super().__init__()
     self.embd_tree = nn.Embedding(vocab_size, word_dim)
     self.tree_lstm_rnn = BinaryTreeLstmRnn(word_dim, hidden_dim, leaf_transformation, trans_hidden_dim)
     self.linear = nn.Linear(in_features=hidden_dim, out_features=label_dim)
     self.criterion = nn.CrossEntropyLoss()
     self.reset_parameters()