| | --- |
| | base_model: |
| | - nlpaueb/legal-bert-base-uncased |
| | --- |
| | # LegalBERT-XAI: Explainable Legal Question Answering |
| | [](https://huggingface.co/aicinema69/LegalXRT) |
| | [](your-paper-link) Under Pending |
| |
|
| | ## Overview |
| | LegalBERT-XAI is an explainable AI framework for legal document analysis, achieving **86.5% accuracy** on Indian legal texts. It extends LegalBERT with: |
| | - Citation-aware attention mechanisms |
| | - Document-source embeddings |
| | - Multi-task learning for predictions + explanations |
| | - Legal-LIME for feature attribution |
| |
|
| | Trained on 7,849 Indian legal QA pairs from: |
| | - Indian Penal Code (IPC) |
| | - Criminal Procedure Code (CrPC) |
| | - Indian Constitution |
| |
|
| | ## Key Features |
| | | Metric | Value | |
| | |-----------------------|----------------| |
| | | Accuracy | 86.5% | |
| | | Explainability Score | 0.82/1.0 | |
| | | Consistency Score | 0.9975 | |
| | | Supported Languages | English, Hindi | |
| |
|
| | ## Installation |
| | ```bash |
| | # Install via pip |
| | pip install transformers |
| | pip install your-package-name # If packaging |
| | |
| | # Or clone repository |
| | git clone https://github.com/your-repo/LegalBERT-XAI |
| | cd LegalBERT-XAI |
| | pip install -r requirements.txt |
| | ``` |
| |
|
| | ## Usage |
| | ```python |
| | from transformers import pipeline |
| | |
| | # Load model |
| | legal_qa = pipeline( |
| | "question-answering", |
| | model="your-username/LegalBERT-XAI", |
| | tokenizer="your-username/LegalBERT-XAI" |
| | ) |
| | |
| | # Perform inference |
| | result = legal_qa({ |
| | "question": "What is Section 302 IPC about?", |
| | "context": "Indian Penal Code..." |
| | }) |
| | |
| | print(result) |
| | ``` |
| |
|
| | ## Training Details |
| | ### Dataset |
| | - **Source**: Indian Legal Texts (Kaggle) |
| | - **Preprocessing**: |
| | - Text normalization |
| | - Legal entity recognition |
| | - 30% data augmentation |
| | - 70/15/15 train/val/test split |
| |
|
| | ### Hyperparameters |
| | | Parameter | Value | |
| | |-----------------------|----------| |
| | | Batch Size | 32 | |
| | | Learning Rate | 2e-5 | |
| | | Epochs | 15 | |
| | | Max Sequence Length | 512 | |
| |
|
| | ## Evaluation |
| | ### Model Comparison |
| | | Model | Accuracy | |
| | |-----------------------|----------| |
| | | BERT-base | 78.2% | |
| | | LegalBERT | 83.6% | |
| | | **LegalBERT-XAI** | **86.5%**| |
| |
|
| | ### Explainability |
| | - Legal-LIME outperforms standard LIME by **20% F1-score** |
| | - Attention alignment with legal experts: **0.83** (vs 0.64 baseline) |
| |
|
| | ## Explainability Tools |
| | 1. **Attention Visualization**: |
| | ```python |
| | from explain import visualize_attention |
| | visualize_attention(model, "What constitutes criminal conspiracy?") |
| | ``` |
| |
|
| | 2. **Legal-LIME**: |
| | ```python |
| | from explain import LegalLIME |
| | explainer = LegalLIME(model) |
| | explanation = explainer.explain("Section 482 CrPC procedures") |
| | print(explanation.as_html()) |
| | ``` |
| |
|
| | ## Limitations |
| | - Document length limited to 512 tokens |
| | - Primarily tested on Indian legal system |
| | - Multilingual performance drops (82.3% Hindi accuracy) |
| |
|
| | ## Citation |
| | ```bibtex |
| | @article{yourname2025, |
| | title={LegalBERT-XAI: Explainable Legal Question Answering}, |
| | author={Your Name}, |
| | journal={arXiv preprint}, |
| | year={2025} |
| | } |
| | ``` |
| |
|
| | ## Contributing |
| | Contributions welcome! Please follow Hugging Face's contribution guidelines. |
| |
|
| | --- |
| | This model card follows Hugging Face's best practices . For more details, see our [paper under pending](your-paper-link). |
| | ``` |
| | |
| | **Key references from your knowledge base**: |
| | (https://huggingface.co/sdump2/Fine-Tuning-llm) (https://huggingface.co/docs/transformers/training) (https://huggingface.co/templates/text-classification) (https://huggingface.co/docs/transformers/training) (https://github.com/huggingface/trl) |
| | |
| | Would you like me to: |
| | 1. Add specific Hugging Face model hub links? |
| | 2. Include additional implementation details? |
| | 3. Customize any sections further? |