{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Using the latest cached version of the module from C:\\Users\\ericr\\.cache\\huggingface\\modules\\datasets_modules\\datasets\\steamcyclone--Pill_Ideologies-Post_Titles\\793a6b87307104ca492b65c5a82ea97d785585b22683f670e677e61876e2166c (last modified on Tue Mar 19 04:37:51 2024) since it couldn't be found locally at steamcyclone/Pill_Ideologies-Post_Titles, or remotely on the Hugging Face Hub.\n" ] } ], "source": [ "import datasets\n", "\n", "test = datasets.load_dataset(\"steamcyclone/Pill_Ideologies-Post_Titles\", trust_remote_code=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "DatasetDict({\n", " train: Dataset({\n", " features: ['subreddit', 'id', 'title', 'text', 'url', 'score', 'date', 'subreddit_subscribers', 'num_comments', 'ups', 'downs', 'upvote_ratio', 'is_video'],\n", " num_rows: 5123\n", " })\n", " validation: Dataset({\n", " features: ['subreddit', 'id', 'title', 'text', 'url', 'score', 'date', 'subreddit_subscribers', 'num_comments', 'ups', 'downs', 'upvote_ratio', 'is_video'],\n", " num_rows: 1281\n", " })\n", " test: Dataset({\n", " features: ['subreddit', 'id', 'title', 'text', 'url', 'score', 'date', 'subreddit_subscribers', 'num_comments', 'ups', 'downs', 'upvote_ratio', 'is_video'],\n", " num_rows: 712\n", " })\n", "})" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Concatenate the Datasets" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "train = pd.DataFrame(test[\"train\"])\n", "validation = pd.DataFrame(test[\"validation\"])\n", "test = pd.DataFrame(test[\"test\"])" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "# concatenate all the dataframes\n", "\n", "df = pd.concat([train, validation, test])" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.shape == (len(train) + len(validation) + len(test), len(train.columns))" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [], "source": [ "# preparing feature engineering by targetting mentions of words\n", "gendered_words_men = [\"boy\", \"boys\", \"man\", \"men\", \"guy\", \"guys\", \"he\", \"him\", \"his\"]\n", "gendered_words_father = [\"father\", \"dad\", \"daddy\"]\n", "gendered_words_brother = [\"brother\", \"brothers\"]\n", "gendered_words_son = [\"son\", \"sons\"]\n", "gendered_words_uncle = [\"uncle\", \"uncles\"]\n", "gendered_words_nephew = [\"nephew\", \"nephews\"]\n", "gendered_words_husband = [\"husband\", \"husbands\", \"spouse\", \"spouses\"]\n", "gendered_words_boyfriend = [\"boyfriend\", \"boyfriends\", \"partner\", \"partners\"]\n", "\n", "gendered_words_women = [\n", " \"women\",\n", " \"woman\",\n", " \"girl\",\n", " \"girls\",\n", " \"she\",\n", " \"her\",\n", " \"hers\",\n", " \"lady\",\n", " \"ladies\",\n", "]\n", "gendered_words_mother = [\n", " \"mother\",\n", " \"mothers\",\n", " \"mom\",\n", " \"moms\",\n", " \"mama\",\n", " \"mamas\",\n", " \"mum\",\n", " \"mommy\",\n", " \"mommies\",\n", "]\n", "gendered_words_sister = [\"sister\", \"sisters\"]\n", "gendered_words_daughter = [\"daughter\", \"daughters\"]\n", "gendered_words_aunt = [\"aunt\", \"aunts\"]\n", "gendered_words_niece = [\"niece\", \"nieces\"]\n", "gendered_words_wife = [\"wife\", \"wives\", \"spouse\", \"spouses\"]\n", "gendered_words_girlfriend = [\"girlfriend\", \"girlfriends\", \"partner\", \"partners\"]\n", "\n", "# physical relations\n", "sex_words = [\"sex\", \"sexual\", \"sexual\", \"intercourse\", \"intimacy\", \"intimate\"]\n", "female_organs_words = [\"breasts\", \"boobs\", \"vagina\", \"pussy\", \"vulva\", \"clitoris\"]\n", "male_organ_words = [\"penis\", \"cock\", \"dick\", \"balls\", \"testicles\"]\n", "pregnancy_words = [\n", " \"pregnancy\",\n", " \"pregnant\",\n", " \"conceive\",\n", " \"conception\",\n", " \"conceiving\",\n", " \"conceived\",\n", " \"miscarriage\",\n", " \"miscarry\",\n", " \"miscarried\",\n", " \"miscarrying\",\n", " \"abortion\",\n", " \"abort\",\n", " \"aborted\",\n", " \"aborting\",\n", " \"abortions\",\n", "]\n", "menstrual_words = [\"period\", \"menstruation\", \"menstrual\", \"cramps\"]\n", "love_words = [\n", " \"love\",\n", " \"loves\",\n", " \"loved\",\n", " \"loving\",\n", " \"lover\",\n", " \"lovers\",\n", " \"lovable\",\n", " \"loveable\",\n", " \"lovingly\",\n", " \"unloved\",\n", " \"beloved\",\n", " \"loveless\",\n", " \"lovesick\",\n", " \"self-love\",\n", "]\n", "romance_words = [\n", " 'romance',\n", " \"romantic\",\n", " \"romantically\",\n", " \"romanticism\",\n", " \"romanticist\",\n", " \"romanticize\",\n", " \"romanticized\",\n", " \"romanticizing\",\n", " \"romanticization\",\n", " \"romanticised\",\n", " \"romanticising\",\n", " \"romanticise\",\n", "]\n", "\n", "self_words = [\n", " \"i\",\n", " \"me\",\n", " \"my\",\n", " \"mine\",\n", " \"myself\",\n", " \"self\",\n", " \"mine\"]\n", "\n", "social_media_websites = [\n", " \"facebook\",\n", " \"instagram\",\n", " \"twitter\",\n", " \"linkedIn\",\n", " \"snapchat\",\n", " \"tikTok\",\n", " \"pinterest\",\n", " \"reddit\",\n", " \"youTube\",\n", " \"whatsapp\",\n", " \"wechat\",\n", " \"telegram\",\n", " \"tumblr\",\n", " \"discord\",\n", " \"clubhouse\",\n", " \"twitch\",\n", " \"vine\",\n", " \"Myspace\"\n", "]\n", "\n", "otherness = ['he', 'him', 'her', 'she', 'they', 'them', 'it', 'its', 'their', 'theirs']\n", "\n", "togetherness = ['our', 'ours', 'us', 'we', 'ourselves']\n", "\n", "negative_male = [\"ass\", \"asshole\", \"jerk\", \"dick\"]\n", "negative_female = [\"bitch\", \"whore\", \"whores\", \"hoe\", \"hoes\"]\n", "\n", "\n", "total_male_list = gendered_words_men + gendered_words_father + gendered_words_brother + gendered_words_son + gendered_words_uncle + gendered_words_nephew + gendered_words_husband + gendered_words_boyfriend + male_organ_words\n", "total_female_list = gendered_words_women + gendered_words_mother + gendered_words_sister + gendered_words_daughter + gendered_words_aunt + gendered_words_niece + gendered_words_wife + menstrual_words + pregnancy_words + female_organs_words + gendered_words_girlfriend" ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [], "source": [ "df['title_processed'] = df['title'].str.lower()\n", "df['title_processed'] = df['title_processed'].str.replace('[^\\w\\s]','')\n", "df['title_split'] = df['title_processed'].str.split()\n", "df['title_count'] = df['title_split'].apply(len)\n", "\n", "\n", "df['text_processed'] = df['text'].str.lower()\n", "df['text_processed'] = df['text_processed'].str.replace('[^\\w\\s]','')\n", "df['text_split'] = df['text_processed'].str.split()\n", "df['text_count'] = df['text_split'].apply(len)\n", "\n", "# remove stopwords\n", "stop = stopwords.words('english')\n", "df['title_split'] = df['title_split'].apply(lambda x: [item for item in x if item not in stop])\n", "df['text_split'] = df['text_split'].apply(lambda x: [item for item in x if item not in stop])\n" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 [casual, sex, perceived, men, women]\n", "1 [wrong, \"settle\", can't, get, really, want?]\n", "2 [anyone, else, annoyed, seeing, valentines, po...\n", "3 [60, dod, 2019, -, official, kickoff]\n", "4 [go, getting, relationship]\n", "Name: title_split, dtype: object" ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df['title_split'].head()" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | subreddit | \n", "id | \n", "title | \n", "text | \n", "url | \n", "score | \n", "date | \n", "subreddit_subscribers | \n", "num_comments | \n", "ups | \n", "... | \n", "title_I_count | \n", "text_I_count | \n", "title_i_count | \n", "text_i_count | \n", "title_facebook_count | \n", "text_facebook_count | \n", "title_he_count | \n", "text_he_count | \n", "title_our_count | \n", "text_our_count | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "PurplePillDebate | \n", "1bbj8lq | \n", "How casual sex is perceived for men and women | \n", "In regards to the famous double standard (how ... | \n", "\n", " | 0 | \n", "1.710100e+09 | \n", "127329 | \n", "199 | \n", "0 | \n", "... | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
1 | \n", "PurplePillDebate | \n", "1aigdg6 | \n", "Is it wrong to \"settle\" because you can't get ... | \n", "I wanted to discuss this from the **male's per... | \n", "\n", " | 33 | \n", "1.707024e+09 | \n", "127329 | \n", "360 | \n", "33 | \n", "... | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
2 | \n", "ForeverAloneWomen | \n", "1aqwejo | \n", "Is anyone else annoyed by seeing all the valen... | \n", "I removed instagram and facebook from my phone... | \n", "\n", " | 54 | \n", "1.707941e+09 | \n", "22857 | \n", "5 | \n", "54 | \n", "... | \n", "0 | \n", "3 | \n", "0 | \n", "0 | \n", "0 | \n", "2 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
3 | \n", "marriedredpill | \n", "b45byj | \n", "60 DoD 2019 - Official kickoff | \n", "Rejoice, for 60 DoD 2019 is finally here! I kn... | \n", "\n", " | 60 | \n", "1.553263e+09 | \n", "50459 | \n", "50 | \n", "60 | \n", "... | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
4 | \n", "ForeverAloneWomen | \n", "18uwb2f | \n", "How do I go about getting in a relationship | \n", "I 21 tried to date for years...and so far ive ... | \n", "\n", " | 24 | \n", "1.703988e+09 | \n", "22857 | \n", "31 | \n", "24 | \n", "... | \n", "0 | \n", "3 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
5 rows × 76 columns
\n", "\n", " | subreddit | \n", "id | \n", "title | \n", "text | \n", "url | \n", "score | \n", "date | \n", "subreddit_subscribers | \n", "num_comments | \n", "ups | \n", "... | \n", "title_facebook_count | \n", "text_facebook_count | \n", "title_he_count | \n", "text_he_count | \n", "title_our_count | \n", "text_our_count | \n", "title_ass_count | \n", "text_ass_count | \n", "title_bitch_count | \n", "text_bitch_count | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "PurplePillDebate | \n", "1bbj8lq | \n", "How casual sex is perceived for men and women | \n", "In regards to the famous double standard (how ... | \n", "\n", " | 0 | \n", "1.710100e+09 | \n", "127329 | \n", "199 | \n", "0 | \n", "... | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
1 | \n", "PurplePillDebate | \n", "1aigdg6 | \n", "Is it wrong to \"settle\" because you can't get ... | \n", "I wanted to discuss this from the **male's per... | \n", "\n", " | 33 | \n", "1.707024e+09 | \n", "127329 | \n", "360 | \n", "33 | \n", "... | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
2 | \n", "ForeverAloneWomen | \n", "1aqwejo | \n", "Is anyone else annoyed by seeing all the valen... | \n", "I removed instagram and facebook from my phone... | \n", "\n", " | 54 | \n", "1.707941e+09 | \n", "22857 | \n", "5 | \n", "54 | \n", "... | \n", "0 | \n", "2 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
3 | \n", "marriedredpill | \n", "b45byj | \n", "60 DoD 2019 - Official kickoff | \n", "Rejoice, for 60 DoD 2019 is finally here! I kn... | \n", "\n", " | 60 | \n", "1.553263e+09 | \n", "50459 | \n", "50 | \n", "60 | \n", "... | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
4 | \n", "ForeverAloneWomen | \n", "18uwb2f | \n", "How do I go about getting in a relationship | \n", "I 21 tried to date for years...and so far ive ... | \n", "\n", " | 24 | \n", "1.703988e+09 | \n", "22857 | \n", "31 | \n", "24 | \n", "... | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "0 | \n", "
5 rows × 80 columns
\n", "