|
|
|
|
|
|
|
|
|
|
|
"""Depression: Reddit Dataset (Cleaned)""" |
|
|
|
|
|
import csv |
|
import json |
|
import os |
|
|
|
import datasets |
|
from datasets.tasks import TextClassification |
|
|
|
_DESCRIPTION = """\ |
|
The dataset provided is a Depression: Reddit Dataset (Cleaned)containing approximately |
|
7,000 labeled instances. It consists of two main features: 'clean_text' and 'is_depression'. |
|
The 'clean_text' feature contains the text data from Reddit posts related to depression, while |
|
the 'is_depression' feature indicates whether a post is classified as depression or not. |
|
|
|
The raw data for this dataset was collected by web scraping Subreddits. To ensure the data's |
|
quality and usefulness, multiple natural language processing (NLP) techniques were applied |
|
to clean the data. The dataset exclusively consists of English-language posts, and its |
|
primary purpose is to facilitate mental health classification tasks. |
|
|
|
This dataset can be employed in various natural language processing tasks related to |
|
depression,such as sentiment analysis, topic modeling, text classification, or any other NLP |
|
task that requires labeled data pertaining to depression from Reddit. |
|
""" |
|
|
|
_TRAIN_URL = "depression_reddit_cleaned_ds.csv" |
|
|
|
|
|
class DepressionRedditCleaned(datasets.GeneratorBasedBuilder): |
|
""" |
|
~7000 Cleaned Reddit Labelled Dataset on Depression |
|
The raw data is collected through web-scrapping Subreddits and is cleaned using multiple NLP techniques. |
|
The data is only in English. It mainly targets mental health classification. |
|
""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"clean_text": datasets.Value("string"), |
|
"is_depression": datasets.features.ClassLabel( |
|
num_classes=2, |
|
names=["not_depression", "depression"] |
|
) |
|
} |
|
), |
|
task_templates=[TextClassification(text_column="clean_text", label_column="is_depression")] |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
train_path = dl_manager.download_and_extract(_TRAIN_URL) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={"filepath": train_path} |
|
) |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
"""Yields examples as (key, example) tuples.""" |
|
with open(filepath, encoding="utf-8") as f: |
|
csv_reader = csv.reader(f, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True) |
|
|
|
next(csv_reader) |
|
for id_, row in enumerate(csv_reader): |
|
clean_text, is_depression = row |
|
yield id_, {"clean_text": clean_text, "is_depression": is_depression} |
|
|