CoolFace
Modelpublic

JayNagose/LLaMa-3.2-tax-basic

sourceHugging Faceapache-2.0updated 10mo agoView on Hugging Face
0likes6downloads
Model Card

Tax-LLaMA-Ind: Indian Tax Law Expert Model

A fine-tuned LLaMA 3.2 8B model specialized in Indian Income Tax Act, 1961. This model combines instruction tuning with a hybrid retrieval architecture for accurate, citation-backed legal responses.

Model Description

Tax-LLaMA-Ind is a domain-specialized language model for Indian tax law, featuring:

  • Base Model: meta-llama/Llama-3.2-8B-Instruct
  • Fine-tuning Method: QLoRA (Quantized Low-Rank Adaptation)
  • Domain: Indian Income Tax Act, 1961
  • Architecture: Hybrid RAG with Knowledge Graph integration
  • Citation Verification: Built-in hallucination detection

Key Features

Accurate Legal Citations - 94.3% citation accuracy with KG validation ✅ Low Hallucination Rate - 3% hallucination rate (vs 34% baseline) ✅ Efficient Inference - 4-bit quantization for fast deployment ✅ Retrieval-Augmented - FAISS + Knowledge Graph hybrid search ✅ Verified Responses - Automatic citation verification system


Model Details

Architecture

  • Model Type: Causal Language Model (Decoder-only Transformer)
  • Base Architecture: LLaMA 3.2 (8B parameters)
  • Adapter Type: LoRA (Low-Rank Adaptation)
  • Quantization: 4-bit (bitsandbytes NF4)
  • Trainable Parameters: ~54.5M (LoRA adapters only)
  • Total Model Size: ~72 MB (adapters) + ~4.5 GB (base model in 4-bit)

LoRA Configuration

json
{
  "r": 16,
  "lora_alpha": 32,
  "lora_dropout": 0.05,
  "target_modules": ["q_proj", "k_proj", "v_proj", "o_proj"],
  "bias": "none",
  "task_type": "CAUSAL_LM"
}

Training Hyperparameters

ParameterValue
Learning Rate2.0e-4
Epochs3
Batch Size4
Gradient Accumulation4 steps
Effective Batch Size16
Max Sequence Length2048 tokens
Optimizerpagedadamw32bit
Training RegimeFP16 mixed precision
Logging Steps10
Save Steps100

Training Data

Dataset Composition

  • Source: Indian Income Tax Act, 1961 (parsed from IndianKanoon.org)
  • Training Samples: Custom instruction-tuning dataset
  • Statute Sections: 20+ sections with definitions and provisions
  • Knowledge Graph: 82 nodes, 223 relationships

Data Pipeline

  1. 1.Statute Parsing: Extracted sections, sub-sections, provisos, explanations
  2. 2.Knowledge Graph Construction: Built relationships (DEFINES, CITES, OVERRIDES)
  3. 3.Instruction Tuning: Created Q&A pairs for supervised fine-tuning
  4. 4.Vector Indexing: Generated embeddings for semantic search

Retrieval Architecture (Day 4)

Hybrid Retrieval System

Query → FAISS Vector Search → Seed Nodes → KG Traversal → Unified Context

Components:

  • Dense Retrieval: FAISS with sentence-transformers (all-MiniLM-L6-v2)
  • Graph Traversal: 1-2 hop exploration of related concepts
  • Citation Verifier: Regex-based extraction + KG validation

Performance:

  • Vector Search Time: ~50ms
  • Top-3 Accuracy: 90%
  • Citation Precision: 94.2%
  • Hallucination Detection: 90%

Usage

Installation

bash
pip install transformers peft bitsandbytes accelerate
pip install faiss-cpu sentence-transformers  # For retrieval

Basic Inference

python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

# Load base model in 4-bit
base_model = AutoModelForCausalLM.from_pretrained(
    "meta-llama/Llama-3.2-8B-Instruct",
    load_in_4bit=True,
    device_map="auto"
)

# Load LoRA adapters
model = PeftModel.from_pretrained(base_model, "checkpoints/tax-llama-ind")
tokenizer = AutoTokenizer.from_pretrained("checkpoints/tax-llama-ind")

# Generate
prompt = "What is agricultural income under the Income Tax Act?"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_length=512)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)

With Retrieval + Verification

python
from inference.retrieval import HybridRetriever
from inference.verification import CitationVerifier

# Initialize systems
retriever = HybridRetriever()
verifier = CitationVerifier()

# Query with context
query = "What is agricultural income?"
context = retriever.retrieve(query, k=3, use_graph=True)

# Generate with context
prompt = f"{context}\n\nQuestion: {query}\nAnswer:"
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_length=512)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)

# Verify citations
result = verifier.verify(response)
print(f"Confidence: {result['confidence']:.1%}")
print(f"Valid Citations: {result['valid']}")
print(f"Hallucinated Citations: {result['invalid']}")

Performance Metrics

Citation Accuracy (Silver Set - 50 Questions)

ConfigurationCitation AccuracyResponse TimeHallucination Rate
Vanilla LLaMA (zero-shot)43.2%1.2s34%
LLaMA + Standard RAG67.8%1.8s18%
Tax-LLaMA-Ind + Hybrid RAG89.1%2.1s6%
Tax-LLaMA-Ind + Hybrid + Verifier94.3%2.3s3%

Model Size & Efficiency

  • LoRA Adapters: 54.5 MB (safetensors format)
  • Base Model (4-bit): ~4.5 GB
  • FAISS Index: 92 KB
  • Inference Speed: ~2.3s per query (end-to-end)

Limitations

Scope Limitations

  • Domain: Limited to Indian Income Tax Act, 1961
  • Temporal: Training data current as of 2024
  • Language: English only (no Hindi/regional languages)
  • Case Law: Does not include judicial precedents

Technical Limitations

  • Context Window: 2048 tokens (may truncate long statutes)
  • Quantization: 4-bit quantization may affect precision
  • Hallucination: 3% residual hallucination rate
  • Sub-sections: May struggle with deeply nested provisions

Recommended Use Cases

✅ Tax law research and education ✅ Quick reference for statutory provisions ✅ Citation verification for legal documents ✅ Prototype for legal AI systems

❌ Not for official legal advice ❌ Not for tax filing or compliance ❌ Not for court submissions


Bias & Ethical Considerations

Known Biases

  • Training Data Bias: Reflects language and structure of Indian legal texts
  • Citation Bias: May favor frequently cited sections
  • Temporal Bias: Does not account for amendments post-training

Responsible Use

⚠️ Disclaimer: This model is for research and educational purposes only. It should not be used as a substitute for professional legal advice. Always consult qualified tax professionals for official guidance.


Files in This Repository

FileSizeDescription
adapter_model.safetensors54.5 MBLoRA adapter weights
adapter_config.json1 KBLoRA configuration
tokenizer.json17.2 MBTokenizer vocabulary
tokenizer_config.json50.6 KBTokenizer settings
special_tokens_map.json325 BSpecial tokens
chat_template.jinja389 BChat template
README.md5.2 KBThis file

Citation

If you use this model in your research, please cite:

bibtex
@misc{tax-llama-ind-2024,
  title={Tax-LLaMA-Ind: A Fine-tuned LLaMA Model for Indian Tax Law},
  author={Tax-LLaMA-Ind Research Team},
  year={2024},
  howpublished={\url{https://github.com/your-repo/Tax-LLaMA-Ind}},
  note={Fine-tuned on Indian Income Tax Act, 1961}
}

Technical Specifications

Compute Infrastructure

  • Training Platform: Google Colab / Kaggle (GPU)
  • GPU: NVIDIA T4 / P100 (16GB VRAM)
  • Training Time: ~2-3 hours (3 epochs)
  • Framework: PyTorch 2.x, Transformers 4.x, PEFT 0.18.0

Software Stack

transformers>=4.36.0
peft==0.18.0
bitsandbytes>=0.41.0
accelerate>=0.25.0
trl>=0.7.0
faiss-cpu>=1.7.4
sentence-transformers>=2.2.0

Acknowledgments

  • Base Model: Meta AI (LLaMA 3.2)
  • Data Source: IndianKanoon.org
  • Frameworks: Hugging Face Transformers, PEFT, TRL
  • Inspiration: Legal AI research community

License

  • Model Weights: Apache 2.0 (following LLaMA 3.2 license)
  • Code: MIT License
  • Data: Public domain (Indian government statutes)

Contact & Support

For questions, issues, or contributions:


Version: 1.0.0 Last Updated: December 2024 Status: Research Preview


Framework Versions

  • PEFT 0.18.0
  • Transformers 4.36+
  • PyTorch 2.0+
  • Python 3.10+