if __name__ == '__main__':
#只有当直接执行这个文件才会被执行tf.app.flags
可以指定运行时的参数;设置随机数的种子:np.random.seed(0)
、tf.set_random_seed(0)
; 使用debug
跟踪项目进行学习; tenforflow 是静态图计算,先把图绘制好,再加入数据;静态图,适合语料库中句子长度差距不大,static_rnn
动态图,适合语料库中句子长度差距大,dynamic_rnn
一层lstm 只有一个cell Seq2Seq 的参数 N、V、S、M os.path.join()
路径拼接 防止梯度爆炸的有效方法:梯度截断法。限制梯度的导数的大小。 梯度爆炸的表象是损失值不减反增 梯度下降求导的目的:1、求得方向 ;2、求出导数绝对值 softmax输出归一化的分类概率 机器翻译-词对齐,词语对齐的目标是得到中英文词或短语的对齐信息,便于翻译系统做解码时寻找相应的phrase。 tf.variable与tf.get_variable 生成变量的方法
val = tf. variable( tf. constant( 1.0 , shape= [ 1 ] , name= "val" ) )
val = tf. get_variable( "val" , 1.0 , shape= [ 1 ] , initializer = tf. constant_initializer( 1.0 ) )
with tf. variable_scope( "foo" ) :
val1 = tf. get_variable( "val" , 1.0 , shape= [ 1 ] , initializer = tf. constant_initializer( 1.0 ) )
with tf. variable_scope( "foo" ,refuse = True ) :
val2 = tf. get_variable( "val" , 1.0 , shape= [ 1 ] )
with tf. variable_scope( "foo1" , ,refuse = True ) :
val2 = tf. get_variable( "val" , 1.0 , shape= [ 1 ] )
with tf. variable_scope( "foo1" ) :
val2 = tf. get_variable( "val" , 1.0 , shape= [ 1 ] ,tf. constant_initializer( 1.0 ) )
求平均值,tf.reduce_mean(output,axis=0)
拼接, tf.concat([a,b],0)
前面是需要拼接的列表,后面是在哪个维度上进行拼接 句子比较长的时候,选择每个时刻的状态和输出;句子比较短的时候,选择最终的状态和输出 Beamsearch 定向搜索 attention里面的 linear
代表映射 with tf.device('/cpu:0)'
指定设备random_number = np.random.random_sample()
均匀分布产生的随机数 0-1之间,便于根据不同的样本数量进行采样。