1T Conte commited on
Commit
e40c071
1 Parent(s): b5c1167

first commit

Browse files
Files changed (4) hide show
  1. README.md +58 -0
  2. convert.py +58 -0
  3. reviews.parquet +3 -0
  4. reviews_polarity.parquet +3 -0
README.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ task_categories:
5
+ - text-classification
6
+
7
+ dataset_info:
8
+ - config_name: default
9
+ features:
10
+ - name: stars
11
+ dtype:
12
+ class_label:
13
+ names:
14
+ '0': 1 star
15
+ '1': 2 stars
16
+ '2': 3 stars
17
+ '3': 4 stars
18
+ '4': 5 stars
19
+ - name: date
20
+ dtype: string
21
+ - name: text
22
+ dtype: string
23
+ - name: useful
24
+ dtype: int16
25
+ - name: funny
26
+ dtype: int16
27
+ - name: cool
28
+ dtype: int16
29
+ - config_name: polarity
30
+ features:
31
+ - name: stars
32
+ dtype:
33
+ class_label:
34
+ names:
35
+ '0': negative
36
+ '1': positive
37
+ - name: date
38
+ dtype: string
39
+ - name: text
40
+ dtype: string
41
+ - name: useful
42
+ dtype: int16
43
+ - name: funny
44
+ dtype: int16
45
+ - name: cool
46
+ dtype: int16
47
+
48
+ configs:
49
+ - config_name: default
50
+ data_files:
51
+ - split: complete
52
+ path: "reviews.parquet"
53
+ default: true
54
+ - config_name: polarity
55
+ data_files:
56
+ - split: complete
57
+ path: "reviews_polarity.parquet"
58
+ ---
convert.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import random
3
+
4
+ import pandas as pd
5
+
6
+
7
+ def parse_review(line):
8
+ d = json.loads(line)
9
+ d.pop("review_id")
10
+ d.pop("user_id")
11
+ d.pop("business_id")
12
+ d["stars"] = int(d["stars"]) - 1 # from 0 to 4
13
+
14
+ return d
15
+
16
+
17
+ def remap2polarity(row):
18
+ if row["stars"] in [0, 1]:
19
+ row["stars"] = 0
20
+ elif row["stars"] in [3, 4]:
21
+ row["stars"] = 1
22
+ else:
23
+ raise ValueError("Invalid value")
24
+
25
+ return row
26
+
27
+
28
+ def run():
29
+ rows = []
30
+
31
+ with open(
32
+ "yelp_dataset/yelp_academic_dataset_review.json", "r", encoding="utf8"
33
+ ) as file:
34
+ lines = file.readlines()
35
+
36
+ for line in lines:
37
+ obj = parse_review(line)
38
+ rows.append(obj)
39
+
40
+ df = pd.DataFrame(rows)
41
+ df.to_parquet("reviews.parquet")
42
+
43
+ # polarity
44
+ polarity_rows = [remap2polarity(row) for row in rows if row["stars"] != 2]
45
+
46
+ positive = [row for row in polarity_rows if row["stars"] == 1]
47
+ negative = [row for row in polarity_rows if row["stars"] == 0]
48
+ min_size = min(len(positive), len(negative))
49
+
50
+ polarity_rows = positive[:min_size] + negative[:min_size]
51
+ random.shuffle(polarity_rows)
52
+
53
+ df = pd.DataFrame(polarity_rows)
54
+ df.to_parquet("reviews_polarity.parquet")
55
+
56
+
57
+ if __name__ == "__main__":
58
+ run()
reviews.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:069f66f46b8b6def36fd346b9ca3c3ad3a81ae573d696865c8fcac47a01bc3fc
3
+ size 2636471449
reviews_polarity.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c0db32db7029489aadb11e4d51cf8421727978e03e9a2c6f534e70657787d707
3
+ size 1301672500