implemented preprocessing for secondary subfields
Browse files- all2023/val.json +2 -2
- major/test.json +2 -2
- major/train.json +2 -2
- minor/test.json +2 -2
- minor/train.json +2 -2
- preprocess.sh +13 -0
- preprocess_all2023.py +3 -8
- preprocess_major_minor.py +6 -9
- util_preprocess.py +24 -0
all2023/val.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d695efd145ac745cf81aab5073fc6938b7562b4330f1aed2cb029e3aae958627
|
3 |
+
size 412108395
|
major/test.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:94c2a729e10b65e46a530ee56fe1f17ecf588ffbf978a9a15166a385134e48a6
|
3 |
+
size 406488121
|
major/train.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9ceb77a8b2c6fd61decbc05c5c469341637638dfe513e4238c994b79c8edc2fc
|
3 |
+
size 1639130854
|
minor/test.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fab45ae4a61a692399a62538566ae755750592529ad21135a03946192e420fcf
|
3 |
+
size 1453299801
|
minor/train.json
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1640a3c3cbf951940ed0edab35eac1c5d7c638c7e97f06d12fdd1902f7cb3e71
|
3 |
+
size 5823472832
|
preprocess.sh
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# # test
|
2 |
+
# python preprocess_major_minor.py -d major -s test
|
3 |
+
|
4 |
+
# major/minor cats
|
5 |
+
for dataset in major minor
|
6 |
+
do
|
7 |
+
for split in train test
|
8 |
+
do
|
9 |
+
python preprocess_major_minor.py -d $dataset -s $split
|
10 |
+
done
|
11 |
+
done
|
12 |
+
# all 2023 corpus
|
13 |
+
python preprocess_all2023.py
|
preprocess_all2023.py
CHANGED
@@ -34,12 +34,9 @@ output_path = args.output_path
|
|
34 |
# Remaining imports
|
35 |
#
|
36 |
import pandas as pd
|
37 |
-
import numpy as np
|
38 |
import os
|
39 |
from tqdm import tqdm
|
40 |
-
from
|
41 |
-
GENERAL_CATEGORIES,
|
42 |
-
IGNORED_CATEGOREIES)
|
43 |
|
44 |
# %% [markdown]
|
45 |
# Rename columns to reflect standarized terminology:
|
@@ -89,10 +86,8 @@ for i, original_df in tqdm(enumerate(pd.read_csv(file_path, sep='\t', chunksize=
|
|
89 |
if feature not in original_df.columns:
|
90 |
original_df[feature] = ""
|
91 |
|
92 |
-
#
|
93 |
-
df = original_df
|
94 |
-
if df['primary_subfield'].isin(CATEGORY_ALIASES.keys()).sum():
|
95 |
-
ValueError("IMPLEMENT CODE TO CHANGE CATEGORY_ALIASES ")
|
96 |
|
97 |
# convert all columns to string per huggingface requirements
|
98 |
if i == 0:
|
|
|
34 |
# Remaining imports
|
35 |
#
|
36 |
import pandas as pd
|
|
|
37 |
import os
|
38 |
from tqdm import tqdm
|
39 |
+
from util_preprocess import preprocess_primary_secondary
|
|
|
|
|
40 |
|
41 |
# %% [markdown]
|
42 |
# Rename columns to reflect standarized terminology:
|
|
|
86 |
if feature not in original_df.columns:
|
87 |
original_df[feature] = ""
|
88 |
|
89 |
+
# Apply preprocessing rules
|
90 |
+
df = preprocess_primary_secondary(original_df)
|
|
|
|
|
91 |
|
92 |
# convert all columns to string per huggingface requirements
|
93 |
if i == 0:
|
preprocess_major_minor.py
CHANGED
@@ -34,12 +34,9 @@ output_path = args.output_path
|
|
34 |
# Remaining imports
|
35 |
#
|
36 |
import pandas as pd
|
37 |
-
import numpy as np
|
38 |
import os
|
39 |
from tqdm import tqdm
|
40 |
-
from
|
41 |
-
GENERAL_CATEGORIES,
|
42 |
-
IGNORED_CATEGOREIES)
|
43 |
|
44 |
# %% [markdown]
|
45 |
# Rename columns to reflect standarized terminology:
|
@@ -67,14 +64,14 @@ for i, original_df in tqdm(enumerate(pd.read_json(file_path, lines=True, chunksi
|
|
67 |
'prime_category': 'primary_subfield',
|
68 |
'abs_categories': 'secondary_subfield'
|
69 |
}, inplace=True)
|
70 |
-
# ignore entries from ignored categories (i.e., primary subfield)
|
71 |
-
df = original_df[~original_df['field'].isin(GENERAL_CATEGORIES | IGNORED_CATEGOREIES)]
|
72 |
-
if df['primary_subfield'].isin(CATEGORY_ALIASES.keys()).sum():
|
73 |
-
ValueError("IMPLEMENT CODE TO CHANGE CATEGORY_ALIASES ")
|
74 |
|
|
|
|
|
|
|
|
|
75 |
if i == 0:
|
76 |
df.to_json(save_path, lines=True, orient="records")
|
77 |
else:
|
78 |
df.to_json(save_path, lines=True, orient="records", mode='a')
|
79 |
-
|
80 |
# %%
|
|
|
34 |
# Remaining imports
|
35 |
#
|
36 |
import pandas as pd
|
|
|
37 |
import os
|
38 |
from tqdm import tqdm
|
39 |
+
from util_preprocess import preprocess_primary_secondary
|
|
|
|
|
40 |
|
41 |
# %% [markdown]
|
42 |
# Rename columns to reflect standarized terminology:
|
|
|
64 |
'prime_category': 'primary_subfield',
|
65 |
'abs_categories': 'secondary_subfield'
|
66 |
}, inplace=True)
|
|
|
|
|
|
|
|
|
67 |
|
68 |
+
# Apply preprocessing rules
|
69 |
+
df = preprocess_primary_secondary(original_df)
|
70 |
+
|
71 |
+
# Save to file
|
72 |
if i == 0:
|
73 |
df.to_json(save_path, lines=True, orient="records")
|
74 |
else:
|
75 |
df.to_json(save_path, lines=True, orient="records", mode='a')
|
76 |
+
print("Saved to file: ", save_path)
|
77 |
# %%
|
util_preprocess.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from arxiv_classifier.utils import (CATEGORY_ALIASES,
|
2 |
+
GENERAL_CATEGORIES,
|
3 |
+
IGNORED_CATEGOREIES)
|
4 |
+
|
5 |
+
IGNORE = GENERAL_CATEGORIES | IGNORED_CATEGOREIES
|
6 |
+
|
7 |
+
def preprocess_primary_secondary(original_df):
|
8 |
+
df = original_df[~original_df['field'].isin(IGNORE)]
|
9 |
+
if df['primary_subfield'].isin(CATEGORY_ALIASES.keys()).sum():
|
10 |
+
ValueError("IMPLEMENT CODE TO CHANGE CATEGORY_ALIASES ")
|
11 |
+
|
12 |
+
def preprocess_secondary(s):
|
13 |
+
# split string to list by space
|
14 |
+
subfields = s.split()
|
15 |
+
# ignore entries from ignored categories (i.e., primary subfield)
|
16 |
+
subfields = [subfield for subfield in subfields if subfield not in IGNORE]
|
17 |
+
# substitute subfield aliases
|
18 |
+
if set(subfields) & set(CATEGORY_ALIASES.keys()):
|
19 |
+
ValueError("IMPLEMENT CODE TO CHANGE CATEGORY_ALIASES ")
|
20 |
+
return subfields
|
21 |
+
|
22 |
+
# Preprocess secondary subfields
|
23 |
+
df.loc[:, 'secondary_subfield'] = df['secondary_subfield'].apply(preprocess_secondary)
|
24 |
+
return df
|