Views
No views yet
1- Rank (r): 8
2- Alpha: 16
3- Target modules: ["q_proj", "v_proj"]
4- Dropout: 0.05pip install transformers torch accelerate peft1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4# Load model and tokenizer
5model_name = "subrit/gemma-3-270m-indian-legal"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(
8 model_name,
9 device_map="auto",
10 torch_dtype=torch.float32
11)
12
13# Inference
14def generate_answer(question, max_length=150):
15 prompt = f"[INST] {question} [/INST]"
16 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
17
18 outputs = model.generate(
19 **inputs,
20 max_new_tokens=max_length,
21 temperature=0.4,
22 top_p=0.85,
23 do_sample=True,
24 repetition_penalty=1.2,
25 no_repeat_ngram_size=3
26 )
27
28 answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
29 # Extract answer after [/INST]
30 answer = answer.split("[/INST]")[-1].strip()
31 return answer
32
33# Example usage
34question = "Explain bail in Indian law with an example."
35answer = generate_answer(question)
36print(answer)1generation_config = {
2 "max_new_tokens": 100,
3 "temperature": 0.4, # Lower = more factual
4 "top_p": 0.85, # Focused sampling
5 "do_sample": True,
6 "repetition_penalty": 1.2,
7 "no_repeat_ngram_size": 3,
8}"Mens Rea refers to the mental state of a person when he commits an offence, and it includes his knowledge or belief that they are guilty of committing such offences..."
"This model was created by Subrit Dikshit."
1@misc{dikshit2026gemma-indian-legal,
2 author = {Dikshit, Subrit},
3 title = {Gemma-3-270m Indian Legal QA},
4 year = {2026},
5 publisher = {HuggingFace},
6 howpublished = {\url{https://huggingface.co/subrit/gemma-3-270m-indian-legal}},
7 note = {Gemma model for Indian legal domain}
8}Dikshit, S. (2026). Gemma-3-270m Indian Legal QA.
HuggingFace Model Hub. https://huggingface.co/subrit/gemma-3-270m-indian-legalDikshit, Subrit. "Gemma-3-270m Indian Legal QA."
HuggingFace Model Hub, 2026, huggingface.co/subrit/gemma-3-270m-indian-legal.1@article{gemma_2024,
2 title={Gemma: Open Models Based on Gemini Research and Technology},
3 author={Gemma Team},
4 journal={Google DeepMind},
5 year={2024},
6 url={https://arxiv.org/abs/2403.08295}
7}1@misc{lozhkov2024fineweb,
2 title={The FineWeb Datasets: Decanting the Web for the Finest Text Data at Scale},
3 author={Anton Lozhkov and Raymond Li and Loubna Ben Allal and Federico Cassano and Joel Lamy-Poirier and Nouamane Tazi and Ao Tang and Dmytro Pykhtar and Jian Zhu and Colin Raffel and Leandro von Werra and Thomas Wolf},
4 year={2024},
5 eprint={2406.17557},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2406.17557}
9}1@misc{kalamkar2024aalap,
2 title={Aalap: AI Assistant for Legal and Paralegal functions in India},
3 author={Prathamesh Kalamkar and Saurabh Karn and Smita Gupta and Vivek Raghavan},
4 year={2024},
5 eprint={2402.01758},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2402.01758}
9}1@misc{nisaar2023lawyergpt,
2 author = {Nisaar},
3 title = {Lawyer_GPT_India Dataset},
4 year = {2023},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/datasets/nisaar/Lawyer_GPT_India}}
7}1@misc{dikshit2026indian-legal-dataset,
2 author = {Dikshit, Subrit},
3 title = {Indian Legal Concepts Dataset for Fine-tuning},
4 year = {2026},
5 note = {Custom curated dataset of 250 samples covering Indian legal concepts}
6}1@article{hu2021lora,
2 title={LoRA: Low-Rank Adaptation of Large Language Models},
3 author={Hu, Edward J and Shen, Yelong and Wallis, Phillip and Allen-Zhu, Zeyuan and Li, Yuanzhi and Wang, Shean and Wang, Lu and Chen, Weizhu},
4 journal={arXiv preprint arXiv:2106.09685},
5 year={2021}
6}