bug fix related to subfield/category aliases
Browse files- all2023/val.json +2 -2
- major/test.json +2 -2
- major/train.json +2 -2
- minor/train.json +2 -2
- preprocess.sh +9 -9
- preprocess_all2023.py +9 -1
- preprocess_major_minor.py +9 -1
- util_preprocess.py +28 -12
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:016f8e4a4fe37bb0f1ff9f71d842e1d500db965ba6428d0a4124adfa47ce0f48
|
3 |
+
size 409838372
|
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:77359a2c1fe3cbeeba38694398b94ce4d97047d5b77f06e8e50996044e896f9e
|
3 |
+
size 434108093
|
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:68979fe29cbae77e4bca24d6b892a959192385b1a5dd9a32d96acb549fbc1759
|
3 |
+
size 1741063444
|
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:21ee95f10cd102f2ca8a8fdbb390cb59df3a37ca2f1010a1c0407ffcb7dbaed0
|
3 |
+
size 560901682
|
preprocess.sh
CHANGED
@@ -1,13 +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 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
done
|
12 |
# all 2023 corpus
|
13 |
-
python preprocess_all2023.py
|
|
|
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 -ip $1
|
10 |
+
# done
|
11 |
+
# done
|
12 |
# all 2023 corpus
|
13 |
+
python preprocess_all2023.py -ip $1
|
preprocess_all2023.py
CHANGED
@@ -23,11 +23,14 @@ parser = ArgumentParser()
|
|
23 |
# parser.add_argument("--dataset", "-d", type=str, default="minor")
|
24 |
# parser.add_argument("--split", "-s", type=str, default="val")
|
25 |
parser.add_argument("--output_path", "-op", type=str, default="./")
|
|
|
|
|
26 |
args, opt = parser.parse_known_args()
|
27 |
|
28 |
dataset = 'all2023' # args.dataset
|
29 |
split = 'val' # args.split
|
30 |
output_path = args.output_path
|
|
|
31 |
|
32 |
# %%
|
33 |
#
|
@@ -52,7 +55,12 @@ from util_preprocess import preprocess_primary_secondary
|
|
52 |
|
53 |
# %%
|
54 |
# file_path = os.path.join('data', 'raw', dataset, f"{split}_{dataset}_cats_full.json")
|
55 |
-
file_path =
|
|
|
|
|
|
|
|
|
|
|
56 |
save_dir = os.path.join(output_path, dataset)
|
57 |
os.makedirs(save_dir, exist_ok=True)
|
58 |
save_path = os.path.join(save_dir, f"{split}.json")
|
|
|
23 |
# parser.add_argument("--dataset", "-d", type=str, default="minor")
|
24 |
# parser.add_argument("--split", "-s", type=str, default="val")
|
25 |
parser.add_argument("--output_path", "-op", type=str, default="./")
|
26 |
+
parser.add_argument("--input_path", "-ip", type=str, default="./",
|
27 |
+
help="Path to the input data files")
|
28 |
args, opt = parser.parse_known_args()
|
29 |
|
30 |
dataset = 'all2023' # args.dataset
|
31 |
split = 'val' # args.split
|
32 |
output_path = args.output_path
|
33 |
+
input_path = args.input_path
|
34 |
|
35 |
# %%
|
36 |
#
|
|
|
55 |
|
56 |
# %%
|
57 |
# file_path = os.path.join('data', 'raw', dataset, f"{split}_{dataset}_cats_full.json")
|
58 |
+
file_path = os.path.join(
|
59 |
+
input_path,
|
60 |
+
'raw',
|
61 |
+
'all2023',
|
62 |
+
'all-2023-new-reps.tsv'
|
63 |
+
)
|
64 |
save_dir = os.path.join(output_path, dataset)
|
65 |
os.makedirs(save_dir, exist_ok=True)
|
66 |
save_path = os.path.join(save_dir, f"{split}.json")
|
preprocess_major_minor.py
CHANGED
@@ -23,11 +23,14 @@ parser = ArgumentParser()
|
|
23 |
parser.add_argument("--dataset", "-d", type=str, default="minor")
|
24 |
parser.add_argument("--split", "-s", type=str, default="train")
|
25 |
parser.add_argument("--output_path", "-op", type=str, default="./")
|
|
|
|
|
26 |
args, opt = parser.parse_known_args()
|
27 |
|
28 |
dataset = args.dataset
|
29 |
split = args.split
|
30 |
output_path = args.output_path
|
|
|
31 |
|
32 |
# %%
|
33 |
#
|
@@ -51,7 +54,12 @@ from util_preprocess import preprocess_primary_secondary
|
|
51 |
# - Major category = field
|
52 |
|
53 |
# %%
|
54 |
-
file_path = os.path.join(
|
|
|
|
|
|
|
|
|
|
|
55 |
save_dir = os.path.join(output_path, dataset)
|
56 |
os.makedirs(save_dir, exist_ok=True)
|
57 |
save_path = os.path.join(save_dir, f"{split}.json")
|
|
|
23 |
parser.add_argument("--dataset", "-d", type=str, default="minor")
|
24 |
parser.add_argument("--split", "-s", type=str, default="train")
|
25 |
parser.add_argument("--output_path", "-op", type=str, default="./")
|
26 |
+
parser.add_argument("--input_path", "-ip", type=str, default="./",
|
27 |
+
help="Path to the input data files")
|
28 |
args, opt = parser.parse_known_args()
|
29 |
|
30 |
dataset = args.dataset
|
31 |
split = args.split
|
32 |
output_path = args.output_path
|
33 |
+
input_path = args.input_path
|
34 |
|
35 |
# %%
|
36 |
#
|
|
|
54 |
# - Major category = field
|
55 |
|
56 |
# %%
|
57 |
+
file_path = os.path.join(
|
58 |
+
input_path,
|
59 |
+
'raw',
|
60 |
+
dataset,
|
61 |
+
f"{split}_{dataset}_cats_full.json"
|
62 |
+
)
|
63 |
save_dir = os.path.join(output_path, dataset)
|
64 |
os.makedirs(save_dir, exist_ok=True)
|
65 |
save_path = os.path.join(save_dir, f"{split}.json")
|
util_preprocess.py
CHANGED
@@ -1,24 +1,40 @@
|
|
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(
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def preprocess_secondary(s):
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
20 |
return subfields
|
21 |
|
22 |
# Preprocess secondary subfields
|
23 |
df.loc[:, 'secondary_subfield'] = df['secondary_subfield'].apply(preprocess_secondary)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
return df
|
|
|
1 |
from arxiv_classifier.utils import (CATEGORY_ALIASES,
|
2 |
GENERAL_CATEGORIES,
|
3 |
+
IGNORED_CATEGOREIES,
|
4 |
+
SUBFIELD_MAP)
|
5 |
|
6 |
IGNORE = GENERAL_CATEGORIES | IGNORED_CATEGOREIES
|
7 |
|
8 |
+
def preprocess_primary_secondary(df):
|
9 |
+
def substitute_aliases(s):
|
10 |
+
if s in CATEGORY_ALIASES:
|
11 |
+
return CATEGORY_ALIASES[s]
|
12 |
+
return s
|
13 |
+
# substitute aliases for primary subfield
|
14 |
+
df.loc[:, 'primary_subfield'] = df['primary_subfield'].apply(substitute_aliases)
|
15 |
+
# ignore row if primary subfield is one of the ignored categories
|
16 |
+
df = df[~df['primary_subfield'].isin(IGNORE)]
|
17 |
|
18 |
def preprocess_secondary(s):
|
19 |
+
subfields = []
|
20 |
+
# split string to list by space
|
21 |
+
for subfield in s.split():
|
22 |
+
# substitute aliases
|
23 |
+
subfield = substitute_aliases(subfield)
|
24 |
+
# ignore secondary subfield if one of the ignored categories
|
25 |
+
if subfield in IGNORE:
|
26 |
+
continue
|
27 |
+
subfields.append(subfield)
|
28 |
+
# return list of subfields
|
29 |
return subfields
|
30 |
|
31 |
# Preprocess secondary subfields
|
32 |
df.loc[:, 'secondary_subfield'] = df['secondary_subfield'].apply(preprocess_secondary)
|
33 |
+
|
34 |
+
# tests
|
35 |
+
# assert that each primary subfield is in SUBFIELD_MAP
|
36 |
+
assert all(df['primary_subfield'].isin(SUBFIELD_MAP.keys()))
|
37 |
+
# assert that each secondary subfield is in SUBFIELD_MAP
|
38 |
+
assert all(df['secondary_subfield'].apply(lambda x: all(subfield in SUBFIELD_MAP.keys() for subfield in x)))
|
39 |
+
# return preprocessed dataframe
|
40 |
return df
|