Instructions to use anasakram/llama_fine_tuned_spanish with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use anasakram/llama_fine_tuned_spanish with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("NousResearch/llama-2-7b-chat-hf") model = PeftModel.from_pretrained(base_model, "anasakram/llama_fine_tuned_spanish") - Notebooks
- Google Colab
- Kaggle
Model Card: llama_fine_tuned_spanish
Model Description
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.
- Developer: Anas Akram
- Model Type: Causal Language Model (fine-tuned with LoRA)
- Languages: English (input), Spanish (output)
- License: [To be specified, e.g., Apache 2.0 or MIT]
- Base Model: NousResearch/llama-2-7b-chat-hf
Model Sources
- Hugging Face Repository: anasakram/llama_fine_tuned_spanish
Intended Use
Direct Use
- Educational Purposes: Assisting students with math, physics, and logic puzzles by generating detailed, step-by-step solutions in Spanish.
- Bilingual Reasoning Tasks: Translating and solving problems from English prompts into structured Spanish responses.
Limitations & Risks
- Scope: Not designed for general conversation, factual knowledge retrieval, or multi-language tasks beyond English-Spanish reasoning.
- Accuracy Issues: The model may struggle with complex multi-step reasoning problems or deviate from expected outputs if inputs differ from training patterns.
- Potential Hallucinations: It may produce incorrect calculations or steps if faced with unfamiliar problem structures.
How to Use
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
Training Details
Training Data
- Dataset: 200 examples (
train.jsonl), 20 validation examples (test.jsonl) - Task: Solving speed/distance/time, geometry, and logic puzzles in Spanish.
Training Procedure
- Fine-Tuning Method: LoRA with 4-bit quantization
- Epochs: 10
- Batch Size: Effective batch size of 8 (2 per device, 4 gradient accumulation steps)
- Learning Rate: 2e-4
- Optimizer: Paged AdamW 32-bit
- Max Sequence Length: 512
Evaluation
- Metric: Validation loss (lower is better)
- Performance:
- Correctly solves standard speed problems (e.g., 80 km at 40 km/h and 60 km at 30 km/h → 35 km/h)
- Struggles with certain generalization cases
Environmental Impact
- Training Hardware: Kaggle GPU (likely NVIDIA T4)
- Training Time: ~1-2 hours
- Estimated Carbon Emissions: Low (can be estimated using ML CO2 Impact calculators)
Model Architecture & Infrastructure
- Architecture: Transformer-based causal language model with LoRA adapters
- Objective: Generate accurate, step-by-step Spanish solutions to English reasoning prompts
- Compute Environment: Kaggle GPU, Transformers library, PEFT 0.14.0, PyTorch
Model Card Authors
- Anas Akram
- Downloads last month
- 1
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support