如何解决如何使用 lambda_ 参数的值 0.2
我被难住了。我对 Python 和文本挖掘还是很陌生。我知道我需要做的事情非常简单,但我不知道如何使用 lambda_ 参数的值 0.2 生成一篇关于印第安纳州的文章的提取摘要。
我为初学者尝试过这个
#define a function that will generate an extractive summary of the article's text by identifying the best
#representative,non-redundant sentence in each paragraph; i.e.,the sentence with the Maximum Marginal Relevance (MMR).
def get_extractive_summary(lambda_):
#NOTE: the lambda parameter controls the level of relevance vs. redundancy among the sentences in the summary
summary_sentences = []
for paragraph_id in range(len(paragraphs)): #for each paragraph ID
#extract the TF-IDF scores for this paragraph's sentences from the dataframe
df_sentences = df[['tfidf_scores']][df.paragraph_id == paragraph_id]
#identify the sentence with the Maximum Marginal Relevance (MMR) for this paragraph
maximum_marginal_relevance = -np.inf #holds the MMR for the sentences in this paragraph
best_sentence = None #holds the sentence with the MMR
for sentence in df_sentences.itertuples(): #for each sentence in this paragraph
#calculate the cosine similarity between this sentence's TF-IDF scores and the article's centroid
similarity_to_article = cosine_similarity(np.reshape(sentence.tfidf_scores,(1,-1)),centroid)[0][0]
#calculate the maximum cosine similarity between this sentence and any already-chosen summary sentences
max_similarity_to_summary_sentence = -np.inf
for sentence_id,summary_sentence_tfidf_scores in summary_sentences:
similarity_to_summary_sentence = cosine_similarity(np.reshape(sentence.tfidf_scores,np.reshape(summary_sentence_tfidf_scores,-1)))[0][0]
if similarity_to_summary_sentence > max_similarity_to_summary_sentence:
max_similarity_to_summary_sentence = similarity_to_summary_sentence
#compute the marginal relevance for this sentence
marginal_relevance = ((1 - lambda_) * similarity_to_article) - (lambda_ * max_similarity_to_summary_sentence)
if marginal_relevance > maximum_marginal_relevance:
maximum_marginal_relevance = marginal_relevance
best_sentence = (sentence.Index,sentence.tfidf_scores)
#add the sentence with the Maximum Marginal Relevance (MMR) for this paragraph to the collection of summary sentences
summary_sentences.append(best_sentence)
#construct and return the summary of the article
article_summary = ''
for sentence_id,_ in summary_sentences:
article_summary += df.iloc[sentence_id]['raw_text'] + ' '
return article_summary.strip()
get_extractive_summary(lambda 0.2)
但它出错并说 lambda 没有定义,但它是由 def 函数定义的。
感谢任何帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。