Advanced Natural Language Processing(NLP)手法を使用した記事の簡潔な要約を提供するAIベースのWebアプリケーション。
article-summarizer-using-aiは、 NLPを使用して長い記事を要約するように設計されたWebアプリケーションです。このアプリケーションにより、ユーザーは独自の記事をアップロードしたり、サンプルデータを使用してさまざまなスタイルで概要を生成したりできます。
トレーニングと評価に使用されるデータセットは、PubMed要約データセットです。これには、要約として使用される対応する要約を含むPubMedの記事が含まれています。
データセットのロード:
from datasets import load_dataset
pubmed_data = load_dataset ( "ccdv/pubmed-summarization" , split = 'train[:1000]' )最初のデータクリーニング:
pubmed_data = pubmed_data . filter ( lambda x : x [ 'article' ] is not None and x [ 'abstract' ] is not None )探索的データ分析:
print ( pubmed_data [ 0 ]) # View the first data entry テキストトークン化:
from nltk . tokenize import sent_tokenize , word_tokenize
sentences = sent_tokenize ( article_text )
words = word_tokenize ( sentence )単語の削除を停止:
from nltk . corpus import stopwords
stop_words = set ( stopwords . words ( 'english' ))
words = [ word for word in words if word . lower () not in stop_words ]一化:
from nltk . stem import WordNetLemmatizer
lemmatizer = WordNetLemmatizer ()
words = [ lemmatizer . lemmatize ( word . lower ()) for word in words ]API構成:
google.generativeaiライブラリを使用してください。 import google . generativeai as genai
import os
api_key = os . environ . get ( 'your_api_key' )
genai . configure ( api_key = api_key )モデルの初期化:
model = genai . GenerativeModel ()PubMedデータセットでモデルを微調整して、概要の品質を向上させます。
# Example pseudo-code for fine-tuning
model . train ( dataset = pubmed_data , epochs = 10 , learning_rate = 0.001 )抽出的な要約のために、アプリケーションは従来のNLP手法を使用して、生成モデルに依存せずに記事から重要な文を特定します。
抽出概要スクリプト:
提供されたextractive_summary.pyをapp.pyに変更し、プロジェクトルートに移動します。
mv /mnt/data/extractive_summary.py app.pyコアロジック:
# Example of extractive summarization
def extractive_summary ( text ):
# Tokenize the text and rank sentences
sentences = sent_tokenize ( text )
# Rank and select key sentences (pseudo-code)
summary = ' ' . join ( sentences [: 3 ]) # Example: Select first 3 sentences
return summary統合:
@ app . route ( '/summarize' , methods = [ 'POST' ])
def summarize ():
if 'file' in request . files and request . files [ 'file' ]. filename != '' :
file = request . files [ 'file' ]
article_text = file . read (). decode ( "utf-8" )
else :
sample_index = int ( request . form [ 'sample' ])
article_text = pubmed_data [ sample_index ][ 'article' ]
style = request . form . get ( 'style' , 'brief' )
summary_method = request . form . get ( 'method' , 'generative' )
if summary_method == 'generative' :
summary_text = preprocess_and_summarize ( article_text , style )
else :
summary_text = extractive_summary ( article_text )
return render_template ( 'result.html' , original = article_text , summary = summary_text )ルージュやブルーなどのメトリックを使用して、モデルのパフォーマンスを評価します。
from nltk . translate . bleu_score import sentence_bleu
reference = [ reference_summary . split ()]
candidate = generated_summary . split ()
score = sentence_bleu ( reference , candidate )
print ( f'BLEU Score: { score } ' )フラスコのセットアップ:
from flask import Flask
from flask_login import LoginManager
app = Flask ( __name__ )
app . secret_key = 'your_secret_key'
login_manager = LoginManager ( app )ルートと認証:
@ app . route ( '/login' , methods = [ 'GET' , 'POST' ])
def login ():
# login logic here
return render_template ( 'login.html' )テンプレート:
<!-- templates/index.html -->
< form action =" {{ url_for('summarize') }} " method =" post " enctype =" multipart/form-data " >
< input type =" file " name =" file " >
< button type =" submit " > Summarize </ button >
</ form >ユーザーエクスペリエンス:
リポジトリをクローンします:
git clone https://github.com/yourusername/Article-Summarizer-Using-AI.gitプロジェクトディレクトリに移動します。
cd Article-Summarizer-Using-AI仮想環境を作成します:
python -m venv venv
source venv/bin/activate # On Windows use `venvScriptsactivate`依存関係をインストールします:
pip install -r requirements.txt環境変数を設定します:
.envファイルを作成します。 your_api_key=<YOUR_GENERATIVE_AI_API_KEY>
NLTKデータのダウンロード:
スクリプトは、必要なNLTKデータのダウンロードを処理します。
アプリケーションを実行します:
flask run --port=5001アプリへのアクセス:
http://127.0.0.1:5001にアクセスしてください。ログイン/登録:
記事の要約:
概要を見る:
記事のムライザーを使用していただきありがとうございます!要約のニーズに役立つことを願っています。