{ "cells": [ { "cell_type": "markdown", "id": "54d7cbbf", "metadata": {}, "source": [ "# Sentiment Analysis Pipeline (Simplified & Consistent)\n", "\n", "This notebook demonstrates a streamlined workflow for sentiment analysis on YouTube comments, including data loading, cleaning, feature engineering, model training, evaluation, and visualization. Steps are merged and redundant code is removed for clarity and consistency." ] }, { "cell_type": "code", "execution_count": 6, "id": "d21b91a8", "metadata": {}, "outputs": [], "source": [ "from huggingface_hub import notebook_login\n", "\n", "notebook_login()" ] }, { "cell_type": "code", "execution_count": 7, "id": "7696aa2e", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[nltk_data] Downloading package stopwords to /root/nltk_data...\n", "[nltk_data] Package stopwords is already up-to-date!\n", "[nltk_data] Downloading package wordnet to /root/nltk_data...\n", "[nltk_data] Package wordnet is already up-to-date!\n", "[nltk_data] Downloading package omw-1.4 to /root/nltk_data...\n", "[nltk_data] Package omw-1.4 is already up-to-date!\n", "[nltk_data] Downloading package punkt to /root/nltk_data...\n", "[nltk_data] Package punkt is already up-to-date!\n", "[nltk_data] Downloading package punkt_tab to /root/nltk_data...\n", "[nltk_data] Package punkt_tab is already up-to-date!\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Loaded 1032225 rows from looh2/data/youtube_comments_cleaned.csv\n" ] } ], "source": [ "# Step 1: Data Loading, Cleaning, and Preprocessing\n", "import os\n", "import pandas as pd\n", "import re\n", "import nltk\n", "from huggingface_hub import hf_hub_download, list_repo_files\n", "from nltk.corpus import stopwords\n", "from nltk.stem import WordNetLemmatizer\n", "from nltk.tokenize import word_tokenize\n", "import string\n", "\n", "# Download required NLTK resources (run once)\n", "nltk.download('stopwords')\n", "nltk.download('wordnet')\n", "nltk.download('omw-1.4')\n", "nltk.download('punkt')\n", "nltk.download('punkt_tab')\n", "\n", "# Load data from Hugging Face Hub (validated file lookup)\n", "repo_id = os.getenv('HF_DATASET_REPO', 'looh2/data')\n", "csv_name = os.getenv('HF_DATA_FILE', 'youtube_comments_cleaned.csv')\n", "\n", "repo_files = list_repo_files(repo_id=repo_id, repo_type='dataset')\n", "if csv_name not in repo_files:\n", " raise FileNotFoundError(f'{csv_name} not found in {repo_id}')\n", "\n", "csv_path = hf_hub_download(\n", " repo_id=repo_id,\n", " filename=csv_name,\n", " repo_type='dataset'\n", " )\n", "\n", "df = pd.read_csv(csv_path, low_memory=False)\n", "print(f'Loaded {len(df)} rows from {repo_id}/{csv_name}')" ] }, { "cell_type": "code", "execution_count": null, "id": "081e9e22", "metadata": { "vscode": { "languageId": "markdown" } }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 8, "id": "4a66dac7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
| \n", " | Sentiment | \n", "CommentText | \n", "CleanedComment | \n", "
|---|---|---|---|
| 0 | \n", "Neutral | \n", "anyone know what movie this is? | \n", "anyone know movie | \n", "
| 1 | \n", "Positive | \n", "the fact they're holding each other back while... | \n", "fact theyre holding back equally aggressive | \n", "
| 2 | \n", "Neutral | \n", "waiting next video will be? | \n", "waiting next video | \n", "
| 3 | \n", "Neutral | \n", "thanks for the great video.\\n\\ni don't underst... | \n", "thanks great video dont understand db continue... | \n", "
| 4 | \n", "Positive | \n", "good person helping good people.\\nthis is how ... | \n", "good person helping good people america except... | \n", "