astra / src /classifier_model.py
suryadev1's picture
v1
6a34fd4
raw
history blame
614 Bytes
import torch.nn as nn
from bert import BERT
class BERTForClassification(nn.Module):
"""
Progress Classifier Model
"""
def __init__(self, bert: BERT, vocab_size, n_labels):
"""
:param bert: BERT model which should be trained
:param vocab_size: total vocab size for masked_lm
"""
super().__init__()
self.bert = bert
self.linear = nn.Linear(self.bert.hidden, n_labels)
# self.softmax = nn.LogSoftmax(dim=-1)
def forward(self, x, segment_label):
x = self.bert(x, segment_label)
return x, self.linear(x[:, 0])