File size: 2,193 Bytes
5c72fe4
 
 
 
 
 
6a34fd4
 
 
5c72fe4
6a34fd4
 
 
 
5c72fe4
 
 
6a34fd4
5c72fe4
6a34fd4
 
 
 
 
5c72fe4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6a34fd4
 
 
 
 
 
 
 
 
 
5c72fe4
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<<<<<<< HEAD
import torch
import torch.nn as nn

from .bert import BERT
=======
import torch.nn as nn

from bert import BERT
>>>>>>> bffd3381ccb717f802fe651d4111ec0a268e3896


class BERTForClassification(nn.Module):
    """
<<<<<<< HEAD
        Fine-tune Task Classifier Model
=======
        Progress Classifier Model
>>>>>>> bffd3381ccb717f802fe651d4111ec0a268e3896
    """

    def __init__(self, bert: BERT, vocab_size, n_labels):
        """
        :param bert: BERT model which should be trained
<<<<<<< HEAD
        :param vocab_size: total vocab size
        :param n_labels: number of labels for the task
        """
        super().__init__()
        self.bert = bert
        self.linear = nn.Linear(self.bert.hidden, n_labels)

    def forward(self, x, segment_label):
        x = self.bert(x, segment_label)
        return self.linear(x[:, 0])
    
class BERTForClassificationWithFeats(nn.Module):
    """
        Fine-tune Task Classifier Model 
        BERT embeddings concatenated with features
    """

    def __init__(self, bert: BERT, n_labels, feat_size=9):
        """
        :param bert: BERT model which should be trained
        :param vocab_size: total vocab size
        :param n_labels: number of labels for the task
        """
        super().__init__()
        self.bert = bert
        # self.linear1 = nn.Linear(self.bert.hidden+feat_size, 128)
        self.linear = nn.Linear(self.bert.hidden+feat_size, n_labels)
        # self.RELU = nn.ReLU()
        # self.linear2 = nn.Linear(128, n_labels)

    def forward(self, x, segment_label, feat):
        x = self.bert(x, segment_label)
        x = torch.cat((x[:, 0], feat), dim=-1)
        # x = self.linear1(x)
        # x = self.RELU(x)
        # return self.linear2(x)
        return self.linear(x)
=======
        :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])
>>>>>>> bffd3381ccb717f802fe651d4111ec0a268e3896