| import torch | |
| import torch.nn as nn | |
| class KABERT(nn.Module): | |
| def __init__(self, bert_model, num_labels=3): | |
| super().__init__() | |
| self.bert = bert_model | |
| self.dropout = nn.Dropout(0.3) | |
| self.classifier = nn.Linear(self.bert.config.hidden_size, num_labels) | |
| def forward(self, input_ids, attention_mask=None, token_type_ids=None): | |
| outputs = self.bert( | |
| input_ids=input_ids, | |
| attention_mask=attention_mask, | |
| token_type_ids=token_type_ids | |
| ) | |
| pooled_output = outputs.pooler_output | |
| pooled_output = self.dropout(pooled_output) | |
| logits = self.classifier(pooled_output) | |
| return logits | |