MCPcopy Create free account
hub / github.com/649453932/Bert-Chinese-Text-Classification-Pytorch / Model

Class Model

models/bert.py:32–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30
31
32class 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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected