Downloads · 30 days
0
chhatramani/Llama3.1-8B-nep_civillaw_finetuned
Llama3.1-8B-nep_civillaw_finetuned is a question answering model from chhatramani. Use it when the input is a question plus a passage. The card lists the license as apache-2.0.
This repository contains a fine-tuned version of the Llama3.1-8B model, specifically adapted for understanding and generating responses related to Nepal Civil Law. The model has been fine-tuned using a custom-generate…
Downloads · 30 days
0
Access
Public
Updated Jul 15, 2025
Repo size
185 MB
Likes
0
Public
Click a slice to open those files.
.safetensors168 MB · 91%
From the Hugging Face model README
This repository contains a fine-tuned version of the Llama3.1-8B model, specifically adapted for understanding and generating responses related to Nepal Civil Law. The model has been fine-tuned using a custom-generated dataset derived from the Nepal Civil Code.
Llama3.1-8B-nep_civillaw_finetuned is a specialized language model designed to provide accurate and contextually relevant information on the Nepal Civil Law. It builds upon the powerful Llama3.1-8B architecture, leveraging its extensive pre-training and adapting it to the nuances of legal texts specific to Nepal.
This model is ideal for applications requiring:
To use this model, you can load it directly from Hugging Face Transformers.
First, ensure you have the transformers and accelerate libraries installed:
!pip install transformers accelerate bitsandbytes -U
Then, you can load the model for inference:
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
import torch
# Load the tokenizer and model
model_id = "chhatramani/Llama3.1-8B-nep_civillaw_finetuned"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16, # Use bfloat16 for Gemma models if your GPU supports it
device_map="auto"
)
# Create a pipeline for text generation
# Ensure the chat template is applied for proper instruction following
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
max_new_tokens=512, # Adjust max_new_tokens as needed for answer length
do_sample=True,
temperature=0.7,
top_p=0.95,
top_k=50,
)
Use Alpa syle to chat with model with text streaming
alpaca_prompt = """Below is an instruction that describes a task, coupled with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
{}
### Response:
{}"""
inputs = tokenizer(
[
alpaca_prompt.format(
"What are the Duty to operate and manage trust property properly", # instruction
"", # input
"", # output - leave this blank for generation!
)
], return_tensors = "pt").to("cuda")
from transformers import TextStreamer
text_streamer = TextStreamer(tokenizer)
_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 500)
The Llama3.1-8B-nep_civillaw_finetuned model was fine-tuned from the base Llama3.1-8B model using a Supervised Fine-Tuning (SFT) approach with the trl library's SFTTrainer.
civil_code_en.pdf document.The following SFTConfig parameters were used during the training process:
| Parameter | Value |
|---|---|
dataset_text_field | "text" |
per_device_train_batch_size | 4 |
gradient_accumulation_steps | 4 |
warmup_ratio | 0.03 |
num_train_epochs | 3 |
learning_rate | 2e-4 |
logging_steps | 10 |
optim | "adamw_8bit" |
weight_decay | 0.01 |
lr_scheduler_type | "cosine" |
seed | 3407 |
report_to | "none" |
fp16 | True |
dataset_text_field: Specifies the column in the training dataset that contains the formatted text for training (instruction + response).per_device_train_batch_size: The batch size per GPU during training. Set to 4.gradient_accumulation_steps: Gradients are accumulated over 4 steps, leading to an effective batch size of 16 (4 * 4) per GPU.warmup_ratio: The proportion of training steps over which the learning rate linearly increases from 0. Set to 0.03 (3% of total steps).num_train_epochs: The total number of training epochs to perform. Set to 3 to ensure the model sees the entire 2712-row dataset multiple times.learning_rate: The initial learning rate for the optimizer. A value of 2e-4 is common for LoRA fine-tuning.logging_steps: Logs training metrics every 10 steps.optim: The optimizer used, adamw_8bit for memory-efficient AdamW.weight_decay: L2 regularization applied to the weights to prevent overfitting.lr_scheduler_type: The learning rate scheduler type, cosine for a cosine annealing schedule.seed: Random seed for reproducibility.report_to: Specifies integration with experiment tracking platforms (set to none here).fp16: Enables mixed-precision training using float16, which speeds up training and reduces memory usage.As with all large language models, this fine-tuned model may exhibit certain limitations and biases:
license: apache-2.0 tags: