Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Β 
Β 

Latest commit

Β 

History

23 Commits

Folders and files

Repository files navigation

AstroContraRag: Geometric Separation of Scientific Contradictions

Python 3.10+ PyTorch FAISS License Status

Official Implementation of "Geometric Separation of Scientific Contradictions: Mitigating Hallucinations in High-Precision Astro-RAG" Submitted to 2026 IEEE Space, Aerospace and Defence Conference (SPACE)


πŸ“‹ Abstract

The growing volume of astronomy literature requires efficient synthesis via Retrieval-Augmented Generation (RAG). However, standard dense retrievers often conflate factual claims with contradictory statements that share high lexical overlap (e.g., "Universe is expanding" vs. "Universe is contracting"), leading to hallucinations.

AstroContraRag (implementing the Astro-SparseCL pipeline) introduces a domain-adapted approach that applies Hoyer Sparsity to embedding-difference vectors. This isolates logical negation in a sparse geometric subspace. On a dataset of 107,944 claim-contradiction pairs, our method achieves 97.8% classification accuracy. By utilizing an asymmetric dual-index retrieval strategy, we reduce retrieval depth ($K=200 \to 20$), achieving a 12.96Γ— speedup while maintaining 86.7% robustness on unseen queries.


πŸ—οΈ Methodology

Our approach follows a four-stage pipeline designed to prevent the retrieval of both distractors and hard negatives in astronomical QA.

graph LR
    A[Mistral-7B] -->|Extracts Claims &<br>Generates Contradictions| B(Data Gen)
    B -->|Triplets| C[Astro-SparseCL Fine-tuning]
    C -->|Hoyer Loss Ξ±=5.88| D[Sparse-Aware Encoder]
    D -->|Embeds Corpus| E[Dual-Index FAISS]
    E -->|Asymmetric Retrieval| F[LLM-as-a-Judge Evaluation]
    
    style A fill:#f9f,stroke:#333,stroke-width:2px
    style C fill:#bbf,stroke:#333,stroke-width:2px
    style E fill:#bfb,stroke:#333,stroke-width:2px
Loading
  1. Atomic Claim Extraction: Uses Mistral-7B to refine abstracts into self-contained factual claims.
  2. Contradiction Synthesis: Generates Type-A (Distractors) and Type-B (Hard Negatives/Causal Inversions) contradictions.
  3. Sparse Contrastive Fine-Tuning: Trains BAAI/bge-base-en-v1.5 using a tailored Hoyer Sparsity Loss to enforce geometric separation.
  4. Dual-Index Retrieval: Deploys an asymmetric retrieval framework with optimized thresholds for Titles (0.53) and Abstracts (0.87).

πŸ“‚ Repository Structure

ASTROCONTRARAG/
β”œβ”€β”€ run.py                      # Main entry point for the pipeline
β”œβ”€β”€ downloder.py                # Utility to download the Pathfinder arXiv dataset
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ README.md                   # (This file)
β”œβ”€β”€ LICENSE                     # MIT License
β”‚
β”œβ”€β”€ csv/                        # Generated datasets and results
β”‚   β”œβ”€β”€ dataset.csv             # Processed claim-contradiction pairs
β”‚   β”œβ”€β”€ hyperparameter_mixed_results.csv  # Grid search results
β”‚   └── intermediate_candidates.csv       # Intermediate training data
β”‚
β”œβ”€β”€ sparse/                     # [MODULE 1 & 2] Data Generation & Training
β”‚   β”œβ”€β”€ datasetmaker.py         # Uses Mistral-7B to extract claims & generate contradictions
β”‚   β”œβ”€β”€ dcombiner.py            # Data utility to merge datasets
β”‚   β”œβ”€β”€ finetune.py             # Fine-tunes BAAI/bge-base-en-v1.5 with Hoyer Loss
β”‚   β”œβ”€β”€ plot.py                 # Training metric visualization
β”‚   β”œβ”€β”€ test_sparse.py          # Unit tests for sparsity constraints
β”‚   └── test_sparse_hyperparameter.md  # Documentation for sparsity hyperparameters
β”‚
β”œβ”€β”€ Faiss/                      # [MODULE 3] Retrieval System
β”‚   β”œβ”€β”€ encode.py               # Encodes corpus into dense/sparse vectors
β”‚   β”œβ”€β”€ hyperparameter_of_retrieval.py  # Grid search for Title/Abstract thresholds
β”‚   └── hyperparameter_of_retrieval.md  # Documentation for retrieval hyperparameters
β”‚
β”œβ”€β”€ testing/                    # [MODULE 4] Evaluation
β”‚   β”œβ”€β”€ evaluate_llm.py         # LLM-as-a-Judge validation (Llama-3.1-8B)
β”‚   β”œβ”€β”€ evaluate_csv.py         # Standard metrics (Recall, Accuracy)
β”‚   β”œβ”€β”€ test_data_creater.py    # Generates synthetic test queries
β”‚   └── accuracy.md             # Documentation for evaluation metrics
β”‚
β”œβ”€β”€ Relevant_Images/            # Generated visualizations and diagrams
β”‚
└── Visualisation Codes/        # Reproduction of Paper Figures
    β”œβ”€β”€ Alpha Optimization Curve.ipynb         # Figure 3: Optimal Alpha (5.88)
    β”œβ”€β”€ Cosine vs. Hoyer Distribution.ipynb    # Figure 2: Geometric Separation
    β”œβ”€β”€ Dual-Index Heatmap.ipynb               # Figure 4: Recall Landscape
    β”œβ”€β”€ Retrieval-Efficiency-Tradeoff.ipynb    # Figure 5: Efficiency vs. Effectiveness
    └── LLM Validation Results.ipynb           # Figure 6: Robustness Analysis

βš™οΈ Installation

Prerequisites

  • Python 3.10+
  • CUDA-enabled GPU (Minimum 1x NVIDIA RTX 3090 recommended for training)
  • 16GB+ RAM

Setup

  1. Clone the repository:

    git clone https://github.com/SamratRay2005/AstroContraRag.git
    cd AstroContraRag
  2. Install dependencies:

    pip install -r requirements.txt
  3. Download the Pathfinder arXiv dataset:

    python downloder.py --dataset kiyer/pathfinder_arxiv_data

πŸš€ Usage Guide

Step 1: Data Generation

Extract atomic claims and generate Type-B hard negatives.

Note: Configuration (overlap thresholds) is managed in the CONFIG block at the top of sparse/datasetmaker.py.

python sparse/datasetmaker.py

Step 2: Fine-Tuning (Astro-SparseCL)

Train the bi-encoder using the Hoyer Sparsity Loss.

Note: Hyperparameters (Alpha=5.88, Epochs=3) are set in the Config class within sparse/finetune.py.

python sparse/finetune.py

Step 3: Indexing & Retrieval

Encode the corpus and build the dual FAISS indices.

Note: This script automatically applies the asymmetric thresholds (0.87 for Abstracts, 0.53 for Titles).

python Faiss/encode.py

Step 4: Evaluation Pipeline

This is a two-stage process. First, generate the retrieval candidates, then validate them with the LLM.

A. Generate Candidate CSV Run standard retrieval on the test set to create intermediate_candidates.csv.

python testing/evaluate_csv.py

B. Run LLM-as-a-Judge Validate the contradictions using Llama-3.1-8B.

Note: This script processes the intermediate_candidates.csv file generated in the previous step. To limit the number of queries, modify the loop in evaluate_llm.py directly.

python testing/evaluate_llm.py

πŸ“Š Key Results

Metric Astro-SparseCL Description
Classification Accuracy 97.8% Separates contradictions from claims
Optimal Sparsity ($\alpha$) 5.88 Balanced semantic/geometric loss
Retrieval Depth ($K$) 20 90% Reduction in candidate processing
Inference Speedup 12.96Γ— Low-latency deployment
Robustness (Unseen Queries) 86.7% Validated on 2,336 novel queries

πŸ”¬ Reproducibility

To reproduce the figures and results from the paper, navigate to the Visualisation Codes/ directory and run the corresponding Jupyter notebooks:

cd "Visualisation Codes"
jupyter notebook

Paper Figures Mapping:

  • Figure 2 (Geometric Separation): Cosine vs. Hoyer Distribution.ipynb
  • Figure 3 (Optimal Alpha): Alpha Optimization Curve.ipynb
  • Figure 4 (Recall Landscape): Dual-Index Heatmap.ipynb
  • Figure 5 (Efficiency Tradeoff): Retrieval-Efficiency-Tradeoff.ipynb
  • Figure 6 (LLM Validation): LLM Validation Results.ipynb

πŸ§ͺ Testing

Run unit tests for sparsity constraints:

python sparse/test_sparse.py

Generate synthetic test queries:

python testing/test_data_creater.py

πŸ› οΈ Key Components

Hoyer Sparsity Loss

The core innovation is the Hoyer Sparsity Loss, which promotes orthogonality between contradictory embeddings:

$$ \mathcal{L}_{\text{total}} = \mathcal{L}_{\text{contrastive}} + \alpha \cdot \mathcal{L}_{\text{Hoyer}} $$

Where:

  • $\mathcal{L}_{\text{contrastive}}$: Standard contrastive loss (InfoNCE)
  • $\mathcal{L}_{\text{Hoyer}}$: Hoyer sparsity regularization on embedding-difference vectors
  • $\alpha = 5.88$: Optimized sparsity weight

Dual-Index Retrieval Strategy

  • Title Index: Threshold = 0.53 (high recall, captures broad topics)
  • Abstract Index: Threshold = 0.87 (high precision, filters contradictions)
  • Asymmetric Design: Balances efficiency and accuracy by prioritizing high-precision abstract matching

πŸ“– Citation

If you use this code or methodology in your research, please cite our submission:

@unpublished{ray2026astrocontrarag,
  title={Geometric Separation of Scientific Contradictions: Mitigating Hallucinations in High-Precision Astro-RAG},
  author={Ray, Samrat and Kulkarni, Ranjeet and Sen, Snigdha and Chakraborty, Pavan},
  note={Submitted to IEEE Space, Aerospace and Defence Conference (SPACE). Submitted: Jan 30, 2026},
  year={2026},
  month={January},
  pages={1--6},
  organization={IIIT Allahabad & Manipal Institute of Technology}
}

πŸ‘₯ Authors & Affiliations

  • Samrat Ray - Dept. of Information Technology, IIIT Allahabad
  • Ranjeet Kulkarni - Dept. of Information Technology, IIIT Allahabad
  • Snigdha Sen - Manipal Institute of Technology, MAHE
  • Pavan Chakraborty - Dept. of Information Technology, IIIT Allahabad

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.


🀝 Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.


πŸ“§ Contact

For questions or collaborations, please contact:


πŸ™ Acknowledgments

  • Pathfinder arXiv Dataset: Astronomy research papers corpus
  • BAAI/bge-base-en-v1.5: Base embedding model
  • Mistral-7B: Claim extraction and contradiction generation
  • Llama-3.1-8B: LLM-as-a-Judge validation

⚑ Built with PyTorch, FAISS, and a passion for reliable scientific AI.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages