@@ -3925,8 +3925,8 @@ def __init__(
39253925 self .batch_size = batch_size
39263926
39273927 # Creats the cell function
3928- cell_instance_fn = lambda : cell_fn (num_units = n_hidden , ** cell_init_args )
3929- # self.cell = cell_fn(num_units=n_hidden, **cell_init_args)
3928+ # cell_instance_fn=lambda: cell_fn(num_units=n_hidden, **cell_init_args) # HanSheng
3929+ self .cell = cell_fn (num_units = n_hidden , ** cell_init_args )
39303930
39313931 # Apply dropout
39323932 if dropout :
@@ -3943,34 +3943,35 @@ def __init__(
39433943 except :
39443944 DropoutWrapper_fn = tf .nn .rnn_cell .DropoutWrapper
39453945
3946- cell_instance_fn1 = cell_instance_fn
3947- cell_instance_fn = DropoutWrapper_fn (
3948- cell_instance_fn1 (),
3949- input_keep_prob = in_keep_prob ,
3950- output_keep_prob = out_keep_prob )
3951- # self.cell = DropoutWrapper_fn(
3952- # self.cell,
3953- # input_keep_prob=in_keep_prob,
3954- # output_keep_prob=out_keep_prob)
3946+ # cell_instance_fn1=cell_instance_fn # HanSheng
3947+ # cell_instance_fn=DropoutWrapper_fn(
3948+ # cell_instance_fn1(),
3949+ # input_keep_prob=in_keep_prob,
3950+ # output_keep_prob=out_keep_prob)
3951+ self .cell = DropoutWrapper_fn (
3952+ self .cell ,
3953+ input_keep_prob = in_keep_prob ,
3954+ output_keep_prob = out_keep_prob )
39553955 # Apply multiple layers
39563956 if n_layer > 1 :
39573957 try :
39583958 MultiRNNCell_fn = tf .contrib .rnn .MultiRNNCell
39593959 except :
39603960 MultiRNNCell_fn = tf .nn .rnn_cell .MultiRNNCell
39613961
3962- cell_instance_fn2 = cell_instance_fn
3962+ # cell_instance_fn2=cell_instance_fn # HanSheng
39633963 try :
3964- cell_instance_fn = lambda : MultiRNNCell_fn ([cell_instance_fn2 () for _ in range (n_layer )], state_is_tuple = True )
3965- # self.cell = MultiRNNCell_fn([self.cell] * n_layer, state_is_tuple=True)
3964+ # cell_instance_fn=lambda: MultiRNNCell_fn([cell_instance_fn2() for _ in range(n_layer)], state_is_tuple=True) # HanSheng
3965+ self .cell = MultiRNNCell_fn ([self .cell ] * n_layer , state_is_tuple = True )
39663966 except :
3967- cell_instance_fn = lambda : MultiRNNCell_fn ([cell_instance_fn2 () for _ in range (n_layer )])
3968- # self.cell = MultiRNNCell_fn([self.cell] * n_layer)
3967+ # cell_instance_fn=lambda: MultiRNNCell_fn([cell_instance_fn2() for _ in range(n_layer)]) # HanSheng
3968+ self .cell = MultiRNNCell_fn ([self .cell ] * n_layer )
3969+
3970+ # self.cell=cell_instance_fn() # HanSheng
39693971
3970- self .cell = cell_instance_fn ()
39713972 # Initialize initial_state
39723973 if initial_state is None :
3973- self .initial_state = self .cell .zero_state (batch_size , dtype = tf .float32 )#dtype="float")
3974+ self .initial_state = self .cell .zero_state (batch_size , dtype = tf .float32 )
39743975 else :
39753976 self .initial_state = initial_state
39763977
@@ -4162,9 +4163,9 @@ def __init__(
41624163
41634164 with tf .variable_scope (name , initializer = initializer ) as vs :
41644165 # Creats the cell function
4165- cell_instance_fn = lambda : cell_fn (num_units = n_hidden , ** cell_init_args )
4166- # self.fw_cell = cell_fn(num_units=n_hidden, **cell_init_args)
4167- # self.bw_cell = cell_fn(num_units=n_hidden, **cell_init_args)
4166+ # cell_instance_fn=lambda: cell_fn(num_units=n_hidden, **cell_init_args) # HanSheng
4167+ self .fw_cell = cell_fn (num_units = n_hidden , ** cell_init_args )
4168+ self .bw_cell = cell_fn (num_units = n_hidden , ** cell_init_args )
41684169
41694170 # Apply dropout
41704171 if dropout :
@@ -4181,33 +4182,33 @@ def __init__(
41814182 except :
41824183 DropoutWrapper_fn = tf .nn .rnn_cell .DropoutWrapper
41834184
4184- cell_instance_fn1 = cell_instance_fn
4185- cell_instance_fn = lambda : DropoutWrapper_fn (
4186- cell_instance_fn1 (),
4187- input_keep_prob = in_keep_prob ,
4188- output_keep_prob = out_keep_prob )
4189-
4190- # self.fw_cell = DropoutWrapper_fn(
4191- # self.fw_cell,
4192- # input_keep_prob=in_keep_prob,
4193- # output_keep_prob=out_keep_prob)
4194- # self.bw_cell = DropoutWrapper_fn(
4195- # self.bw_cell,
4196- # input_keep_prob=in_keep_prob,
4197- # output_keep_prob=out_keep_prob)
4185+ # cell_instance_fn1=cell_instance_fn # HanSheng
4186+ # cell_instance_fn=lambda: DropoutWrapper_fn(
4187+ # cell_instance_fn1(),
4188+ # input_keep_prob=in_keep_prob,
4189+ # output_keep_prob=out_keep_prob)
4190+
4191+ self .fw_cell = DropoutWrapper_fn (
4192+ self .fw_cell ,
4193+ input_keep_prob = in_keep_prob ,
4194+ output_keep_prob = out_keep_prob )
4195+ self .bw_cell = DropoutWrapper_fn (
4196+ self .bw_cell ,
4197+ input_keep_prob = in_keep_prob ,
4198+ output_keep_prob = out_keep_prob )
41984199 # Apply multiple layers
41994200 if n_layer > 1 :
42004201 try :
42014202 MultiRNNCell_fn = tf .contrib .rnn .MultiRNNCell
42024203 except :
42034204 MultiRNNCell_fn = tf .nn .rnn_cell .MultiRNNCell
42044205
4205- cell_instance_fn2 = cell_instance_fn
4206- cell_instance_fn = lambda : MultiRNNCell_fn ([cell_instance_fn2 () for _ in range (n_layer )])
4207- # self.fw_cell = MultiRNNCell_fn([self.fw_cell] * n_layer)
4208- # self.bw_cell = MultiRNNCell_fn([self.bw_cell] * n_layer)
4209- self .fw_cell = cell_instance_fn ()
4210- self .bw_cell = cell_instance_fn ()
4206+ # cell_instance_fn2=cell_instance_fn # HanSheng
4207+ # cell_instance_fn=lambda: MultiRNNCell_fn([cell_instance_fn2() for _ in range(n_layer)])
4208+ self .fw_cell = MultiRNNCell_fn ([self .fw_cell ] * n_layer )
4209+ self .bw_cell = MultiRNNCell_fn ([self .bw_cell ] * n_layer )
4210+ # self.fw_cell=cell_instance_fn()
4211+ # self.bw_cell=cell_instance_fn()
42114212 # Initial state of RNN
42124213 if fw_initial_state is None :
42134214 self .fw_initial_state = self .fw_cell .zero_state (self .batch_size , dtype = tf .float32 )
0 commit comments