监督抽取式文本摘要

2024-05-16 19:57:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从新闻文章中提取潜在的句子,这些句子可以作为文章摘要的一部分。在

花了一段时间,我发现这可以通过两种方式实现

  1. 抽取式摘要(从文本中提取句子并将其归类)
  2. 抽象摘要(内部语言表示,生成更人性化的摘要)

{a1}

我跟随abigailsee's Get To The Point: Summarization with Pointer-Generator Networks进行总结,使用预先训练的模型可以产生很好的结果,但它是抽象的。在

问题: 到目前为止,我看到的大多数抽取式摘要生成器(pytraser、PyTextRank和Gensim)都不是基于监督学习,而是基于朴素贝叶斯分类器、tf–idf、词性标注、基于关键字频率、位置等的句子排序,不需要任何训练。在

到目前为止,我很少尝试提取潜在的摘要语句。在

  • 获取文章的所有句子,并为所有其他句子标注1和0
  • 清理文本并应用停止字过滤器
  • 使用Tokenizerfrom keras.preprocessing.text import Tokenizer将文本语料库矢量化,词汇量为20000,并将所有序列填充到所有句子的平均长度。在
  • 建立一个有序的keras模型来训练它。在
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

我认为这是因为上面的模型更适合于肯定句/否定句,而不是摘要/非摘要句分类。在

如能就解决这一问题的方法提供任何指导,我们将不胜感激。在


Tags: 模型文本add语言modela1方式文章
1条回答
网友
1楼 · 发布于 2024-05-16 19:57:58

I think this is because the above model is more suitable for positive/negative sentences rather than summary/non-summary sentences classification.

没错。以上模型用于二值分类,而不是文本摘要。如果您注意到,输出(Dense(1, activation='sigmoid'))只给您0-1的分数,而在文本摘要中,我们需要一个生成一系列标记的模型。在

我该怎么办?

解决这个问题的主要思想是encoder-decoder(也称为seq2seq)模型。在Keras上有一个用于机器翻译的nice tutorial库,但是它很容易适应文本摘要。在

代码的主要部分是:

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_datadecoder_input_data和{}分别传递给model.fit(),它们分别是输入文本和文本的摘要版本。在

注意,decoder_input_data和{}是相同的东西,除了decoder_target_data是在{}前面的一个标记。在

This is giving very low accuracy ~0.2

I think this is because the above model is more suitable for positive/negative sentences rather than summary/non-summary sentences classification.

由于训练规模小、过拟合、欠拟合等原因,导致了训练精度不高

相关问题 更多 >