Views
No views yet
README.md add karo model repo mein.huggingface.co/Ayushi054/BNS-Legal-Phi2 pe jao → Files → README.md edit karo → yeh paste karo:1---
2language:
3 - en
4license: mit
5base_model: microsoft/phi-2
6tags:
7 - legal
8 - india
9 - bns
10 - bharatiya-nyaya-sanhita
11 - fine-tuned
12 - lora
13 - indian-law
14pipeline_tag: text-generation
15---
16
17# BNS Legal Phi-2 — Bharatiya Nyaya Sanhita 2023
18
19A 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.
20
21## Model Details
22
23| Property | Value |
24|---|---|
25| Base Model | microsoft/phi-2 (2.7B parameters) |
26| Fine-tuning Method | LoRA (rank=16, bf16) |
27| Training Data | 3,000 BNS 2023 QA pairs |
28| Training Hardware | Kaggle T4 x2 GPU |
29| Training Time | ~6.5 hours |
30| Best Eval Loss | 0.1489 |
31| Epochs | 3 |
32
33## Training Results
34
35| Step | Train Loss | Val Loss |
36|---|---|---|
37| 100 | 0.5038 | 0.4434 |
38| 200 | 0.3125 | 0.2603 |
39| 300 | 0.2217 | 0.1872 |
40| 400 | 0.1725 | 0.1489 |
41| 500 | 0.1661 | 0.1423 |
42
43## Dataset
44
45Custom dataset of **3,000 samples** generated from BNS 2023 PDF:
46
47| Type | Count |
48|---|---|
49| Definition | ~358 |
50| Punishment | ~280 |
51| Scenario | ~200 |
52| Augmented | ~2,000 |
53
54## How to Use
55
56```python
57from transformers import AutoTokenizer, AutoModelForCausalLM
58import torch
59
60model_name = "Ayushi054/BNS-Legal-Phi2"
61tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
62model = AutoModelForCausalLM.from_pretrained(
63 model_name,
64 torch_dtype=torch.float16,
65 device_map="cpu",
66 trust_remote_code=True,
67)
68
69prompt = """Instruct: You are a legal AI assistant for BNS 2023.
70Query: What is murder under BNS?
71Output:"""
72
73inputs = tokenizer(prompt, return_tensors="pt")
74with torch.no_grad():
75 output = model.generate(**inputs, max_new_tokens=300, temperature=0.1, do_sample=True)
76print(tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))