Model Card for arafatanam/Mental-Health-Counselor-Qwen2.5-7B-Instruct

Model Details

Model Description

This model, arafatanam/Mental-Health-Counselor-Qwen2.5-7B-Instruct, is designed to provide compassionate, evidence-based mental health counseling for users seeking emotional and psychological support. It was fine-tuned on a dataset of mental health counseling conversations, aiming to generate empathetic and informative responses for individuals facing mental health challenges.

  • Developed by: Arafat Anam Chowdhury
  • Model type: Language Model
  • Language(s): Supports multiple languages, as Qwen models are known for multilingual capabilities.
  • License: Apache 2.0
  • Finetuned from model: unsloth/Qwen2.5-7B-Instruct

Model Sources

Uses

Direct Use

This model can be used as a standalone mental health counseling assistant to generate responses for individuals seeking support in managing stress, anxiety, and other mental health challenges. It is suited for conversational applications where a compassionate and informed response is required.

Downstream Use

It can be integrated into larger mental health support systems, web or mobile apps, or chatbots that provide automated mental health advice and resources. This model may also be employed as part of a mental health chatbot in university and community health services.

Out-of-Scope Use

This model should not be used for making medical diagnoses, nor should it replace professional mental health care. It is not suited for high-risk or severe mental health cases, such as suicidal tendencies, where immediate professional intervention is required.

Bias, Risks, and Limitations

  • The model might display biases present in the training dataset, reflecting the social and cultural perspectives of the data sources. Caution should be taken when deploying the model to ensure fairness and inclusivity in responses.
  • The model may struggle with more complex mental health scenarios that require personalized professional treatment. It is designed to provide general advice, not to replace mental health professionals.

Recommendations

  • Users should be advised that the model is for informational purposes and should not be relied upon as a sole resource for mental health management.
  • Continuous monitoring and fine-tuning are recommended to ensure the model adapts to a diverse range of user needs and minimizes biases.

How to Get Started with the Model

# Install necessary libraries and dependencies
!pip install -U torch transformers peft bitsandbytes

# Import required modules
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftConfig, PeftModel

# Define the base model and the fine-tuned adapter
base_model = "Qwen/Qwen2.5-7B-Instruct"  # Pretrained language model
adapter = "arafatanam/Mental-Health-Counselor-Qwen2.5-7B-Instruct"  # Fine-tuned model for mental health support

# Load the tokenizer (used to convert text into tokens for the model)
tokenizer = AutoTokenizer.from_pretrained(
    base_model,
    add_bos_token=True,             # Add beginning-of-sequence token
    trust_remote_code=True,         # Allow custom model code from the repository
    padding_side='left'             # Ensures padding happens on the left side
)

# Load the fine-tuned adapter using PEFT (Parameter-Efficient Fine-Tuning)
config = PeftConfig.from_pretrained(adapter)  # Load configuration for fine-tuned model
model = AutoModelForCausalLM.from_pretrained(
    config.base_model_name_or_path,           # Load base model
    load_in_4bit=True,                        # Use 4-bit precision to reduce memory usage
    device_map='auto',                        # Automatically assign model to available devices (CPU/GPU)
    torch_dtype='auto'                        # Automatically set data type for best performance
)
model = PeftModel.from_pretrained(model, adapter)  # Apply fine-tuned adapter to base model

# Move the model to the appropriate device (GPU if available, otherwise CPU)
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)                     
model.eval()  # Set model to evaluation mode (no training)

# Define an example user message (input for the chatbot)
user_message = [{"role": "user", "content": 
    "I’m facing severe depression and anxiety and I just feel like I’m going through a lot. "
    "This really distracts me and I can't get my mind off the things that are bothering me. "
    "How do I overcome this anxiety and depression?"
}]

# Convert user message into tokenized input using the chat template
input_ids = tokenizer.apply_chat_template(
    conversation=user_message,     # Provide conversation history
    tokenize=True,                 # Convert text into numerical token format
    add_generation_prompt=True,    # Indicate that this input requires a response
    return_tensors='pt'            # Return as PyTorch tensor
).to(device)

# Generate a response from the model
output_ids = model.generate(
    input_ids=input_ids,
    max_new_tokens=512,          # Limit response length for focused output
    do_sample=True,              # Enable sampling for variation in responses
    temperature=0.2,             # Controls randomness (lower is more focused)
    top_k=20,                    # Consider top 20 words per step for diversity
    top_p=0.9,                   # Sample from top 90% probability mass
    repetition_penalty=1.3,      # Reduce repetitive responses
    typical_p=0.95,              # Ensure more natural responses
    num_beams=3,                 # Use small beam search for coherent responses
    no_repeat_ngram_size=2,       # Prevent repeated two-word sequences
    pad_token_id=tokenizer.pad_token_id,
    eos_token_id=tokenizer.eos_token_id
)

# Extract only the newly generated tokens (removing the original input)
generated_ids = output_ids[:, input_ids.shape[1]:]

# Convert the generated tokens back into readable text
response = tokenizer.decode(generated_ids[0], skip_special_tokens=True)

# Clean up any extra spaces in the response
clean_response = response.strip()

# Print the chatbot's generated response
print("Generated Response:")
print(clean_response)
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for arafatanam/Mental-Health-Counselor-Qwen2.5-7B-Instruct

Base model

Qwen/Qwen2.5-7B
Finetuned
(144)
this model

Dataset used to train arafatanam/Mental-Health-Counselor-Qwen2.5-7B-Instruct