| 90 | |
| 91 | |
| 92 | class bBert(torch.nn.Module): |
| 93 | def __init__(self,bert_model,fea_dim, dropout): |
| 94 | super(bBert, self).__init__() |
| 95 | self.text_dim = 768 |
| 96 | |
| 97 | self.bert = BertModel.from_pretrained(bert_model).requires_grad_(False) |
| 98 | |
| 99 | self.linear_text = nn.Sequential(torch.nn.Linear(self.text_dim, fea_dim),torch.nn.ReLU()) |
| 100 | self.classifier = nn.Linear(fea_dim,2) |
| 101 | |
| 102 | def forward(self, **kwargs): |
| 103 | title_inputid = kwargs['title_inputid'] |
| 104 | title_mask=kwargs['title_mask'] |
| 105 | fea_text=self.bert(title_inputid,attention_mask=title_mask)[1] |
| 106 | fea_text=self.linear_text(fea_text) |
| 107 | output = self.classifier(fea_text) |
| 108 | return output,fea_text |
| 109 | |
| 110 | class bTextCNN(nn.Module): |
| 111 | def __init__(self, fea_dim, vocab_size): |