File size: 2,575 Bytes
b905fe2 0a7b5ae b905fe2 0a7b5ae dfc41fe 0a7b5ae b905fe2 0a7b5ae b905fe2 7fd5f74 0a7b5ae b905fe2 0a7b5ae b905fe2 dfc41fe b905fe2 0a7b5ae b905fe2 0a7b5ae dfc41fe 0a7b5ae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
---
license: apache-2.0
tags:
- peft
- lora
- mental-health
- therapy
- transformers
- llama
- 4-bit
- bitsandbytes
library_name: peft
language:
- en
datasets:
- kunalchamoli/mental_health_v1
model_name: Meet Lora - Your Own Therapist
model_type: llama
inference: false
pipeline_tag: text-generation
---
# 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 π€](https://huggingface.co/datasets/kunalchamoli/mental_health_v1)
---
## π§ How to Use
```python
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)
|