2024-04-24 12:37:06 发布
网友
我需要创建LSTM单元,但不是为网络中的权重和偏差创建新变量,而是LSTM单元中的权重和偏差来自另一个网络的输出,即,我需要能够将张量(而不是变量,例如使用重用)传递给LSTM单元以用于权重和偏差。在Tensorflow中有没有这样的方法?请注意,我的目标不是定义LSTM,而是了解在当前实现中是否有传递张量的方法。你知道吗
Keras现在默认运行在TensorFlow之上,并且有an LSTM layer可以在您的模型中调用。这将自动传递权重作为层之间的张量。你知道吗
>>>IN>>> nb_words = min(MAX_NB_WORDS, len(word_index)) lstm_out = MAX_SEQUENCE_LENGTH model = Sequential() model.add(Embedding(nb_words,EMBEDDING_DIM,input_length=MAX_SEQUENCE_LENGTH)) model.add(LSTM(50)) #model.add(Attention(MAX_SEQUENCE_LENGTH)) model.add(Dense(3, activation = 'softmax')) model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy']) model.summary() >>>OUT>>> _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= embedding_1 (Embedding) (None, 100, 160) 480000 _________________________________________________________________ lstm_1 (LSTM) (None, 50) 42200 _________________________________________________________________ dense_1 (Dense) (None, 3) 153 ================================================================= Total params: 522,353 Trainable params: 522,353 Non-trainable params: 0 _________________________________________________________________
Here is a notebook where you can see it used.
Keras+张量流
Keras现在默认运行在TensorFlow之上,并且有an LSTM layer可以在您的模型中调用。这将自动传递权重作为层之间的张量。你知道吗
Here is a notebook where you can see it used.
相关问题 更多 >
编程相关推荐