Example #1
0
    def build_models(self):
        '''
        Build all models.
        '''
        self.pretrained_models['bert'] = BertModel.from_pretrained(
            'bert-base-uncased',
            output_hidden_states=True,
            output_attentions=True).to(self.args.device)

        self.train_models['attn_concept'] = Attention_Concepts(
            input_size=768,
            n_concepts=self.args.n_concepts,
            device=self.args.device).to(self.args.device)

        self.train_models['attn_self'] = AttentionSelf(
            input_size=768, hidden_size=768,
            device=self.args.device).to(self.args.device)

        self.train_models['ff'] = torch.nn.Linear(768,
                                                  768).to(self.args.device)
        self.train_models['classifier'] = torch.nn.Linear(
            768, self.args.n_class).to(self.args.device)

        self.train_models['drop'] = torch.nn.Dropout(self.args.drop_rate)

        self.loss_criterion = torch.nn.CrossEntropyLoss(ignore_index=-1).to(
            self.args.device)
Example #2
0
    def build_models(self):
        '''
        Build all models.
        '''
        self.base_models['embedding'] = torch.nn.Embedding(
            self.batch_data['vocab_size'],
            self.args.emb_dim).to(self.args.device)

        self.train_models['encoder'] = EncoderRNN(
            emb_dim=self.args.emb_dim,
            hidden_size=self.args.rnn_hidden_dim,
            nLayers=self.args.rnn_nLayers,
            rnn_network=self.args.rnn_network,
            device=self.args.device).to(self.args.device)

        self.train_models['attn_self'] = AttentionSelf(
            input_size=self.args.rnn_hidden_dim * 2,
            hidden_size=self.args.rnn_hidden_dim * 2,
            device=self.args.device).to(self.args.device)

        self.train_models['ff'] = torch.nn.Linear(self.args.rnn_hidden_dim * 2,
                                                  self.args.rnn_hidden_dim *
                                                  2).to(self.args.device)
        self.train_models['classifier'] = torch.nn.Linear(
            self.args.rnn_hidden_dim * 2,
            self.args.n_class).to(self.args.device)

        self.train_models['drop'] = torch.nn.Dropout(self.args.drop_rate)

        self.loss_criterion = torch.nn.CrossEntropyLoss(ignore_index=-1).to(
            self.args.device)