CoolFace
Apppublic

ayushsaun/Kharagpur-Data-Science-Hackathon-KDSH-2026

sourceHugging Facemitupdated 8mo agoView on Hugging Face
1likes
App README

Narrative Consistency Verification (CPU Demo)

This repository hosts a CPU-only Hugging Face Space for verifying whether a hypothetical character backstory is consistent or contradictory with a long-form narrative. The system is inference-only and focuses on reasoning, contradiction detection, and evidence verification rather than supervised training.

The demo is designed to run on free, on-demand CPU resources and is intended for research demonstration, evaluation, and portfolio purposes.


What This Project Does

Given:

  • —A long narrative (one or more books in plain text format)
  • —A hypothetical character backstory

The system determines whether the backstory:

  • —aligns with the original story (consistent), or
  • —contradicts facts, events, or timelines in the story (contradict)

This problem is treated as a verification and reasoning task, not as a standard text classification problem.


Core Approach

The pipeline follows a multi-stage inference-only design:

  1. 1.Evidence Retrieval The narrative text is split into multi-scale overlapping chunks. A bi-encoder retrieves the most relevant passages for the given backstory.
  1. 1.Contradiction Detection A natural language inference (NLI) model evaluates whether the retrieved evidence entails or contradicts the backstory.
  1. 1.Reasoning-Based Verification A lightweight instruction-tuned language model reasons over the evidence and NLI signals to produce a final decision.
  1. 1.Rule-Guided Arbitration Explicit contradiction or entailment signals override ambiguous reasoning outputs to avoid majority-class collapse.

This mirrors how humans verify claims against long texts: retrieve relevant context, check for contradictions, then reason globally.


Why Inference-Only

Supervised training performed poorly due to:

  • —Very small labeled dataset
  • —Class imbalance
  • —Negation-heavy contradictions
  • —Long-range dependencies across narratives

An inference-only reasoning pipeline proved more stable and interpretable for this task.


Models Used (CPU-Compatible)

  • —Sentence Embedding Model sentence-transformers/all-mpnet-base-v2
  • —Natural Language Inference roberta-large-mnli
  • —Reasoning Model google/flan-t5-base

All models run entirely on CPU and are selected to balance reasoning capability with feasibility on free Hugging Face infrastructure.


Input Format

Books

  • —Upload a ZIP file containing one or more .txt files
  • —Each file should contain the full text of a narrative

Book Name

  • —The name of the book, matching the uploaded filename (case-insensitive)

Backstory

  • —A single hypothetical character backstory provided as plain text

Output

The system returns one of the following labels:

  • —consistent
  • —contradict

These indicate whether the backstory aligns with or violates the narrative evidence.


How to Use (Hugging Face Space)

  1. 1.Upload a ZIP file containing book text files
  2. 2.Enter the book name
  3. 3.Paste a hypothetical backstory
  4. 4.Click “Verify Consistency”
  5. 5.Wait approximately 20–40 seconds for the result

This latency is expected on CPU-only resources.


Repository Structure

app.py Gradio application entry point for the Hugging Face Space

main.py Core inference and reasoning pipeline

requirements.txt Python dependencies for CPU execution

README.md Project documentation


Limitations

  • —CPU-only execution results in higher latency
  • —Designed for single backstory evaluation per request
  • —Not intended for high-throughput or production deployment

The goal is interpretability and correctness, not scale.


Generality

Although demonstrated on literary narratives, the system can be applied to:

  • —Any long-form document
  • —Hypothetical or counterfactual claims
  • —Consistency and contradiction verification tasks

Only the input text and backstory need to be changed.


Intended Audience

  • —Hackathon judges evaluating reasoning quality
  • —Recruiters assessing system design and ML maturity
  • —Researchers interested in inference-time verification

License

This project is released under the Apache 2.0 License and is free to use for research and educational purposes.


Note

This repository intentionally presents a clean, final solution. Earlier experimental approaches and training-based baselines were excluded to keep the demo focused on the most effective and principled method.