# Reproduce the prepared corpora This folder contains the standalone preprocessing code shared by SciNews, BBC-News, WOS-5736, WOS-11967 and WOS-46985. It downloads pinned source files, rebuilds the CSV and JSON files described in the dataset cards, and checks the result against the recorded SHA-256 values. It needs no parent project checkout, BigARTM, TopicNet installation or model training. The code is distributed under [MIT](LICENSE). This license covers the code only. Source texts and prepared data retain their own rights and access conditions; consult the corresponding dataset card and original source notices. In particular, rebuilding SciNews requires approved access to the original dataset, and BBC redistribution rights remain unresolved. ## Obtain only the code The common code lives in `preprocessing/` in the `TopicNet/SciNews` dataset repository. Downloading this folder does not require access to the original SciNews source. Separate source approval is needed only to rebuild SciNews; it is not needed to run the code for BBC-News or WOS. Choose a full commit hash from the repository history that contains this folder. Set `CODE_REVISION` to that hash, rather than relying on a moving `main` branch. Use a separate download environment with the official `huggingface_hub` SDK for this initial download (`python -m pip install huggingface_hub==1.25.1`): ```bash export CODE_REVISION=REPLACE_WITH_FULL_COMMIT_HASH python - <<'PY' import os from huggingface_hub import snapshot_download snapshot_download( repo_id="TopicNet/SciNews", repo_type="dataset", revision=os.environ["CODE_REVISION"], allow_patterns=["preprocessing/*"], local_dir="corpus-code", ) PY cd corpus-code ``` This downloads the code folder, not the prepared SciNews CSV files. Before the code is published, use the local copy of `SciNews/preprocessing/` instead and work from its parent directory. A Hugging Face commit containing new code is available only after that code has been committed to the dataset repository. ## Create the environment The supplied locks target Linux x86-64 with Python 3.11.15. Create a dedicated environment with Conda, then install the locked Python packages: ```bash conda create --prefix /path/to/envs/corpus-preprocessing --file preprocessing/conda-linux-64.lock.txt conda activate /path/to/envs/corpus-preprocessing python -m pip install -r preprocessing/pip-linux-x86_64.lock.txt ``` Place the environment outside the downloaded code folder. Keep the locks unchanged for byte-for-byte reproduction. Scientific dependencies and NLTK resources are checked by the program. NLTK 3.9.2 uses the resource revision recorded in the cards and source pins. The Hugging Face download SDK is an optional network dependency, specified in `preprocessing/requirements-download.txt`; install it when downloading SciNews: ```bash python -m pip install -r preprocessing/requirements-download.txt ``` ## Download sources Choose a writable source directory. The supported dataset selectors are `bbc-news`, `scinews`, `wos-5736`, `wos-11967` and `wos-46985`: ```bash python preprocessing/prepare.py download --dataset bbc-news --sources-dir /path/to/sources python preprocessing/prepare.py download --dataset scinews --sources-dir /path/to/sources python preprocessing/prepare.py download --dataset wos-5736 --sources-dir /path/to/sources ``` The three WOS selectors share the same source archive, so download it once. Before the WOS download command, obtain the original `ReadMe.txt` notice from the [official version 6 release](https://data.mendeley.com/datasets/9rw3vkcfy4/6) and place it at `/path/to/sources/wos/ReadMe.txt`. Preserve its exact bytes: 2,587 bytes, SHA-256 `6da4ab1e624c4ef61c46600d727770f873ff4db3c15541fb481e7af8a715c0ec`. You can copy `SOURCE_README.txt` unchanged from any of the provided WOS packages to this path; all three packages contain the same notice with this exact hash. The notice requires this manual step because its stable download URL could not be confirmed. The program validates it, then downloads and validates the archive; it stops with placement instructions if the notice is absent. Downloads also provide the pinned NLTK resources. For SciNews, first obtain approval at the original `dongqi-me/SciNews` repository and authenticate through the standard Hugging Face login or `HF_TOKEN` environment variable. Approval for one repository does not imply approval for another. Keep credentials out of logs and copied source directories. The downloaded layout is: ```text sources/ bbc-news/bbc-fulltext.zip scinews/README.md scinews/train.json scinews/val.json scinews/test.json wos/WebOfScience.zip wos/ReadMe.txt nltk_data/ ``` Only the selected corpus and shared NLTK resources are needed for each build. Source revisions, URLs and expected hashes are recorded in this code folder; substituting a newer source release changes the input and is rejected. If source files are transferred manually, preserve this layout and their exact bytes. ## Build and verify offline After downloading sources and installing the environment, build and verify need no network connection. Select a fresh output path and a fresh scratch path. The output directory holds `noow.csv`, `bow.csv`, `labels.json` and `splits.json`, plus `hierarchy.json` for WOS. These correspond to the files under `data/` in the respective dataset repository. Scratch files are kept separately. ```bash export HF_HUB_OFFLINE=1 export HF_DATASETS_OFFLINE=1 python preprocessing/prepare.py build --dataset bbc-news \ --sources-dir /path/to/sources \ --output-dir /path/to/rebuilt/BBC-News/data \ --scratch-dir /path/to/scratch/bbc-news python preprocessing/prepare.py verify --dataset bbc-news \ --data-dir /path/to/rebuilt/BBC-News/data ``` Use the same commands with any supported selector. Verification checks the recorded hashes of the prepared data files, including split memberships and WOS hierarchy metadata; it does not download missing inputs or rebuild files. A successful build alone is not a successful verification. The dataset-level `sha256sum -c SHA256SUMS` checks a complete downloaded repository package, including its card and source notice, and is separate from verifying a rebuild. Missing output and scratch parent directories are created after input and path validation. Both destination directories themselves must be new. Builds refuse to overwrite existing outputs. If a build fails, retain its output, scratch files and log for diagnosis. Use new output and scratch paths for a manual retry; do not treat a partial directory as a verified result. ## Run the bundled checks From the directory containing `preprocessing/`, run the checks with Python's standard `unittest` runner; no additional test dependency is needed: ```bash python -B -m unittest discover -v -s preprocessing -p test_prepare.py PORTABLE_NLTK_DATA=/absolute/path/to/sources/nltk_data \ python -B -m unittest discover -v -s preprocessing -p test_prepare.py ``` The first command skips the three checks requiring real NLTK resources. The second runs all six checks with the locked environment and acquired resources. Full rebuilds from the raw sources followed by exact hash verification have been confirmed for BBC-News and WOS-5736. Full SciNews, WOS-11967 and WOS-46985 reproduction is pending server verification; fixture checks and source pins alone do not establish byte-for-byte reproduction of those builds. ## Run the remaining full builds on a server Transfer this entire code folder and the relevant downloaded sources, including `nltk_data/`, to the server. Recreate the locked environment there using the commands above. Run from the directory containing `preprocessing/`. Choose paths on a filesystem with enough space for source archives, temporary files and both CSV representations. These full builds may take substantially longer than a small-corpus run; no fixed time or memory limit is assumed here. The following Bash example records build and verification logs separately and stops if either command fails. Replace the paths before running; all output, scratch and log paths must be fresh: ```bash set -euo pipefail export HF_HUB_OFFLINE=1 export HF_DATASETS_OFFLINE=1 SOURCE_ROOT=/srv/corpus-sources RUN_ROOT=/srv/corpus-rebuild-001 mkdir "$RUN_ROOT" mkdir "$RUN_ROOT/logs" python --version > "$RUN_ROOT/logs/python.txt" 2>&1 python -m pip freeze > "$RUN_ROOT/logs/packages.txt" find preprocessing -type f ! -path '*/__pycache__/*' ! -name '*.pyc' -print0 \ | sort -z | xargs -0 sha256sum > "$RUN_ROOT/logs/code-sha256.txt" for DATASET in scinews wos-11967 wos-46985; do python preprocessing/prepare.py build --dataset "$DATASET" \ --sources-dir "$SOURCE_ROOT" \ --output-dir "$RUN_ROOT/$DATASET/data" \ --scratch-dir "$RUN_ROOT/$DATASET-scratch" \ 2>&1 | tee "$RUN_ROOT/logs/$DATASET-build.log" python preprocessing/prepare.py verify --dataset "$DATASET" \ --data-dir "$RUN_ROOT/$DATASET/data" \ 2>&1 | tee "$RUN_ROOT/logs/$DATASET-verify.log" done ``` Retain the chosen code commit hash with these logs. Count a corpus as reproduced only after its verification command exits successfully. If a command fails, the loop stops and preserves its existing files; choose a new run directory when retrying.