Views
No views yet
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.transformers and accelerate libraries installed:!pip install transformers accelerate bitsandbytes -U1from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
2import torch
3
4# Load the tokenizer and model
5model_id = "chhatramani/Llama3.1-8B-nep_civillaw_finetuned"
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 torch_dtype=torch.bfloat16, # Use bfloat16 for Gemma models if your GPU supports it
10 device_map="auto"
11)
12
13# Create a pipeline for text generation
14# Ensure the chat template is applied for proper instruction following
15pipe = pipeline(
16 "text-generation",
17 model=model,
18 tokenizer=tokenizer,
19 max_new_tokens=512, # Adjust max_new_tokens as needed for answer length
20 do_sample=True,
21 temperature=0.7,
22 top_p=0.95,
23 top_k=50,
24)
251alpaca_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.
2
3### Instruction:
4{}
5
6### Response:
7{}"""
8
9inputs = tokenizer(
10[
11 alpaca_prompt.format(
12 "What are the Duty to operate and manage trust property properly", # instruction
13 "", # input
14 "", # output - leave this blank for generation!
15 )
16], return_tensors = "pt").to("cuda")
17
18from transformers import TextStreamer
19text_streamer = TextStreamer(tokenizer)
20_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 500)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.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.