{ "cells": [ { "cell_type": "code", "execution_count": 1, "source": [ "\"\"\"This script's purpose is to re-define the datset loading functions to better suit this specific\n", "reddit posts dataset.\"\"\"\n", "\n", "import csv\n", "import json\n", "import os" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": 1, "source": [ "import csv\n", "import json\n", "import os" ], "outputs": [], "metadata": {} }, { "cell_type": "code", "execution_count": 2, "source": [ "from datasets import load_dataset\n", "\n", "" ], "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "c:\\Users\\ericr\\miniconda3\\envs\\sta663C\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "metadata": {} }, { "cell_type": "code", "execution_count": 3, "source": [ "ds = load_dataset('rotten_tomatoes')" ], "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "Downloading data: 100%|██████████| 699k/699k [00:00<00:00, 2.88MB/s]\n", "Downloading data: 100%|██████████| 90.0k/90.0k [00:00<00:00, 90.7kB/s]\n", "Downloading data: 100%|██████████| 92.2k/92.2k [00:00<00:00, 1.56MB/s]\n", "Generating train split: 100%|██████████| 8530/8530 [00:00<00:00, 448827.83 examples/s]\n", "Generating validation split: 100%|██████████| 1066/1066 [00:00<00:00, 94627.05 examples/s]\n", "Generating test split: 100%|██████████| 1066/1066 [00:00<00:00, 127328.15 examples/s]\n" ] } ], "metadata": {} }, { "cell_type": "code", "execution_count": 4, "source": [ "ds" ], "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "DatasetDict({\n", " train: Dataset({\n", " features: ['text', 'label'],\n", " num_rows: 8530\n", " })\n", " validation: Dataset({\n", " features: ['text', 'label'],\n", " num_rows: 1066\n", " })\n", " test: Dataset({\n", " features: ['text', 'label'],\n", " num_rows: 1066\n", " })\n", "})" ] }, "metadata": {}, "execution_count": 4 } ], "metadata": {} }, { "cell_type": "code", "execution_count": 5, "source": [ "ds.citation" ], "outputs": [ { "output_type": "error", "ename": "AttributeError", "evalue": "'DatasetDict' object has no attribute 'citation'", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[5], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m ds\u001b[39m.\u001b[39;49mcitation\n", "\u001b[1;31mAttributeError\u001b[0m: 'DatasetDict' object has no attribute 'citation'" ] } ], "metadata": {} }, { "cell_type": "code", "execution_count": 6, "source": [ "ds.citation()" ], "outputs": [ { "output_type": "error", "ename": "AttributeError", "evalue": "'DatasetDict' object has no attribute 'citation'", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[6], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m ds\u001b[39m.\u001b[39;49mcitation()\n", "\u001b[1;31mAttributeError\u001b[0m: 'DatasetDict' object has no attribute 'citation'" ] } ], "metadata": {} }, { "cell_type": "code", "execution_count": 7, "source": [ "ds.column_names" ], "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "{'train': ['text', 'label'],\n", " 'validation': ['text', 'label'],\n", " 'test': ['text', 'label']}" ] }, "metadata": {}, "execution_count": 7 } ], "metadata": {} }, { "cell_type": "code", "execution_count": 8, "source": [ "ds['train']" ], "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "Dataset({\n", " features: ['text', 'label'],\n", " num_rows: 8530\n", "})" ] }, "metadata": {}, "execution_count": 8 } ], "metadata": {} }, { "cell_type": "code", "execution_count": 9, "source": [ "ds.license" ], "outputs": [ { "output_type": "error", "ename": "AttributeError", "evalue": "'DatasetDict' object has no attribute 'license'", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[9], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m ds\u001b[39m.\u001b[39;49mlicense\n", "\u001b[1;31mAttributeError\u001b[0m: 'DatasetDict' object has no attribute 'license'" ] } ], "metadata": {} }, { "cell_type": "code", "execution_count": 10, "source": [ "ds.dataset_size" ], "outputs": [ { "output_type": "error", "ename": "AttributeError", "evalue": "'DatasetDict' object has no attribute 'dataset_size'", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[10], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m ds\u001b[39m.\u001b[39;49mdataset_size\n", "\u001b[1;31mAttributeError\u001b[0m: 'DatasetDict' object has no attribute 'dataset_size'" ] } ], "metadata": {} }, { "cell_type": "code", "execution_count": 11, "source": [ "ds._info" ], "outputs": [ { "output_type": "error", "ename": "AttributeError", "evalue": "'DatasetDict' object has no attribute '_info'", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[11], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m ds\u001b[39m.\u001b[39;49m_info\n", "\u001b[1;31mAttributeError\u001b[0m: 'DatasetDict' object has no attribute '_info'" ] } ], "metadata": {} }, { "cell_type": "code", "execution_count": 12, "source": [ "ds['train']._info" ], "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "DatasetInfo(description=\"Movie Review Dataset.\\nThis is a dataset of containing 5,331 positive and 5,331 negative processed\\nsentences from Rotten Tomatoes movie reviews. This data was first used in Bo\\nPang and Lillian Lee, ``Seeing stars: Exploiting class relationships for\\nsentiment categorization with respect to rating scales.'', Proceedings of the\\nACL, 2005.\\n\", citation='@InProceedings{Pang+Lee:05a,\\n author = {Bo Pang and Lillian Lee},\\n title = {Seeing stars: Exploiting class relationships for sentiment\\n categorization with respect to rating scales},\\n booktitle = {Proceedings of the ACL},\\n year = 2005\\n}\\n', homepage='http://www.cs.cornell.edu/people/pabo/movie-review-data/', license='', features={'text': Value(dtype='string', id=None), 'label': ClassLabel(names=['neg', 'pos'], id=None)}, post_processed=None, supervised_keys=SupervisedKeysData(input='', output=''), task_templates=[TextClassification(task='text-classification', text_column='text', label_column='label')], builder_name='parquet', dataset_name='rotten_tomatoes', config_name='default', version=1.0.0, splits={'train': SplitInfo(name='train', num_bytes=1075873, num_examples=8530, shard_lengths=None, dataset_name='rotten_tomatoes'), 'validation': SplitInfo(name='validation', num_bytes=134809, num_examples=1066, shard_lengths=None, dataset_name='rotten_tomatoes'), 'test': SplitInfo(name='test', num_bytes=136102, num_examples=1066, shard_lengths=None, dataset_name='rotten_tomatoes')}, download_checksums={'hf://datasets/rotten_tomatoes@cab0f883b39cfb510c34e41db874679b3e2bafa3/default/train/0000.parquet': {'num_bytes': 698845, 'checksum': None}, 'hf://datasets/rotten_tomatoes@cab0f883b39cfb510c34e41db874679b3e2bafa3/default/validation/0000.parquet': {'num_bytes': 90001, 'checksum': None}, 'hf://datasets/rotten_tomatoes@cab0f883b39cfb510c34e41db874679b3e2bafa3/default/test/0000.parquet': {'num_bytes': 92206, 'checksum': None}}, download_size=881052, post_processing_size=None, dataset_size=1346784, size_in_bytes=2227836)" ] }, "metadata": {}, "execution_count": 12 } ], "metadata": {} }, { "cell_type": "code", "execution_count": 13, "source": [ "print(ds['train']._info)" ], "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "DatasetInfo(description=\"Movie Review Dataset.\\nThis is a dataset of containing 5,331 positive and 5,331 negative processed\\nsentences from Rotten Tomatoes movie reviews. This data was first used in Bo\\nPang and Lillian Lee, ``Seeing stars: Exploiting class relationships for\\nsentiment categorization with respect to rating scales.'', Proceedings of the\\nACL, 2005.\\n\", citation='@InProceedings{Pang+Lee:05a,\\n author = {Bo Pang and Lillian Lee},\\n title = {Seeing stars: Exploiting class relationships for sentiment\\n categorization with respect to rating scales},\\n booktitle = {Proceedings of the ACL},\\n year = 2005\\n}\\n', homepage='http://www.cs.cornell.edu/people/pabo/movie-review-data/', license='', features={'text': Value(dtype='string', id=None), 'label': ClassLabel(names=['neg', 'pos'], id=None)}, post_processed=None, supervised_keys=SupervisedKeysData(input='', output=''), task_templates=[TextClassification(task='text-classification', text_column='text', label_column='label')], builder_name='parquet', dataset_name='rotten_tomatoes', config_name='default', version=1.0.0, splits={'train': SplitInfo(name='train', num_bytes=1075873, num_examples=8530, shard_lengths=None, dataset_name='rotten_tomatoes'), 'validation': SplitInfo(name='validation', num_bytes=134809, num_examples=1066, shard_lengths=None, dataset_name='rotten_tomatoes'), 'test': SplitInfo(name='test', num_bytes=136102, num_examples=1066, shard_lengths=None, dataset_name='rotten_tomatoes')}, download_checksums={'hf://datasets/rotten_tomatoes@cab0f883b39cfb510c34e41db874679b3e2bafa3/default/train/0000.parquet': {'num_bytes': 698845, 'checksum': None}, 'hf://datasets/rotten_tomatoes@cab0f883b39cfb510c34e41db874679b3e2bafa3/default/validation/0000.parquet': {'num_bytes': 90001, 'checksum': None}, 'hf://datasets/rotten_tomatoes@cab0f883b39cfb510c34e41db874679b3e2bafa3/default/test/0000.parquet': {'num_bytes': 92206, 'checksum': None}}, download_size=881052, post_processing_size=None, dataset_size=1346784, size_in_bytes=2227836)\n" ] } ], "metadata": {} }, { "cell_type": "code", "execution_count": 14, "source": [ "print(ds['train']._info.description)" ], "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Movie Review Dataset.\n", "This is a dataset of containing 5,331 positive and 5,331 negative processed\n", "sentences from Rotten Tomatoes movie reviews. This data was first used in Bo\n", "Pang and Lillian Lee, ``Seeing stars: Exploiting class relationships for\n", "sentiment categorization with respect to rating scales.'', Proceedings of the\n", "ACL, 2005.\n", "\n" ] } ], "metadata": {} } ], "nbformat": 4, "nbformat_minor": 2, "metadata": { "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": 3 } } }