hieuhocnlp
commited on
Commit
•
c9dfa9e
1
Parent(s):
6c333b4
Upload BiLSTM
Browse files- blstm_config.py +3 -2
- blstm_model.py +3 -3
- config.json +1 -0
blstm_config.py
CHANGED
@@ -5,7 +5,7 @@ import torch
|
|
5 |
class BiLSTMConfig(PretrainedConfig):
|
6 |
def __init__(self, vocab_size=23626, embed_dim=100,
|
7 |
num_layers=1, hidden_dim=256, dropout=0.33,
|
8 |
-
output_dim=128, predict_output=10, **kwargs):
|
9 |
|
10 |
super().__init__(**kwargs)
|
11 |
self.vocab_size = vocab_size
|
@@ -14,4 +14,5 @@ class BiLSTMConfig(PretrainedConfig):
|
|
14 |
self.hidden_dim = hidden_dim
|
15 |
self.dropout = dropout
|
16 |
self.output_dim = output_dim
|
17 |
-
self.predict_output = predict_output
|
|
|
|
5 |
class BiLSTMConfig(PretrainedConfig):
|
6 |
def __init__(self, vocab_size=23626, embed_dim=100,
|
7 |
num_layers=1, hidden_dim=256, dropout=0.33,
|
8 |
+
output_dim=128, predict_output=10, device="cuda:0", **kwargs):
|
9 |
|
10 |
super().__init__(**kwargs)
|
11 |
self.vocab_size = vocab_size
|
|
|
14 |
self.hidden_dim = hidden_dim
|
15 |
self.dropout = dropout
|
16 |
self.output_dim = output_dim
|
17 |
+
self.predict_output = predict_output
|
18 |
+
self.device = device
|
blstm_model.py
CHANGED
@@ -19,7 +19,7 @@ class BiLSTM(PreTrainedModel):
|
|
19 |
self.dropout = nn.Dropout(config.dropout)
|
20 |
self.elu = nn.ELU()
|
21 |
self.fc = nn.Linear(config.output_dim, config.predict_output)
|
22 |
-
|
23 |
|
24 |
def forward(self, input): # input is a list of indices, shape batch_size, seq_len
|
25 |
x = self.embed_layer(input) # batch_size, seq_len, 100 (This is only when batch_first=True!!!!)
|
@@ -37,6 +37,6 @@ class BiLSTM(PreTrainedModel):
|
|
37 |
return out, hidden
|
38 |
|
39 |
def init_hidden(self, batch_size):
|
40 |
-
hidden = torch.zeros(2, batch_size, self.hidden_dim//2)
|
41 |
-
cell = torch.zeros(2, batch_size, self.hidden_dim//2)
|
42 |
return hidden, cell
|
|
|
19 |
self.dropout = nn.Dropout(config.dropout)
|
20 |
self.elu = nn.ELU()
|
21 |
self.fc = nn.Linear(config.output_dim, config.predict_output)
|
22 |
+
self.device_ = config.device
|
23 |
|
24 |
def forward(self, input): # input is a list of indices, shape batch_size, seq_len
|
25 |
x = self.embed_layer(input) # batch_size, seq_len, 100 (This is only when batch_first=True!!!!)
|
|
|
37 |
return out, hidden
|
38 |
|
39 |
def init_hidden(self, batch_size):
|
40 |
+
hidden = torch.zeros(2, batch_size, self.hidden_dim//2, device=self.device_)
|
41 |
+
cell = torch.zeros(2, batch_size, self.hidden_dim//2, device=self.device_)
|
42 |
return hidden, cell
|
config.json
CHANGED
@@ -6,6 +6,7 @@
|
|
6 |
"AutoConfig": "blstm_config.BiLSTMConfig",
|
7 |
"AutoModel": "blstm_model.BiLSTM"
|
8 |
},
|
|
|
9 |
"dropout": 0.33,
|
10 |
"embed_dim": 100,
|
11 |
"hidden_dim": 256,
|
|
|
6 |
"AutoConfig": "blstm_config.BiLSTMConfig",
|
7 |
"AutoModel": "blstm_model.BiLSTM"
|
8 |
},
|
9 |
+
"device": "cuda:0",
|
10 |
"dropout": 0.33,
|
11 |
"embed_dim": 100,
|
12 |
"hidden_dim": 256,
|