Falcon3-1B-MentalHealth is a fine-tuned version of the tiiuae/Falcon3-1B-Instruct model, adapted for providing empathetic and contextually relevant responses to mental health-related queries.
Since it is fine-tuned on an Instruct model, it's responses are contextually appropriate and reasonable.
The model has been trained on a curated dataset to assist in mental health conversations, offering advice, guidance, and support for individuals dealing with issues like stress, anxiety, and depression.
It provides a compassionate approach to mental health queries while focusing on promoting emotional well-being and mental health awareness.
As Mental Health is a sensitive topic, it would be preferable to use the code snippet provided below in order to get optimal results. It is expected that this model will be used responsibly.
This is a LoRA adapter for the Falcon3-1B-Instruct LLM which has been merged with the respective base model. It was fine-tuned on the 'marmikpandya/mental-health' dataset.
1import torch
2import re
3from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
4
5# Load the model from Hugging Face
6model_name = "ShivomH/Falcon3-1B-MentalHealth"
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
9
10# Move the model to GPU if available
11device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
12model.to(device)
13
14def chat():
15
16 print("Chat with your fine-tuned Falcon model (type 'exit' to quit):")
17
18 system_instruction = (
19 "### Instruction:\n"
20 "You are an empathetic AI specialized in mental health support. "
21 "Do not respond to topics that are unrelated to the medical domain. \n"
22 "If a crisis situation is detected, suggest reaching out to a mental health professional immediately. "
23 "Your responses should be clear, precise, supportive, comforting and free from speculation."
24 )
25
26 # Store short chat history for context
27 chat_history = []
28
29 while True:
30 user_input = input("\nYou: ")
31 if user_input.lower() == "exit":
32 break
33
34 # Maintain short chat history (last 3 exchanges)
35 chat_history.append(f"User: {user_input}")
36 chat_history = chat_history[-1:]
37
38 prompt = f"{system_instruction}\n\n" + "\n".join(chat_history) + "\nAssistant:"
39
40 inputs = tokenizer(prompt, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
41
42 with torch.no_grad():
43 output = model.generate(
44 **inputs,
45 max_new_tokens=100,
46 pad_token_id=tokenizer.eos_token_id,
47 temperature=0.5,
48 top_p=0.85,
49 repetition_penalty=1.2,
50 do_sample=True,
51 no_repeat_ngram_size=3,
52 early_stopping=True
53 )
54
55 response = tokenizer.decode(output[0], skip_special_tokens=True).strip()
56
57 if "Assistant:" in response:
58 response = response.split("Assistant:", 1)[-1].strip()
59
60 # Remove URLs from the response
61 response = re.sub(r'http[s]?://\S+', '', response)
62
63 print(f"Assistant: {response}")
64
65chat()