Meet Lora β Your Own Therapist π§ π¬
It is a fine-tuned LLM built to simulate a therapist, trained on a dataset of therapy sessions.
It leverages Parameter-Efficient Fine-Tuning (PEFT) using LoRA (Low-Rank Adaptation) on Meta LLaMA 2 7B.
The model was fine-tuned on a Tesla T4 GPU, selectively training a small number of parameters to efficiently adapt the base model to the domain of mental health and therapy.
π‘ Dataset used is available on Hugging Face π€
π§ How to Use
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
# Load the base model in 4-bit precision
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_quant_type="nf4"
)
base_model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-2-7b-hf",
quantization_config=bnb_config,
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")
# Load the adapter
model = PeftModel.from_pretrained(base_model, "aryan27/llama-therapy-lora")
# System prompt to guide behavior
system_prompt = (
"You are a compassionate and thoughtful therapist. "
"Your responses are empathetic, non-judgmental, and helpful."
)
# π§© Function to generate response
def generate_therapy_response(user_input: str):
prompt = f"{system_prompt}\nUser: {user_input}\nTherapist:"
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=200,
do_sample=True,
temperature=0.7,
top_p=0.9,
repetition_penalty=1.1,
pad_token_id=tokenizer.eos_token_id
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
# Strip off the prompt from the generated text
response_only = response.split("Therapist:")[-1].strip()
return response_only
# π¬ Example usage
response = generate_therapy_response("I feel demotivated because of my breakup")
print(response)
- Downloads last month
- 3
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
π
Ask for provider support