SarcasmNet/self-annotated_reddit_climate_comment
Dataset Card for Self-annotated Reddit Climate Comment Dataset Structure This JSON example represents an example portion of the dataset. This nested structure allows for efficient navigation and analysis of posts, comments, and replies within specific subreddit communities and individual posts. { "id": "1006cei", "post_title": "Amazing Water Filter Invention", "post_author": "User123", "post_body": "Check out this incredible water filter!", "post_url":… See the full description on the dataset page: https://huggingface.co/datasets/SarcasmNet/self-annotated_reddit_climate_comment.
132
1import csv2import json3import os4from datasets import GeneratorBasedBuilder, Features, Value, Sequence, SplitGenerator, BuilderConfig, DatasetInfo, Split, Image5import logging6import pandas as pd7from typing import Dict8 9CITATION = ""10_DESCRIPTION = "" 11_HOMEPAGE = "https://huggingface.co/datasets/SarcasmNet/self-annotated_reddit_climate_comment"12_LICENSE = "MIT"13 14_URL = "https://github.com/catherine-ywang/Reddit-Climate-Environment-Sarcasm-Self-Annotated-Data/raw/main/self_annotated_comments.csv"15 16class NewDataset(GeneratorBasedBuilder):17 def _info(self):18 return DatasetInfo(19 description=_DESCRIPTION,20 features=Features({21 "id": Value("string"),22 "post_title": Value("string"),23 "post_author": Value("string"),24 "post_body": Value("string"),25 "post_url": Value("string"),26 "post_pic": Image(),27 "subreddit": Value("string"),28 "post_timestamp": Value("string"),29 "post_upvotes": Value("int32"),30 "post_permalink": Value("string"),31 "comments": Sequence({32 "CommentID": Value("string"),33 "CommentAuthor": Value("string"),34 "CommentBody": Value("string"),35 "CommentTimestamp": Value("string"),36 "CommentUpvotes": Value("int32"),37 "CommentPermalink": Value("string"),38 "Label": Value("int32")39 })40 }),41 homepage=_HOMEPAGE,42 )43 def _split_generators(self, dl_manager):44 return [SplitGenerator(name=Split.TRAIN, gen_kwargs={"filepath": dl_manager.download(_URL)})]45 46 def _generate_examples(self, filepath):47 df = pd.read_csv(filepath)48 for column in df.columns:49 df[column] = df[column].replace({pd.NA: None})50 # Group the DataFrame by post ID51 grouped_df = df.groupby('PostID')52 53 for post_id, group in grouped_df:54 post_data = group.iloc[0] # Get the data for the post55 56 post_title = post_data['PostTitle']57 post_author = post_data['PostAuthor']58 post_body = post_data['PostBody']59 post_url = post_data['PostUrl']60 post_pic = post_data['PostPic']61 subreddit = post_data['Subreddit']62 post_timestamp = post_data['PostTimestamp']63 post_upvotes = post_data['PostUpvotes']64 post_permalink = post_data['PostPermalink']65 66 comments = []67 68 # Iterate over each unique comment ID69 for comment_id in group['CommentID'].unique():70 comment_data = group[group['CommentID'] == comment_id].iloc[0]71 72 comment_author = comment_data['CommentAuthor']73 comment_body = comment_data['CommentBody']74 comment_timestamp = comment_data['CommentTimestamp']75 comment_upvotes = comment_data['CommentUpvotes']76 comment_permalink = comment_data['CommentPermalink']77 comment_label = comment_data['Label']78 79 # Add comment with its replies to the list80 comment = {81 "CommentID": comment_id,82 "CommentAuthor": comment_author,83 "CommentBody": comment_body,84 "CommentTimestamp": comment_timestamp,85 "CommentUpvotes": comment_upvotes,86 "CommentPermalink": comment_permalink,87 "Label": comment_label88 }89 comments.append(comment)90 91 example = {92 "id": post_id,93 "post_title": post_title,94 "post_author": post_author,95 "post_body": post_body,96 "post_url": post_url,97 "post_pic": post_pic,98 "subreddit": subreddit,99 "post_timestamp": post_timestamp,100 "post_upvotes": post_upvotes,101 "post_permalink": post_permalink,102 "comments": comments103 }104 105 yield post_id, example106 107 108 109 