Downloads · 30 days
6
46% of all-time downloads
anasakram/llama_fine_tuned_spanish
llama_fine_tuned_spanish is a machine learning model from anasakram. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for peft.
llamafinetunedspanish is a fine-tuned version of NousResearch/llama-2-7b-chat-hf, designed to solve reasoning-heavy questions in English and provide step-by-step solutions in Spanish. The model uses LoRA (Low-Rank Ada…
Downloads · 30 days
6
46% of all-time downloads
All-time downloads
13
Public
Repo size
269 MB
Likes
0
Public
Click a slice to open those files.
.safetensors134 MB · 97%
From the Hugging Face model README
llama_fine_tuned_spanish is a fine-tuned version of NousResearch/llama-2-7b-chat-hf, designed to solve reasoning-heavy questions in English and provide step-by-step solutions in Spanish. The model uses LoRA (Low-Rank Adaptation) for efficient fine-tuning and 4-bit quantization, making it suitable for deployment in resource-constrained environments like Kaggle.
You can load and use the model as follows:
!pip install transformers torch peft bitsandbytes
# Step 1: Import necessary libraries
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline, BitsAndBytesConfig
from peft import PeftModel
import torch
# Step 2: Define repository and load tokenizer
repo_id = "anasakram/llama_fine_tuned_spanish"
tokenizer = AutoTokenizer.from_pretrained(repo_id)
# Step 3: Set up quantization config (matches training setup)
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16,
)
# Step 4: Load the base model with quantization
base_model = AutoModelForCausalLM.from_pretrained(
"NousResearch/llama-2-7b-chat-hf",
quantization_config=bnb_config,
device_map={"": 0} # Map to GPU 0
)
# Step 5: Load the fine-tuned LoRA weights
model = PeftModel.from_pretrained(base_model, repo_id)
# Step 6: Create text generation pipeline
gen = pipeline('text-generation', model=model, tokenizer=tokenizer, max_length=500) # Max length for generation
# Step 7: Define system message and prompt
system_message = (
"Given a puzzle-like, reasoning-heavy question in English, provide an accurate, "
"step-by-step solution in Spanish. For multi-part problems, calculate each segment "
"separately, sum distances and times correctly, and verify all steps logically to "
"ensure the final answer is correct."
)
prompt = (
f"[INST] <<SYS>>\n{system_message}\n<</SYS>>\n\n"
"A car travels 100 km at 50 km/h and 50 km at 25 km/h. What is the average speed? [/INST]"#Enter Your Puzzle Here
)
# Step 8: Generate and print response
result = gen(prompt)
print("Generated Response:")
print(result[0]['generated_text'].replace(prompt, '')) # Print only the generated part
train.jsonl), 20 validation examples (test.jsonl)