我想从可以作为文章摘要一部分的新闻文章中提取潜在的句子。
经过一段时间,我发现这可以通过两种方式来实现,
我遵循指向点:指针-生成器网络综述的总结,这是产生良好的结果与预先训练的模型,但它是抽象的。
问题:我到目前为止看过的大多数抽取总结器(PyTeaser、PyTextRank和Gensim)都不是基于监督学习,而是基于朴素贝叶斯分类器、tf-以色列国防军、POS标记、基于关键字频率、位置等的句子排序,它们不需要任何训练。
到目前为止,我已经尝试了很少的东西来提取潜在的摘要句。
from keras.preprocessing.text import Tokenizer对文本语料库进行矢量化,并将所有序列的平均长度调整为所有句子的长度。model_lstm = Sequential()
model_lstm.add(Embedding(20000, 100, input_length=sentence_avg_length))
model_lstm.add(LSTM(100, dropout=0.2, recurrent_dropout=0.2))
model_lstm.add(Dense(1, activation='sigmoid'))
model_lstm.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])这给出了很低的准确度~0.2
我认为这是因为上面的模型更适合于正反句,而不是摘要/非摘要句的分类。
如能就解决这一问题的方法提供任何指导,将不胜感激。
发布于 2019-01-22 06:47:31
我认为这是因为上面的模型更适合于正反句,而不是摘要/非摘要句的分类。
没错。该模型用于二值分类,而不是文本摘要。如果您注意到,输出(Dense(1, activation='sigmoid'))只给出0-1之间的分数,而在文本摘要中,我们需要一个生成一系列标记的模型。
我该怎么办?
解决这个问题的主要思想是编译码器 (也称为seq2seq)模型。Keras存储库上有一个用于机器翻译的不错的教程,但是很容易将其用于文本摘要。
守则的主要部分是:
from keras.models import Model
from keras.layers import Input, LSTM, Dense
# Define an input sequence and process it.
encoder_inputs = Input(shape=(None, num_encoder_tokens))
encoder = LSTM(latent_dim, return_state=True)
encoder_outputs, state_h, state_c = encoder(encoder_inputs)
# We discard `encoder_outputs` and only keep the states.
encoder_states = [state_h, state_c]
# Set up the decoder, using `encoder_states` as initial state.
decoder_inputs = Input(shape=(None, num_decoder_tokens))
# We set up our decoder to return full output sequences,
# and to return internal states as well. We don't use the
# return states in the training model, but we will use them in inference.
decoder_lstm = LSTM(latent_dim, return_sequences=True, return_state=True)
decoder_outputs, _, _ = decoder_lstm(decoder_inputs,
initial_state=encoder_states)
decoder_dense = Dense(num_decoder_tokens, activation='softmax')
decoder_outputs = decoder_dense(decoder_outputs)
# Define the model that will turn
# `encoder_input_data` & `decoder_input_data` into `decoder_target_data`
model = Model([encoder_inputs, decoder_inputs], decoder_outputs)
# Run training
model.compile(optimizer='rmsprop', loss='categorical_crossentropy')
model.fit([encoder_input_data, decoder_input_data], decoder_target_data,
batch_size=batch_size,
epochs=epochs,
validation_split=0.2)在以上实现的基础上,需要将encoder_input_data、decoder_input_data和decoder_target_data分别作为文本的输入文本和摘要文本传递给model.fit()。
请注意,decoder_input_data和decoder_target_data是相同的东西,只不过decoder_target_data比decoder_input_data领先一个令牌。
这给出了很低的准确度~0.2 我认为这是因为上面的模型更适合于正反句,而不是摘要/非摘要句的分类。
由于训练规模小、过装、装配不全等原因造成的精度不高。
https://stackoverflow.com/questions/54287822
复制相似问题