NLP (National Natural Language Processing) 기술을 사용하여 기사의 간결한 요약을 제공하는 AI 기반 웹 응용 프로그램.
Article-Summarizer-using-AI 는 NLP를 사용하는 긴 기사를 요약하도록 설계된 웹 응용 프로그램입니다. 응용 프로그램을 통해 사용자는 자체 기사를 업로드하거나 샘플 데이터를 사용하여 생성 AI 모델을 사용하여 다양한 스타일로 요약을 생성 할 수 있습니다.
교육 및 평가에 사용되는 데이터 세트는 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 )Rouge 또는 Bleu와 같은 메트릭을 사용하여 모델의 성능을 평가하십시오.
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 방문하십시오.로그인/레지스터 :
기사 요약 :
요약보기 :
Article-Summarizer-using-AI를 사용해 주셔서 감사합니다! 요약 요구에 유용하다는 것을 알게되기를 바랍니다.