Exemple #1
0
    def __init__(self, classes_num, hidden_size=128, BERT_out_dropout=0.5, BiLSTM_dropout=0.1):
        super(Encoder, self).__init__()

        self.hidden_size = hidden_size
        self.zeros = T.tensor(0.0).to(device)
        self.neg_inf = T.tensor(-2.0**32).to(device)

        self.BERT = BertModel.from_pretrained('../Pre_trained_BERT/',
                                              output_hidden_states=True,
                                              output_attentions=False)

        self.dropout = nn.Dropout(BERT_out_dropout)

        self.layer_fusion = capsule_fusion(D=768,
                                           n_in=6, n_out=768,
                                           in_dim=128, out_dim=1,
                                           depth_encoding=True)

        self.BiLSTM = BiLSTM_Encoder(D=768, hidden_size=hidden_size, dropout=BiLSTM_dropout)

        self.hidden_fusion = capsule_fusion(D=2*hidden_size,
                                            n_in=1, n_out=2*hidden_size,
                                            in_dim=128, out_dim=1,
                                            depth_encoding=False)

        self.linear1 = Linear(2*hidden_size, 300)
        self.linear2 = Linear(300, 1)
        self.linear3 = Linear(300, classes_num)
    def __init__(self,
                 classes_num,
                 hidden_size=128,
                 BERT_out_dropout=0.5,
                 BiLSTM_dropout=0.1):
        super(Encoder, self).__init__()
        self.BERT = BertModel.from_pretrained('../Pre_trained_BERT/',
                                              output_hidden_states=True,
                                              output_attentions=False)

        self.dropout = nn.Dropout(BERT_out_dropout)

        self.linear1 = Linear(768, 300)
        self.linear2 = Linear(300, 1)
        self.linear3 = Linear(300, classes_num)