Ziyuan111 commited on
Commit
47a0e6d
1 Parent(s): 625cbd8

Upload sarcasm.py

Browse files
Files changed (1) hide show
  1. sarcasm.py +91 -0
sarcasm.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Sarcasm
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/15_wDQ9RJXwyxbomu2F1k0pK9H7XZ1cuT
8
+ """
9
+
10
+ import pandas as pd
11
+ import geopandas as gpd
12
+ from datasets import (
13
+ GeneratorBasedBuilder, Version, DownloadManager, SplitGenerator, Split,
14
+ Features, Value, BuilderConfig, DatasetInfo
15
+ )
16
+ import matplotlib.pyplot as plt
17
+ import seaborn as sns
18
+ import csv
19
+ import json
20
+ from shapely.geometry import Point
21
+
22
+ # URL definitions
23
+ _URLS = {
24
+ "csv_file": "https://drive.google.com/uc?export=download&id=1WcPqVZasDy1nmGcildLS-uw_-04I9Max",
25
+ }
26
+
27
+ class Sarcasm(GeneratorBasedBuilder):
28
+ VERSION = Version("1.0.0")
29
+
30
+ def _info(self):
31
+ return DatasetInfo(
32
+ description="This dataset combines information from sarcasm",
33
+ features=Features({
34
+ "comments": Value("string"),
35
+ "contains_slash_s": Value("int64"),
36
+ }),
37
+ supervised_keys=None,
38
+ homepage="https://github.com/AuraMa111?tab=repositories",
39
+ citation="Citation for the combined dataset",
40
+ )
41
+
42
+ def _split_generators(self, dl_manager):
43
+ downloaded_files = dl_manager.download_and_extract(_URLS)
44
+ data_file_path = downloaded_files["combined_data.csv"]
45
+
46
+ num_examples = pd.read_csv(data_file_path).shape[0]
47
+ train_size = int(0.6 * num_examples)
48
+ val_size = int(0.2 * num_examples)
49
+ test_size = num_examples - train_size - val_size
50
+
51
+ return [
52
+ SplitGenerator(
53
+ name=Split.TRAIN,
54
+ gen_kwargs={"data_file_path": data_file_path, "split": Split.TRAIN, "size": train_size}
55
+ ),
56
+ SplitGenerator(
57
+ name=Split.VALIDATION,
58
+ gen_kwargs={"data_file_path": data_file_path, "split": Split.VALIDATION, "size": val_size}
59
+ ),
60
+ SplitGenerator(
61
+ name=Split.TEST,
62
+ gen_kwargs={"data_file_path": data_file_path, "split": Split.TEST, "size": test_size}
63
+ ),
64
+ ]
65
+
66
+ def _generate_examples(self, data_file_path, split, size):
67
+ data = pd.read_csv(data_file_path)
68
+ if split == Split.TRAIN:
69
+ subset_data = data[:size]
70
+ elif split == Split.VALIDATION:
71
+ subset_data = data[size:size*2]
72
+ elif split == Split.TEST:
73
+ subset_data = data[size*2:]
74
+
75
+ for index, row in subset_data.iterrows():
76
+ example = {
77
+ "comments": row["comments"],
78
+ "contains_slash_s": row["contains_slash_s"]
79
+ }
80
+ yield index, example
81
+
82
+ # Instantiate your dataset class
83
+ sarcasm = Sarcasm()
84
+
85
+ # Build the datasets
86
+ sarcasm.download_and_prepare()
87
+
88
+ # Access the datasets for training, validation, and testing
89
+ dataset_train = sarcasm.as_dataset(split='train')
90
+ dataset_validation = sarcasm.as_dataset(split='validation')
91
+ dataset_test = sarcasm.as_dataset(split='test')