Spaces:
Runtime error

humanizer-engine / verify_stage1.py
faseehsandhu's picture
stage 1 completed
f66da21
Raw History Blame Contribute Delete
5.27 kB
"""
Stage 1 verification script.
Runs the TextAnalyzer against all three sample inputs from the spec
WITHOUT loading Qwen2.5 (perplexity scoring is skipped — testing all other
analyzers only).
Run from the project root:
python verify_stage1.py
"""
import json
import sys
import time
# Add the project root to sys.path so "app" is importable
import os
sys.path.insert(0, os.path.dirname(__file__))
from app.core.analyzer import TextAnalyzer
# ---------------------------------------------------------------------------
# Sample inputs from the spec
# ---------------------------------------------------------------------------
SAMPLES = {
"Healthcare": (
"Artificial intelligence has fundamentally transformed the landscape of modern healthcare. "
"Through the implementation of sophisticated machine learning algorithms, medical professionals "
"can now diagnose diseases with unprecedented accuracy. Furthermore, AI-powered systems have "
"demonstrated remarkable capabilities in predicting patient outcomes, enabling proactive "
"intervention strategies. The integration of these technologies into clinical workflows represents "
"a significant paradigm shift in how healthcare services are delivered and optimized."
),
"Climate": (
"Climate change poses an existential threat to global ecosystems and human civilization. "
"The scientific consensus overwhelmingly supports the conclusion that anthropogenic greenhouse "
"gas emissions are the primary driver of observed warming trends. Consequently, nations worldwide "
"have begun implementing comprehensive mitigation strategies, including transitioning to renewable "
"energy sources and establishing carbon pricing mechanisms. However, the pace of these efforts "
"remains insufficient to meet the targets outlined in the Paris Agreement."
),
"Education": (
"The rapid advancement of educational technology has revolutionized the way students engage with "
"learning materials. Digital platforms now offer personalized learning experiences that adapt to "
"individual student needs and learning styles. Moreover, the integration of artificial intelligence "
"into educational frameworks has enabled more efficient assessment methods and targeted feedback "
"mechanisms. These innovations collectively contribute to improved learning outcomes and greater "
"accessibility in education."
),
}
# ---------------------------------------------------------------------------
# Load spaCy
# ---------------------------------------------------------------------------
print("Loading spaCy en_core_web_sm …")
import spacy
nlp = spacy.load("en_core_web_sm")
print("spaCy loaded.\n")
# Create analyzer without Qwen2.5 (perplexity_scorer=None)
analyzer = TextAnalyzer(nlp=nlp, perplexity_scorer=None)
# ---------------------------------------------------------------------------
# Run analysis on each sample
# ---------------------------------------------------------------------------
for sample_name, text in SAMPLES.items():
print("=" * 70)
print(f"SAMPLE: {sample_name}")
print("=" * 70)
print(f"Input text ({len(text.split())} words):\n{text[:120]}...\n")
t0 = time.perf_counter()
result = analyzer.analyze(text)
elapsed = (time.perf_counter() - t0) * 1000
summary = result["summary"]
print(f"Analysis time: {elapsed:.1f} ms (target: <300ms)")
print(f"\nSUMMARY:")
print(f" Total sentences : {summary['total_sentences']}")
print(f" High-risk sentences : {summary['high_risk_sentences']}")
print(f" Medium-risk sentences : {summary['medium_risk_sentences']}")
print(f" Low-risk sentences : {summary['low_risk_sentences']}")
print(f" Burstiness CV : {summary['burstiness_cv']:.3f} ({summary['burstiness_rating']})")
print(f" AI vocabulary count : {summary['ai_vocabulary_count']}")
print(f" Transition flags : {summary['transition_flags']}")
print(f" Opening pattern flags : {summary['opening_pattern_flags']}")
print(f" Overall risk : {summary['overall_risk'].upper()}")
print(f"\nBANNED WORDS FOUND ({len(result['banned_words'])}):")
print(f" {', '.join(result['banned_words'][:20])}")
print(f"\nINSTRUCTIONS ({len(result['instructions'])} total):")
for instr in result["instructions"][:8]: # show first 8
s_idx = instr.get("sentence_index", "N/A")
itype = instr.get("type", "?")
sev = instr.get("severity", "?")
text_short = instr.get("instruction", "")[:90]
print(f" [{itype:<16} | s{s_idx} | {sev:<6}] {text_short}")
if len(result["instructions"]) > 8:
print(f" ... and {len(result['instructions']) - 8} more instructions.")
print()
print("=" * 70)
print("VERIFICATION COMPLETE")
print("=" * 70)
print()
print("Checklist:")
print(" [ ] Analysis completes < 300ms per sample")
print(" [ ] Banned words correctly detected")
print(" [ ] Transition words flagged (Furthermore, Consequently, Moreover, However)")
print(" [ ] Burstiness CV is low (AI text = ~0.15-0.30)")
print(" [ ] Instructions are specific and actionable")