Marcio Monteiro commited on
Commit
9288bfa
1 Parent(s): 94a47f5

fix: removing train/test split (leaving this responsiblity to the data loader)

Browse files
README.md CHANGED
@@ -9,15 +9,11 @@ configs:
9
  data_files:
10
  - split: train
11
  path: "data/all/train.csv"
12
- - split: test
13
- path: "data/all/test.csv"
14
  default: true
15
  - config_name: top4
16
  data_files:
17
  - split: train
18
  path: "data/top4/train.csv"
19
- - split: test
20
- path: "data/top4/test.csv"
21
 
22
  dataset_info:
23
  features:
 
9
  data_files:
10
  - split: train
11
  path: "data/all/train.csv"
 
 
12
  default: true
13
  - config_name: top4
14
  data_files:
15
  - split: train
16
  path: "data/top4/train.csv"
 
 
17
 
18
  dataset_info:
19
  features:
convert.py CHANGED
@@ -15,7 +15,6 @@ import pandas as pd
15
 
16
  from bs4 import BeautifulSoup
17
 
18
- from sklearn.model_selection import train_test_split
19
 
20
  HEADER = [
21
  "source",
@@ -28,10 +27,7 @@ HEADER = [
28
  "pubdate",
29
  ]
30
 
31
- OUTPUT_FILE = "ag_news.csv"
32
- TRAIN_OUTPUT_FILE = "train.csv"
33
- TEST_OUTPUT_FILE = "test.csv"
34
-
35
 
36
  def _clean_text(text):
37
  text = text.replace("\\\n", "\n")
@@ -127,15 +123,15 @@ def run():
127
  row["label"] = _categories.index(row["category"])
128
 
129
  save_csv(rows)
130
-
131
- split_csv_train_test(test_size=0.2, random_state=42)
132
- filter_and_split_csv(["World", "Sports", "Business", "Sci/Tech"], "top4")
133
 
134
 
135
- def save_csv(rows, fname=OUTPUT_FILE):
136
  """
137
  Save the processed data into a CSV file.
138
  """
 
 
139
  with open(fname, "w", encoding="utf8") as f:
140
  writer = csv.DictWriter(f, fieldnames=rows[0].keys())
141
  writer.writeheader()
@@ -144,26 +140,13 @@ def save_csv(rows, fname=OUTPUT_FILE):
144
  writer.writerow(row)
145
 
146
 
147
- def split_csv_train_test(**kwargs):
148
- """
149
- Split the data into training and testing sets.
150
- """
151
- df = pd.read_csv(OUTPUT_FILE)
152
- train_df, test_df = train_test_split(df, **kwargs)
153
-
154
- os.makedirs("data/all", exist_ok=True)
155
-
156
- train_df.to_csv(os.path.join("data", "all", TRAIN_OUTPUT_FILE), index=False)
157
- test_df.to_csv(os.path.join("data", "all", TEST_OUTPUT_FILE), index=False)
158
-
159
-
160
- def filter_and_split_csv(categories, config_name, is_balanced=True, **kwargs):
161
  """
162
  Filter the data by categories and split the data into training and testing
163
  sets. If is_balanced is True, the data will be balanced to size of the
164
  class with fewer examples.
165
  """
166
- df = pd.read_csv(OUTPUT_FILE)
167
 
168
  if is_balanced:
169
  dfs = []
@@ -180,9 +163,7 @@ def filter_and_split_csv(categories, config_name, is_balanced=True, **kwargs):
180
 
181
  os.makedirs(f"data/{config_name}", exist_ok=True)
182
 
183
- train_df, test_df = train_test_split(df, **kwargs)
184
- train_df.to_csv(os.path.join("data", config_name, TRAIN_OUTPUT_FILE), index=False)
185
- test_df.to_csv(os.path.join("data", config_name, TEST_OUTPUT_FILE), index=False)
186
 
187
 
188
  def save_categories(categories, fname="categories.txt"):
 
15
 
16
  from bs4 import BeautifulSoup
17
 
 
18
 
19
  HEADER = [
20
  "source",
 
27
  "pubdate",
28
  ]
29
 
30
+ OUTPUT_FILE_PATH = os.path.join("data", "all", "train.csv")
 
 
 
31
 
32
  def _clean_text(text):
33
  text = text.replace("\\\n", "\n")
 
123
  row["label"] = _categories.index(row["category"])
124
 
125
  save_csv(rows)
126
+ save_csv_categories(["World", "Sports", "Business", "Sci/Tech"], "top4-balanced", is_balanced=True)
 
 
127
 
128
 
129
+ def save_csv(rows, fname=OUTPUT_FILE_PATH):
130
  """
131
  Save the processed data into a CSV file.
132
  """
133
+ os.makedirs(os.path.join("data", "all"), exist_ok=True)
134
+
135
  with open(fname, "w", encoding="utf8") as f:
136
  writer = csv.DictWriter(f, fieldnames=rows[0].keys())
137
  writer.writeheader()
 
140
  writer.writerow(row)
141
 
142
 
143
+ def save_csv_categories(categories, config_name, is_balanced=True, **kwargs):
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  """
145
  Filter the data by categories and split the data into training and testing
146
  sets. If is_balanced is True, the data will be balanced to size of the
147
  class with fewer examples.
148
  """
149
+ df = pd.read_csv(OUTPUT_FILE_PATH)
150
 
151
  if is_balanced:
152
  dfs = []
 
163
 
164
  os.makedirs(f"data/{config_name}", exist_ok=True)
165
 
166
+ df.to_csv(os.path.join("data", config_name, "train.csv"), index=False)
 
 
167
 
168
 
169
  def save_categories(categories, fname="categories.txt"):
data/all/.~lock.train.csv# DELETED
@@ -1 +0,0 @@
1
- ,marcio,marcio-AX370-Gaming,10.04.2024 19:56,file:///home/marcio/.config/libreoffice/4;
 
 
data/all/test.csv DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:fb60f014952b4e1ae53fb3788e3e2b3a76e927ebf65931d87f2f8bcf5d22ad73
3
- size 168573267
 
 
 
 
data/all/train.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:b8a9cf578e8a092d61ed556cebecdf96f3a2a13c8773792e6facbf03f36d8239
3
- size 674112358
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8e3bc4a1a85a56f46327a32c22f0661496b2db7cb18eefa689c9e6c06ea93518
3
+ size 843929665
data/{top4 → top4-balanced}/train.csv RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f52847721502d0f473e6eac9e7704cb13ddf325ab9c36a79ec811c19e2614f56
3
- size 258202157
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4a9a5712dd5bf47810bc6fc7df31b86a6eaba594cc34353efcf02fd7f6289771
3
+ size 344070837
data/top4/test.csv DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:8fb2c8e2218bd3e976e147bbefc3bfa6b5575bb29966910a7d835bd1e5cd5d6a
3
- size 85898679