# --- | |
# jupyter: | |
# jupytext: | |
# cell_metadata_filter: -all | |
# custom_cell_magics: kql | |
# text_representation: | |
# extension: .py | |
# format_name: percent | |
# format_version: '1.3' | |
# jupytext_version: 1.11.2 | |
# kernelspec: | |
# display_name: arxiv-classifier-next | |
# language: python | |
# name: python3 | |
# --- | |
# %% | |
# | |
# parse arguments | |
# | |
from argparse import ArgumentParser | |
parser = ArgumentParser() | |
# parser.add_argument("--dataset", "-d", type=str, default="minor") | |
# parser.add_argument("--split", "-s", type=str, default="val") | |
parser.add_argument("--output_path", "-op", type=str, default="./") | |
args, opt = parser.parse_known_args() | |
dataset = 'all2023' # args.dataset | |
split = 'val' # args.split | |
output_path = args.output_path | |
# %% | |
# | |
# Remaining imports | |
# | |
import pandas as pd | |
import os | |
from tqdm import tqdm | |
from util_preprocess import preprocess_primary_secondary | |
# %% [markdown] | |
# Rename columns to reflect standarized terminology: | |
# - Field: Bio/cs/physics | |
# - Subfield: Subcategories within each | |
# - Primary subfield (bio., cs.LG): Given primary subfield, you can infer the field | |
# - Secondary subfields: Includes primary subfield, but also includes any subfields that were tagged in the paper (1-5) | |
# | |
# Old terminology to standardized terminology translation: | |
# - Prime category = Primary subfield | |
# - Abstract category = secondary subfield | |
# - Major category = field | |
# %% | |
# file_path = os.path.join('data', 'raw', dataset, f"{split}_{dataset}_cats_full.json") | |
file_path = 'data/raw/all2023/all-2023-new-reps.tsv' | |
save_dir = os.path.join(output_path, dataset) | |
os.makedirs(save_dir, exist_ok=True) | |
save_path = os.path.join(save_dir, f"{split}.json") | |
print("Reading from file: ", file_path) | |
FEATURES = [ | |
'paper_id', | |
'version', | |
'yymm', | |
'created', | |
'title', | |
'secondary_subfield', | |
'abstract', | |
'primary_subfield', | |
'field', | |
'fulltext' | |
] | |
for i, original_df in tqdm(enumerate(pd.read_csv(file_path, sep='\t', chunksize=10**4))): | |
# drop columns | |
original_df.drop(columns=['type', 'status'], inplace=True) | |
# Rename columns | |
original_df.rename(columns={ | |
'category': 'primary_subfield', | |
'doc_paper_id': 'paper_id', | |
'version title': 'version', | |
}, inplace=True) | |
# set remaining features to empty string | |
for feature in FEATURES: | |
if feature not in original_df.columns: | |
original_df[feature] = "" | |
# Apply preprocessing rules | |
df = preprocess_primary_secondary(original_df) | |
# convert all columns to string per huggingface requirements | |
if i == 0: | |
df.to_json(save_path, lines=True, orient="records") | |
else: | |
df.to_json(save_path, lines=True, orient="records", mode='a') | |
print("Saved to: ", save_path) | |
# %% | |