@@ -150,7 +150,9 @@ def __init__(self, **kwargs):
150
150
self .contains_unkown = kwargs ["contains_unkown" ]
151
151
self .start = kwargs ['start' ]
152
152
self .end = kwargs ['end' ]
153
- self .lstm = nn .LSTM (input_size , self .hidden_size ,bidirectional = self .bidirectional )
153
+ self .num_layers = kwargs ['num_layers' ]
154
+ self .lstm = nn .LSTM (input_size , self .hidden_size , self .num_layers ,
155
+ bidirectional = self .bidirectional )
154
156
self .fc = nn .Linear (self .hidden_size * (2 if self .bidirectional else 1 ), 3 if self .contains_unkown else 2 )
155
157
156
158
def forward (self , x ):
@@ -163,11 +165,16 @@ def forward(self, x):
163
165
return out
164
166
def polarity_lstm (** kwargs ):
165
167
r"""A LSTM based model.
166
- Args:
167
- pretrained (bool): If True, returns a model pre-trained on Wenchuan)
168
- progress (bool): If True, displays a progress bar of the download to stderr
168
+ Kwargs (form like a dict and should be pass like **kwargs):
169
+ hidden_size (default 64): recommended to be similar as the length of trimmed subsequence
170
+ num_layers (default 2): layers are stacked and results are from the final layer
171
+ start (default 250): start index of the subsequence
172
+ end (default 350): end index of the subsequence
173
+ bidirectional (default False): run lstm from left to right and from right to left
174
+ contains_unkown (default False): True if targets have 0,1,2
169
175
"""
170
176
default_kwargs = {"hidden_size" :64 ,
177
+ "num_layers" :2 ,
171
178
"start" : 250 ,
172
179
"end" : 350 ,
173
180
"bidirectional" :False ,
@@ -179,6 +186,6 @@ def polarity_lstm(**kwargs):
179
186
print (default_kwargs )
180
187
print ("\n ##########################" )
181
188
if (default_kwargs ['end' ] < default_kwargs ['start' ]):
182
- raise ValueError ('<-- end must be largger than start -->' )
189
+ raise ValueError ('<-- end cannot be smaller than start -->' )
183
190
model = PolarityLSTM (** default_kwargs )
184
191
return model
0 commit comments