我想从具有相同形状的本地numpy数组初始化单词嵌入层,这是来自另一个模型的预训练嵌入 . 如果我没有添加分区程序参数,那就没关系 . def word_embedding(shape,dtype = tf.float32,name ='word_embedding'):
f = open('./cnn_embed_array', 'r')
embedding_array = pickle.load(f)
f.close()
print 'embedding_array loaded......'
with tf.device('/cpu:0'), tf.variable_scope(name):
return tf.get_variable('embedding', shape, dtype=dtype, initializer=tf.constant_initializer(embedding_array), trainable = False)
但是如果我在tf.get_variable函数中添加 partitioner=tf.fixed_size_partitioner(20)
,它会给我一个错误,说该参数是多余的 .
partitioner
param倾向于加快训练速度 . 我可以用其他方式添加参数吗?
1 回答
如果
trainable = False
,那么该变量将不会被学习,因此分区赢得't help you. On the other hand, if you want this variable to be updated then you' ll需要设置trainable = True
.