nreimers commited on
Commit
3587946
1 Parent(s): b0458b3
Files changed (5) hide show
  1. README.md +3 -0
  2. bbc-text.csv +0 -0
  3. prepare.py +36 -0
  4. test.jsonl +0 -0
  5. train.jsonl +0 -0
README.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # BBC News Topic Classification
2
+
3
+ Dataset on [BBC News Topic Classification](https://www.kaggle.com/yufengdev/bbc-text-categorization/data): 2225 articles, each labeled under one of 5 categories: business, entertainment, politics, sport or tech.
bbc-text.csv ADDED
The diff for this file is too large to render. See raw diff
 
prepare.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from collections import Counter
3
+ import json
4
+ import random
5
+
6
+
7
+ df = pd.read_csv("bbc-text.csv")
8
+ df.fillna('', inplace=True)
9
+ print(df)
10
+
11
+ label2id = {label: idx for idx, label in enumerate(df['category'].unique())}
12
+
13
+ rows = [{'text': row['text'].strip(),
14
+ 'label': label2id[row['category']],
15
+ 'label_text': row['category'],
16
+ } for idx, row in df.iterrows()]
17
+
18
+ random.seed(42)
19
+ random.shuffle(rows)
20
+
21
+ num_test = 1000
22
+ splits = {'test': rows[0:num_test], 'train': rows[num_test:]}
23
+
24
+ print("Train:", len(splits['train']))
25
+ print("Test:", len(splits['test']))
26
+
27
+ num_labels = Counter()
28
+
29
+ for row in splits['test']:
30
+ num_labels[row['label']] += 1
31
+ print(num_labels)
32
+
33
+ for split in ['train', 'test']:
34
+ with open(f'{split}.jsonl', 'w') as fOut:
35
+ for row in splits[split]:
36
+ fOut.write(json.dumps(row)+"\n")
test.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
train.jsonl ADDED
The diff for this file is too large to render. See raw diff