Marcio Monteiro commited on
Commit
e62be7f
1 Parent(s): 5e2ddf4

fix: metadata features defintion

Browse files
Files changed (5) hide show
  1. .gitignore +2 -1
  2. README.md +39 -0
  3. convert.py +12 -1
  4. test.csv +2 -2
  5. train.csv +2 -2
.gitignore CHANGED
@@ -1,2 +1,3 @@
1
  ag_news.csv
2
- newsSpace
 
 
1
  ag_news.csv
2
+ newsSpace
3
+ categories.txt
README.md CHANGED
@@ -1,4 +1,43 @@
1
  ---
2
  task_categories:
3
  - text-classification
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
 
1
  ---
2
  task_categories:
3
  - text-classification
4
+
5
+ dataset_info:
6
+ features:
7
+ - name: source
8
+ dtype: string
9
+ - name: url
10
+ dtype: string
11
+ - name: title
12
+ dtype: string
13
+ - name: image
14
+ dtype: string
15
+ - name: category
16
+ dtype: string
17
+ - name: description
18
+ dtype: string
19
+ - name: rank
20
+ dtype: int32
21
+ - name: pubdate
22
+ dtype: string
23
+ - name: text
24
+ dtype: string
25
+ - name: label
26
+ dtype:
27
+ class_label:
28
+ names:
29
+ '0': Business
30
+ '1': Entertainment
31
+ '2': Europe
32
+ '3': Health
33
+ '4': Italia
34
+ '5': Music Feeds
35
+ '6': Sci/Tech
36
+ '7': Software and Developement
37
+ '8': Sports
38
+ '9': Toons
39
+ '10': Top News
40
+ '11': Top Stories
41
+ '12': U.S.
42
+ '13': World
43
  ---
convert.py CHANGED
@@ -8,6 +8,7 @@ Usage:
8
 
9
  import csv
10
  import html
 
11
  import sys
12
 
13
  import pandas as pd
@@ -47,7 +48,7 @@ def _clean_html(text):
47
  html_code.replace("</p>", "\n\n</p>")
48
  html_code.replace("<br>", "\n")
49
 
50
- soup = BeautifulSoup(html_code, "lxml")
51
  text = soup.get_text(separator=" ")
52
 
53
  text = text.replace(" \n", "\n").replace("\n ", "\n")
@@ -108,6 +109,8 @@ def run():
108
  # Add a label to each row
109
  _categories = list(categories)
110
  _categories.sort()
 
 
111
 
112
  for row in rows:
113
  row["label"] = _categories.index(row["category"])
@@ -138,5 +141,13 @@ def split_csv_train_test(**kwargs):
138
  test_df.to_csv(TEST_OUTPUT_FILE, index=False)
139
 
140
 
 
 
 
 
 
 
 
 
141
  if __name__ == "__main__":
142
  run()
 
8
 
9
  import csv
10
  import html
11
+ import os
12
  import sys
13
 
14
  import pandas as pd
 
48
  html_code.replace("</p>", "\n\n</p>")
49
  html_code.replace("<br>", "\n")
50
 
51
+ soup = BeautifulSoup(html_code, "html.parser")
52
  text = soup.get_text(separator=" ")
53
 
54
  text = text.replace(" \n", "\n").replace("\n ", "\n")
 
109
  # Add a label to each row
110
  _categories = list(categories)
111
  _categories.sort()
112
+
113
+ save_categories(_categories)
114
 
115
  for row in rows:
116
  row["label"] = _categories.index(row["category"])
 
141
  test_df.to_csv(TEST_OUTPUT_FILE, index=False)
142
 
143
 
144
+ def save_categories(categories, fname="categories.txt"):
145
+ """
146
+ Save the categories into a text file.
147
+ """
148
+ with open(fname, "w") as f:
149
+ for category in categories:
150
+ f.write(category + os.linesep)
151
+
152
  if __name__ == "__main__":
153
  run()
test.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:da30f3d131924df14ef5280f93ef45343a81a0592460a64e0847dca225f5ce70
3
- size 169955948
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f59e985d4ad4a4999f93ddf182b77ec9399c75425c7496d92a2cfca3e31b639
3
+ size 169961937
train.csv CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:4b16743cfa3c595c010695b2ca80899fb6e52f1e91a736110d60b005e7e7b493
3
- size 679730930
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3cb732b181495dbe39da430669d5b11d52da82de2dacf2d6296e35d80a40845a
3
+ size 679752245