1T Conte commited on
Commit
83ddb67
1 Parent(s): d2f40c4

fix: top4-balanced

Browse files
Files changed (3) hide show
  1. README.md +41 -11
  2. convert.py +11 -4
  3. data/top4-balanced.csv +2 -2
README.md CHANGED
@@ -4,18 +4,8 @@ language:
4
  task_categories:
5
  - text-classification
6
 
7
- configs:
8
- - config_name: original
9
- data_files:
10
- - split: complete
11
- path: "data/original.csv"
12
- default: true
13
- - config_name: top4-balanced
14
- data_files:
15
- - split: complete
16
- path: "data/top4-balanced.csv"
17
-
18
  dataset_info:
 
19
  features:
20
  - name: source
21
  dtype: string
@@ -53,4 +43,44 @@ dataset_info:
53
  '11': Top Stories
54
  '12': U.S.
55
  '13': World
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  ---
 
4
  task_categories:
5
  - text-classification
6
 
 
 
 
 
 
 
 
 
 
 
 
7
  dataset_info:
8
+ - config_name: original
9
  features:
10
  - name: source
11
  dtype: string
 
43
  '11': Top Stories
44
  '12': U.S.
45
  '13': World
46
+ - config_name: top4-balanced
47
+ features:
48
+ - name: source
49
+ dtype: string
50
+ - name: url
51
+ dtype: string
52
+ - name: title
53
+ dtype: string
54
+ - name: image
55
+ dtype: string
56
+ - name: category
57
+ dtype: string
58
+ - name: description
59
+ dtype: string
60
+ - name: rank
61
+ dtype: int32
62
+ - name: pubdate
63
+ dtype: string
64
+ - name: text
65
+ dtype: string
66
+ - name: label
67
+ dtype:
68
+ class_label:
69
+ names:
70
+ '0': World
71
+ '1': Sports
72
+ '2': Business
73
+ '3': Sci/Tech
74
+
75
+ configs:
76
+ - config_name: original
77
+ data_files:
78
+ - split: complete
79
+ path: "data/original.csv"
80
+ default: true
81
+ - config_name: top4-balanced
82
+ data_files:
83
+ - split: complete
84
+ path: "data/top4-balanced.csv"
85
+
86
  ---
convert.py CHANGED
@@ -29,6 +29,7 @@ HEADER = [
29
 
30
  OUTPUT_FILE_PATH = os.path.join("data", "original.csv")
31
 
 
32
  def _clean_text(text):
33
  text = text.replace("\\\n", "\n")
34
  text = html.unescape(text)
@@ -58,9 +59,9 @@ def _clean_html(text):
58
 
59
  if output == "null":
60
  return ""
61
-
62
  return output
63
-
64
  return ""
65
 
66
 
@@ -125,7 +126,9 @@ def run():
125
  row["label"] = _categories.index(row["category"])
126
 
127
  save_csv(rows)
128
- save_csv_categories(["World", "Sports", "Business", "Sci/Tech"], "top4-balanced", is_balanced=True)
 
 
129
 
130
 
131
  def save_csv(rows, fname=OUTPUT_FILE_PATH):
@@ -133,7 +136,7 @@ def save_csv(rows, fname=OUTPUT_FILE_PATH):
133
  Save the processed data into a CSV file.
134
  """
135
  os.makedirs("data", exist_ok=True)
136
-
137
  with open(fname, "w", encoding="utf8") as f:
138
  writer = csv.DictWriter(f, fieldnames=rows[0].keys())
139
  writer.writeheader()
@@ -163,6 +166,10 @@ def save_csv_categories(categories, config_name, is_balanced=True, **kwargs):
163
  else:
164
  df = df[df["category"].isin(categories)]
165
 
 
 
 
 
166
  df.to_csv(os.path.join("data", f"{config_name}.csv"), index=False)
167
 
168
 
 
29
 
30
  OUTPUT_FILE_PATH = os.path.join("data", "original.csv")
31
 
32
+
33
  def _clean_text(text):
34
  text = text.replace("\\\n", "\n")
35
  text = html.unescape(text)
 
59
 
60
  if output == "null":
61
  return ""
62
+
63
  return output
64
+
65
  return ""
66
 
67
 
 
126
  row["label"] = _categories.index(row["category"])
127
 
128
  save_csv(rows)
129
+ save_csv_categories(
130
+ ["World", "Sports", "Business", "Sci/Tech"], "top4-balanced", is_balanced=True
131
+ )
132
 
133
 
134
  def save_csv(rows, fname=OUTPUT_FILE_PATH):
 
136
  Save the processed data into a CSV file.
137
  """
138
  os.makedirs("data", exist_ok=True)
139
+
140
  with open(fname, "w", encoding="utf8") as f:
141
  writer = csv.DictWriter(f, fieldnames=rows[0].keys())
142
  writer.writeheader()
 
166
  else:
167
  df = df[df["category"].isin(categories)]
168
 
169
+ # remap the labels to 0, 1, 2, ...
170
+ for i, row in df.iterrows():
171
+ df.at[i, "label"] = categories.index(row["category"])
172
+
173
  df.to_csv(os.path.join("data", f"{config_name}.csv"), index=False)
174
 
175
 
data/top4-balanced.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d877f38b2e29c8cbf7d7334f846158c7eb7c463ad5e51827d41dfb54b3006dd2
3
- size 343796732
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3c900ade9ea2c83255b09021e70d80d58b933880655fc6e794e12a652a30d33f
3
+ size 343919424