Spaces:
Running on Zero
Running on Zero
File size: 11,670 Bytes
90fa9aa | 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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | import os
import random
try:
import pandas as pd
except ImportError:
pd = None
from pathlib import Path
import sys
# Ensure config is importable
sys.path.append(str(Path(__file__).resolve().parent.parent.parent))
from src.config import TEXT_DATASET_PATH, MENTAL_HEALTH_CATEGORIES
# Vocabulary pools based on empirical findings in Paper #14 & #8
ACADEMIC_TEMPLATES = [
"I have {num} major exams next week and my coursework deadlines are overwhelming me completely.",
"The assignment deadline for {subject} is tomorrow and I am terrified about my grades and GPA.",
"I can't focus on my lectures because the exam pressure and coursework difficulty are causing severe concentration difficulties.",
"My thesis defense and final semester exams are approaching, and the workload anxiety is keeping me awake all night.",
"The competition in university for top grades and placement is making my daily stress unbearable.",
"I am falling behind on my {subject} assignments and the fear of failing my semester is paralyzing my productivity.",
"Trying to balance {num} lectures, lab reports, and continuous assessments is causing immense academic fatigue.",
"I feel constant pressure from my professors and exam deadlines, and my academic performance is dropping rapidly.",
"Whenever I open my textbooks for {subject}, my heart races due to performance anxiety and fear of low marks.",
"The grading criteria are so strict that no matter how hard I study, I worry about losing my scholarship."
]
NON_ACADEMIC_TEMPLATES = [
"I feel lonely and depressed because of family issues and difficult personal relationship struggles at home.",
"Financial problems and paying for living expenses are causing me severe anxiety and emotional distress.",
"My personal relationships are falling apart and I feel isolated from my friends and social circle.",
"Dealing with health issues and family expectations at the same time makes me feel hopeless every day.",
"Moving to higher education away from my family has caused deep loneliness and social adjustment difficulties.",
"I feel a constant sense of sadness and emptiness inside that has nothing to do with school or studies.",
"My family relationships are very strained right now, and the emotional burden is weighing heavily on my mental health.",
"Financial insecurity and debt are constantly on my mind, leading to sleepless nights and panic attacks.",
"I recently went through a tough breakup and the emotional pain makes it impossible to enjoy anything in life.",
"I feel disconnected from everyone around me and struggle with severe social isolation in my dormitory."
]
MIXED_TEMPLATES = [
"Between my upcoming {subject} exams and severe financial problems at home, I am completely overwhelmed and stressed.",
"I can't study for my {num} assignments because my family relationship breakdown and loneliness are destroying my focus.",
"My grades are slipping due to exam pressure, and on top of that, my financial debt and personal health issues are worsening.",
"I feel anxious all the time because my academic workload is huge and I also have no social support or friends here.",
"The fear of failing my {subject} coursework combined with family expectations and financial stress is making me feel hopeless.",
"I am dealing with both academic exhaustion from late-night studying and emotional distress from relationship conflicts.",
"My daily life is a struggle right now because of university exam competition and personal family drama happening simultaneously.",
"I feel paralyzed by academic pressure while simultaneously fighting depression and loneliness in my personal life.",
"Balancing part-time job hours to solve financial problems while preparing for {num} university exams is burning me out completely.",
"I experience constant physical symptoms of stress from coursework deadlines combined with emotional anxiety about my future and relationships."
]
CALM_TEMPLATES = [
"I completed my {subject} assignment early today and enjoyed a nice relaxing dinner with my friends.",
"My study schedule is well organized and I feel confident about my upcoming lectures and coursework progress.",
"I had a great balance today between studying for my classes and spending quality time exercising and relaxing.",
"I feel calm and motivated about my academic journey, and my personal relationships are very supportive.",
"Everything is going smoothly with my semester projects and I slept a restful eight hours last night.",
"I attended all my university lectures today and understood the concepts clearly without any anxiety.",
"My friends and family have been very encouraging, which helps me stay positive and focused on my goals.",
"I took a helpful walk after finishing my homework and feel refreshed and mentally balanced.",
"I am enjoying the topics discussed in my {subject} class and feel prepared for upcoming assessments.",
"My daily routine is healthy, allowing me to manage my workload effectively while keeping my mental peace."
]
DEPRESSION_TEMPLATES = [
"I feel a constant sense of sadness and emptiness inside that makes it hard to get out of bed.",
"Nothing brings me joy anymore, and I feel completely hopeless about my future.",
"I am so depressed that even simple daily tasks feel like an impossible burden.",
"My energy levels are completely depleted and I just want to sleep all day.",
"I feel completely isolated and worthless, struggling with severe depression.",
"It is hard to find any meaning in my {subject} studies because I feel so empty.",
"I feel like I am falling into a dark hole and no one understands how hopeless I feel.",
"I have lost interest in all my hobbies and spending time with my friends feels exhausting.",
"Every day feels like a heavy struggle and I just want to give up entirely.",
"The sadness is overwhelming and I constantly cry for no specific reason."
]
ANXIETY_TEMPLATES = [
"I feel constantly on edge and my heart races for no apparent reason.",
"My mind is always racing with worst-case scenarios and I can't stop worrying.",
"I'm experiencing panic attacks and severe anxiety about everyday situations.",
"I feel restless and terrified that something bad is going to happen.",
"My anxiety is so bad that I can't breathe properly when I'm in public.",
"I constantly worry about my {subject} grades to the point of feeling physically sick.",
"The fear of failure keeps me awake all night with a racing heartbeat.",
"I feel a constant nervous tension in my stomach that won't go away.",
"Even small tasks make me feel terrified and overwhelmed with anxiety.",
"I am constantly panicking about my future and feel scared all the time."
]
EMOTIONAL_DISTRESS_TEMPLATES = [
"I'm completely overwhelmed with grief and emotional pain right now.",
"I feel like I'm breaking down emotionally and can't handle this intense distress.",
"Everything is too much to bear and I'm crying uncontrollably from the emotional pain.",
"I'm dealing with severe trauma and emotional distress that is tearing me apart.",
"The emotional suffering is unbearable and I feel like I'm losing control.",
"I am in so much emotional agony that I cannot focus on my {subject} classes.",
"My heart hurts from the intense emotional distress I am experiencing daily.",
"I feel shattered inside and the trauma is completely overwhelming my life.",
"The emotional burden I carry is unbearable and I feel like I am breaking.",
"I am going through a severe emotional crisis and desperately need help."
]
SUBJECTS = ["Computer Science", "Data Structures", "Machine Learning", "Mathematics", "Software Engineering", "Physics", "Thermodynamics", "Digital Logic", "Operating Systems", "Algorithms"]
def calculate_first_person_pronoun_ratio(text):
words = text.lower().split()
if not words:
return 0.0
first_person_words = {"i", "me", "my", "mine", "myself", "we", "our", "us"}
count = sum(1 for w in words if w in first_person_words)
return round(count / len(words), 4)
def calculate_negative_word_density(text):
words = text.lower().split()
if not words:
return 0.0
neg_words = {"stress", "stressed", "overwhelmed", "anxiety", "anxious", "depressed", "depression", "fear", "terrified", "hopeless", "lonely", "isolation", "panic", "fatigue", "falling", "failing", "pain", "sadness", "emptiness", "burnout"}
count = sum(1 for w in words if w in neg_words)
return round(count / len(words), 4)
def generate_dataset(total_samples=1500):
print(f"Generating synthetic/curated student mental health text dataset ({total_samples} samples)...")
data = []
samples_per_cat = total_samples // 6
# Helper to randomize templates
def build_samples(templates, label, count):
cat_data = []
for _ in range(count):
tpl = random.choice(templates)
subj = random.choice(SUBJECTS)
num = random.randint(2, 5)
text = tpl.format(subject=subj, num=num)
# Add slight random variations/modifiers to ensure vocabulary richness
modifiers = [
"",
" Honestly, it is very hard to cope right now.",
" I don't know what to do next.",
" It has been like this for several weeks.",
" I really need some advice or support.",
" My daily focus has dropped significantly.",
" I hope things improve soon."
] if label != "Calm / Normal" else [
"",
" Looking forward to a productive week ahead.",
" I am grateful for the balance.",
" Feeling very peaceful right now.",
" It feels good to stay organized."
]
text += random.choice(modifiers)
# Compute linguistic metadata
fp_ratio = calculate_first_person_pronoun_ratio(text)
neg_density = calculate_negative_word_density(text)
word_count = len(text.split())
cat_data.append({
"text": text,
"category": label,
"first_person_ratio": fp_ratio,
"negative_word_density": neg_density,
"word_count": word_count
})
return cat_data
data.extend(build_samples(ACADEMIC_TEMPLATES, "Academic Stress", samples_per_cat))
data.extend(build_samples(NON_ACADEMIC_TEMPLATES, "Non-Academic Stress", samples_per_cat))
data.extend(build_samples(MIXED_TEMPLATES, "Mixed Stress", samples_per_cat))
data.extend(build_samples(DEPRESSION_TEMPLATES, "Depression", samples_per_cat))
data.extend(build_samples(ANXIETY_TEMPLATES, "Anxiety", samples_per_cat))
data.extend(build_samples(EMOTIONAL_DISTRESS_TEMPLATES, "Emotional Distress", samples_per_cat))
# Fill remaining with Calm
remaining = total_samples - len(data)
data.extend(build_samples(CALM_TEMPLATES, "Calm / Normal", remaining))
# Shuffle dataset
random.seed(42)
random.shuffle(data)
df = pd.DataFrame(data)
os.makedirs(os.path.dirname(TEXT_DATASET_PATH), exist_ok=True)
df.to_csv(TEXT_DATASET_PATH, index=False)
print(f"Successfully generated {len(df)} samples and saved to {TEXT_DATASET_PATH}")
return df
if __name__ == "__main__":
df = generate_dataset(1500)
print(df["category"].value_counts())
|