-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmodels.py
More file actions
70 lines (53 loc) · 1.95 KB
/
models.py
File metadata and controls
70 lines (53 loc) · 1.95 KB
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
# -*- coding: utf-8 -*-
import torch.nn as nn
from networks.embedding import *
from networks.encoder import *
from networks.selector import *
from networks.classifier import *
class Model(nn.Module):
def __init__(self, config):
super(Model, self).__init__()
self.config = config
self.embedding = Embedding(config)
self.encoder = None
self.selector = None
self.classifier = Classifier(config)
def forward(self):
embedding = self.embedding()
sen_embedding = self.encoder(embedding)
logits = self.selector(sen_embedding)
return self.classifier(logits)
def test(self):
embedding = self.embedding()
sen_embedding = self.encoder(embedding)
return self.selector.test(sen_embedding)
class CNN_ATT(Model):
def __init__(self, config):
super(CNN_ATT, self).__init__(config)
self.encoder = CNN(config)
self.selector = Attention(config, config.hidden_size)
class CNN_AVE(Model):
def __init__(self, config):
super(CNN_AVE, self).__init__(config)
self.encoder = CNN(config)
self.selector = Average(config, config.hidden_size)
class CNN_ONE(Model):
def __init__(self, config):
super(CNN_ONE, self).__init__(config)
self.encoder = CNN(config)
self.selector = One(config, config.hidden_size)
class PCNN_ATT(Model):
def __init__(self, config):
super(PCNN_ATT, self).__init__(config)
self.encoder = PCNN(config)
self.selector = Attention(config, config.hidden_size * 3)
class PCNN_AVE(Model):
def __init__(self, config):
super(PCNN_AVE, self).__init__(config)
self.encoder = PCNN(config)
self.selector = Average(config, config.hidden_size * 3)
class PCNN_ONE(Model):
def __init__(self, config):
super(PCNN_ONE, self).__init__(config)
self.encoder = PCNN(config)
self.selector = One(config, config.hidden_size * 3)