我正在训练一个seq2seq模型进行拼写校正,改编自https://github.com/MajorTal/DeepSpell。
我的模型很好地学会了如何纠正拼写错误,但由于某种原因,它也打印出尾随无意义的字符。例如:
错字:用于装饰的一些新鲜的cZhives
正确:一些新鲜的韭菜装饰
预测:一些新鲜的韭菜为garnishhngghnnn))))))ssssssssssssssss
Keras模型的架构如下:
model = Sequential()
# Add masking layer
model.add(Masking(mask_value=0., input_shape=(None, len(chars))))
# "Encode" the input sequence using an RNN, producing an output of hidden_size
# note: in a situation where your input sequences have a variable length,
# use input_shape=(None, nb_feature).
for layer_number in range(CONFIG.input_layers):
model.add(recurrent.LSTM(CONFIG.hidden_size, input_shape=(None, len(chars)), kernel_initializer=CONFIG.initialization,
return_sequences=layer_number + 1 < CONFIG.input_layers))
model.add(Dropout(CONFIG.amount_of_dropout))
# For the decoder's input, we repeat the encoded input for each time step
model.add(RepeatVector(output_len))
# The decoder RNN could be multiple layers stacked or a single layer
for _ in range(CONFIG.output_layers):
model.add(recurrent.LSTM(CONFIG.hidden_size, return_sequences=True, kernel_initializer=CONFIG.initialization))
model.add(Dropout(CONFIG.amount_of_dropout))
# For each of step of the output sequence, decide which character should be chosen
model.add(TimeDistributed(Dense(len(chars), kernel_initializer=CONFIG.initialization)))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
return model
知道我做错了吗?