YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Haan โ auto-generated blank card hai! README.md add karo model repo mein.
huggingface.co/Ayushi054/BNS-Legal-Phi2 pe jao โ Files โ README.md edit karo โ yeh paste karo:
---
language:
- en
license: mit
base_model: microsoft/phi-2
tags:
- legal
- india
- bns
- bharatiya-nyaya-sanhita
- fine-tuned
- lora
- indian-law
pipeline_tag: text-generation
---
# BNS Legal Phi-2 โ Bharatiya Nyaya Sanhita 2023
A fine-tuned **microsoft/phi-2** model trained with **LoRA** on a custom dataset derived from the **Bharatiya Nyaya Sanhita (BNS) 2023** โ India's new criminal law code that replaced IPC 1860.
## Model Details
| Property | Value |
|---|---|
| Base Model | microsoft/phi-2 (2.7B parameters) |
| Fine-tuning Method | LoRA (rank=16, bf16) |
| Training Data | 3,000 BNS 2023 QA pairs |
| Training Hardware | Kaggle T4 x2 GPU |
| Training Time | ~6.5 hours |
| Best Eval Loss | 0.1489 |
| Epochs | 3 |
## Training Results
| Step | Train Loss | Val Loss |
|---|---|---|
| 100 | 0.5038 | 0.4434 |
| 200 | 0.3125 | 0.2603 |
| 300 | 0.2217 | 0.1872 |
| 400 | 0.1725 | 0.1489 |
| 500 | 0.1661 | 0.1423 |
## Dataset
Custom dataset of **3,000 samples** generated from BNS 2023 PDF:
| Type | Count |
|---|---|
| Definition | ~358 |
| Punishment | ~280 |
| Scenario | ~200 |
| Augmented | ~2,000 |
## How to Use
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_name = "Ayushi054/BNS-Legal-Phi2"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16,
device_map="cpu",
trust_remote_code=True,
)
prompt = """Instruct: You are a legal AI assistant for BNS 2023.
Query: What is murder under BNS?
Output:"""
inputs = tokenizer(prompt, return_tensors="pt")
with torch.no_grad():
output = model.generate(**inputs, max_new_tokens=300, temperature=0.1, do_sample=True)
print(tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
Live Demo
Try the model at: BNS Legal Chat Space
Intended Use
- Educational purposes only
- Understanding BNS 2023 provisions
- Legal research and reference
Disclaimer
This model is for educational purposes only and does not constitute legal advice. Always consult a qualified legal professional for legal matters.
License
MIT ```
- Downloads last month
- 9
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐ Ask for provider support