【发布时间】:2021-02-05 09:14:17
【问题描述】:
我目前正在尝试使用 TensorFlow 2.0 开发前馈神经网络 n-gram 语言模型。为了清楚起见,我不希望通过循环神经网络来实现,我只是想使用一些 Dense 层和一个 Softmax 层来实现这一点。 这是我使用的参考;还概述了模型的架构, https://www.researchgate.net/publication/301875194_Authorship_Attribution_Using_a_Neural_Network_Language_Model
但是,当我尝试执行此操作时,我不断收到错误消息。下面给出的是我的模型,
tf.keras.optimizers.Adam(learning_rate=0.01)
model = tf.keras.Sequential([
tf.keras.layers.Embedding(total_words, 300, weights = [embeddings_matrix], input_length=inputs.shape[1], trainable = False),
tf.keras.layers.Dense(100, activation = 'relu'),
tf.keras.layers.Dense(total_words, activation = 'softmax')
])
model.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
这段代码运行时,我得到的错误如下,
ValueError: Shapes (None, 7493) and (None, 116, 7493) are incompatible
谁能告诉我如何解决这个问题?我有点困惑。
【问题讨论】:
标签: python tensorflow neural-network language-model