Artificial Intelligence project 03
AI Extractive Text Summarizer Project
Build a complete extractive text summarizer workflow with reproducible Python code, transparent inputs, reviewable output, and responsible-use limits.
Explore AI training in VizagView all project ideas
AI objective
Select the most informative source sentences without generating facts that are absent from the input.
Data or knowledge source
User-provided plain text split into sentences; the demo article discusses AI data, evaluation, monitoring, and review.
Requirements
- Python 3.10 or later
- A terminal or command prompt
python -m pip install numpy scikit-learn- About 45-60 minutes to build and review
How the system works
Split sentences, calculate TF-IDF features, normalise sentence scores for length, select the highest scores, and restore original order.
Validation checklist
- The requested sentence count is respected
- Every summary sentence is copied from the source
- Short documents are returned without failure
- No external model or network request is required
Complete Python code
Save the program as ai_extractive_text_summarizer.py. The code runs locally and requires no paid API key or model download.
"""Create an extractive summary by ranking source sentences with TF-IDF."""
from __future__ import annotations
import re
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
def split_sentences(text: str) -> list[str]:
return [part.strip() for part in re.split(r"(?<=[.!?])\s+", text.strip()) if part.strip()]
def summarize(text: str, sentences: int = 3) -> str:
source = split_sentences(text)
if not source or sentences < 1:
return ""
if len(source) <= sentences:
return " ".join(source)
matrix = TfidfVectorizer(stop_words="english").fit_transform(source)
scores = np.asarray(matrix.sum(axis=1)).ravel() / np.sqrt(np.maximum(1, (matrix != 0).sum(axis=1).A1))
selected = sorted(scores.argsort()[-sentences:].tolist())
return " ".join(source[index] for index in selected)
def main() -> None:
article = (
"Artificial intelligence systems learn patterns from data. Good datasets need clear ownership and documentation. "
"Evaluation should reflect the real task and user population. A high average score can hide weak performance for important groups. "
"Teams should monitor deployed systems because data and behaviour change. Human review is essential for high-impact decisions."
)
print(summarize(article, sentences=3))
print("This method selects source sentences; it does not generate new facts.")
if __name__ == "__main__":
main()
Run the project
- Create and activate a virtual environment.
- Install dependencies with
python -m pip install numpy scikit-learnwhen packages are required. - Run
python ai_extractive_text_summarizer.py. - Review confidence, fallbacks, sources, or error metrics rather than accepting output automatically.
- Test additional normal, edge, unsupported, and adversarial inputs.
Expected output
A concise extractive summary containing only original sentences.
Accuracy, privacy, and responsible-use limits
TF-IDF importance does not guarantee complete or balanced coverage. Extractive summaries can omit qualifications and should not replace review of legal, medical, financial, or safety-critical text.
Ways to extend the project
Add section-aware scoring, redundancy removal, query-focused summaries, evaluation against human references, and citation offsets.
Continue learning Artificial Intelligence
Try the next project, return to the Softenant project library, or explore the AI training in Vizag for guided NLP, retrieval, evaluation, automation, and responsible AI practice.