@@ -32,7 +32,7 @@ def __init__(self, seq_start_positions, emission_weights, emission_row_max,
32
32
# alpha is a memo table in dynamic programming to caculate
33
33
# nomalization factor.
34
34
self .alpha = np .zeros (
35
- (seq_start_positions [- 1 ], self .tag_num ), dtype = "float32 " )
35
+ (seq_start_positions [- 1 ], self .tag_num ), dtype = "float64 " )
36
36
self .log_likelihood = np .zeros ((self .seq_num , 1 ))
37
37
38
38
def _l1_norm (self , x ):
@@ -92,12 +92,12 @@ def set_test_data(self):
92
92
for i in range (SEQ_NUM ):
93
93
lod [- 1 ].append (lod [- 1 ][- 1 ] + random .randint (1 , MAX_SEQ_LEN ))
94
94
emission = np .random .uniform (- 1 , 1 ,
95
- [lod [- 1 ][- 1 ], TAG_NUM ]).astype ("float32 " )
95
+ [lod [- 1 ][- 1 ], TAG_NUM ]).astype ("float64 " )
96
96
emission_row_max = np .amax (emission , axis = 1 , keepdims = True )
97
97
emission_exps = np .exp (emission - emission_row_max )
98
98
99
99
transition = np .random .uniform (- 0.5 , 0.5 ,
100
- [TAG_NUM + 2 , TAG_NUM ]).astype ("float32 " )
100
+ [TAG_NUM + 2 , TAG_NUM ]).astype ("float64 " )
101
101
transition_exps = np .exp (transition )
102
102
103
103
labels = np .random .randint (
@@ -128,17 +128,11 @@ def test_check_output(self):
128
128
self .check_output ()
129
129
130
130
def test_check_grad (self ):
131
- self .check_grad (
132
- ["Emission" , "Transition" ],
133
- "LogLikelihood" ,
134
- max_relative_error = 0.05 )
131
+ self .check_grad (["Emission" , "Transition" ], "LogLikelihood" )
135
132
136
133
def test_check_grad_ignore_transition (self ):
137
134
self .check_grad (
138
- ["Emission" ],
139
- "LogLikelihood" ,
140
- max_relative_error = 0.05 ,
141
- no_grad_set = set ("Transition" ))
135
+ ["Emission" ], "LogLikelihood" , no_grad_set = set ("Transition" ))
142
136
143
137
144
138
if __name__ == "__main__" :
0 commit comments