| 30 | |
| 31 | |
| 32 | class Model(nn.Module): |
| 33 | |
| 34 | def __init__(self, config): |
| 35 | super(Model, self).__init__() |
| 36 | self.bert = BertModel.from_pretrained(config.bert_path) |
| 37 | for param in self.bert.parameters(): |
| 38 | param.requires_grad = True |
| 39 | self.fc = nn.Linear(config.hidden_size, config.num_classes) |
| 40 | |
| 41 | def forward(self, x): |
| 42 | context = x[0] # 输入的句子 |
| 43 | mask = x[2] # 对padding部分进行mask,和句子一个size,padding部分用0表示,如:[1, 1, 1, 1, 0, 0] |
| 44 | _, pooled = self.bert(context, attention_mask=mask, output_all_encoded_layers=False) |
| 45 | out = self.fc(pooled) |
| 46 | return out |
nothing calls this directly
no outgoing calls
no test coverage detected