【发布时间】:2021-04-23 07:35:53
【问题描述】:
我无法训练我的神经网络。我将神经网络定义如下:
shared = embedding_layer
inputA = keras.Input(shape=(40, ), name="anchor") # Variable-length sequence of ints
inputP = keras.Input(shape=(40, ), name="positive") # Variable-length sequence of ints
inputN = keras.Input(shape=(40, ), name="negative") # Binary vectors of size num_tags
concatenated = layers.concatenate([inputA, inputP, inputN])
embedded_A = shared(concatenated)
encoded = Dense(900, activation = "relu")(embedded_A)
encoded = Dense(600, activation = "relu")(encoded)
encoded = Dense(300, activation = "relu")(encoded)
encoded = Dense(100, activation = "relu")(encoded)
decoded = Dense(100, activation = "relu")(encoded)
decoded = Dense(300, activation = "relu")(decoded)
decoded = Dense(600, activation = "relu")(decoded)
decoded = Dense(900, activation = "relu")(decoded)
predictionsA = Dense(40, activation="sigmoid", name ='outA')(decoded)
predictionsP = Dense(40, activation="sigmoid", name ='outB')(decoded)
predictionsN = Dense(40, activation="sigmoid", name ='outC')(decoded)
ml_model = keras.Model(
inputs=[inputA, inputP, inputN],
outputs=[predictionsA, predictionsP, predictionsN]
)
ml_model.compile(
optimizer='adam',
loss='mse'
)
ml_model.fit(
{"anchor": anchor, "positive": positive, "negative": negative},
{"outA": anchor, "outB": positive, 'outC': negative},
epochs=2)
嵌入层定义如下:
embedding_m = model.syn0
embedding_layer = Embedding(len(vocab),
300,
weights=[embedding_m],
input_length=40,
trainable=True)
What I feed into the network is three numpy arrays of shape (120000, 40) which look like this:
array([[ 2334, 23764, 7590, ..., 3000001, 3000001, 3000001],
[3000000, 1245, 1124, ..., 3000001, 3000001, 3000001],
[ 481, 491, 5202, ..., 3000001, 3000001, 3000001],
...,
[3000000, 125, 20755, ..., 3000001, 3000001, 3000001],
[1217971, 168575, 239, ..., 9383, 1039, 87315],
[ 12990, 91, 258231, ..., 3000001, 3000001, 3000001]])
而且输入和输出一样,因为我正在做一个自动编码器解码器。
我得到的错误是:
尺寸必须相等,但对于输入形状为 [32,120,40 ],[32,40]。
但我似乎无法找出原因,或者如何解决它......有什么想法吗?如果需要,我可以提供更多示例。我怀疑存在一些尺寸错误,因为理想情况下我希望输出的形状 (120000,40) 与输入完全相同。
【问题讨论】:
标签: machine-learning keras nlp