First version of the your_dataset_name dataset.
Browse files- dummy/1.0.0/dummy_data.zip +3 -0
- dummy/1.0.0/dummy_data.zip.lock +0 -0
- twitter-sentiment-analysis.py +135 -0
dummy/1.0.0/dummy_data.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:05d41bacb2cc856e87d7fbd5f79c8fe4e30d0e317c973edbf784418d32c4c008
|
3 |
+
size 946
|
dummy/1.0.0/dummy_data.zip.lock
ADDED
File without changes
|
twitter-sentiment-analysis.py
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
|
15 |
+
"""Twitter Sentiment Analysis Training Corpus (Dataset)"""
|
16 |
+
|
17 |
+
import json
|
18 |
+
import os
|
19 |
+
|
20 |
+
import datasets
|
21 |
+
from datasets import load_dataset
|
22 |
+
|
23 |
+
|
24 |
+
logger = datasets.logging.get_logger(__name__)
|
25 |
+
|
26 |
+
|
27 |
+
_CITATION = """\
|
28 |
+
@InProceedings{thinknook:dataset,
|
29 |
+
title = {Twitter Sentiment Analysis Training Corpus (Dataset)},
|
30 |
+
author={Ibrahim Naji},
|
31 |
+
year={2012}
|
32 |
+
}
|
33 |
+
"""
|
34 |
+
|
35 |
+
_DESCRIPTION = """\
|
36 |
+
The Twitter Sentiment Analysis Dataset contains 1,578,627 classified tweets, each row is marked as 1 for positive sentiment and 0 for negative sentiment.
|
37 |
+
The dataset is based on data from the following two sources:
|
38 |
+
|
39 |
+
University of Michigan Sentiment Analysis competition on Kaggle
|
40 |
+
Twitter Sentiment Corpus by Niek Sanders
|
41 |
+
|
42 |
+
Finally, I randomly selected a subset of them, applied a cleaning process, and divided them between the test and train subsets, keeping a balance between
|
43 |
+
the number of positive and negative tweets within each of these subsets.
|
44 |
+
"""
|
45 |
+
|
46 |
+
|
47 |
+
_URL = "https://raw.githubusercontent.com/cblancac/SentimentAnalysisBert/main/data/"
|
48 |
+
_URLS = {
|
49 |
+
"train": _URL + "train_150k.txt",
|
50 |
+
"test": _URL + "test_62k.txt",
|
51 |
+
}
|
52 |
+
|
53 |
+
|
54 |
+
_HOMEPAGE = "https://raw.githubusercontent.com/cblancac/SentimentAnalysisBert/main"
|
55 |
+
|
56 |
+
|
57 |
+
# TODO: Add link to the official dataset URLs here
|
58 |
+
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
59 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
60 |
+
#_URLS = {
|
61 |
+
# "first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip",
|
62 |
+
# "second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip",
|
63 |
+
#}
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
def _define_columns(example):
|
68 |
+
text_splited = example["text"].split('\t')
|
69 |
+
return {"text": text_splited[1].strip(), "feeling": int(text_splited[0])}
|
70 |
+
|
71 |
+
|
72 |
+
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
73 |
+
class NewDataset(datasets.GeneratorBasedBuilder):
|
74 |
+
"""TODO: Short description of my dataset."""
|
75 |
+
|
76 |
+
VERSION = datasets.Version("1.0.0")
|
77 |
+
|
78 |
+
def _info(self):
|
79 |
+
features = datasets.Features(
|
80 |
+
{
|
81 |
+
"text": datasets.Value("string"),
|
82 |
+
"feeling": datasets.Value("int32")
|
83 |
+
}
|
84 |
+
)
|
85 |
+
return datasets.DatasetInfo(
|
86 |
+
# This is the description that will appear on the datasets page.
|
87 |
+
description=_DESCRIPTION,
|
88 |
+
# This defines the different columns of the dataset and their types
|
89 |
+
features=features, # Here we define them above because they are different between the two configurations
|
90 |
+
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
|
91 |
+
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
92 |
+
# supervised_keys=("sentence", "label"),
|
93 |
+
# Homepage of the dataset for documentation
|
94 |
+
homepage=_HOMEPAGE,
|
95 |
+
# Citation for the dataset
|
96 |
+
citation=_CITATION,
|
97 |
+
)
|
98 |
+
|
99 |
+
def _split_generators(self, dl_manager):
|
100 |
+
|
101 |
+
|
102 |
+
data_dir_files = dl_manager.download_and_extract(_URLS)
|
103 |
+
data_dir = '/'.join(data_dir_files["train"].split('/')[:-1])
|
104 |
+
print("AAAAAAAAAAAAA: ", data_dir)
|
105 |
+
|
106 |
+
data = load_dataset("text", data_files=data_dir_files)
|
107 |
+
data = data.map(_define_columns)
|
108 |
+
|
109 |
+
texts_dataset_clean = data["train"].train_test_split(train_size=0.8, seed=42)
|
110 |
+
# Rename the default "test" split to "validation"
|
111 |
+
texts_dataset_clean["validation"] = texts_dataset_clean.pop("test")
|
112 |
+
# Add the "test" set to our `DatasetDict`
|
113 |
+
texts_dataset_clean["test"] = data["test"]
|
114 |
+
texts_dataset_clean
|
115 |
+
|
116 |
+
for split, dataset in texts_dataset_clean.items():
|
117 |
+
dataset.to_json(data_dir + "/" + f"twitter-sentiment-analysis-{split}.jsonl")
|
118 |
+
|
119 |
+
return [
|
120 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": os.path.join(data_dir, "twitter-sentiment-analysis-train.jsonl")}),
|
121 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": os.path.join(data_dir, "twitter-sentiment-analysis-validation.jsonl")}),
|
122 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": os.path.join(data_dir, "twitter-sentiment-analysis-test.jsonl")}),
|
123 |
+
]
|
124 |
+
|
125 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
126 |
+
def _generate_examples(self, filepath):
|
127 |
+
"""This function returns the examples in the raw (text) form."""
|
128 |
+
logger.info("generating examples from = %s", filepath)
|
129 |
+
with open(filepath, encoding="utf-8") as f:
|
130 |
+
for key, row in enumerate(f):
|
131 |
+
data = json.loads(row)
|
132 |
+
yield key, {
|
133 |
+
"text": data["text"],
|
134 |
+
"feeling": data["feeling"],
|
135 |
+
}
|