Skip to main content

ScienceBeam Utils

Overview

License: MIT

Provides utility functions related to the ScienceBeam project.

Please refer to the development documentation if you wish to contribute to the project.

Most tools are not yet documented. Please feel free to browse the code or tests, or raise an issue.

Pre-requisites

Apache Beam may be used to for preprocessing but also its transparent FileSystems API which makes it easy to access files in the cloud.

Install

pip install apache_beam[gcp]
pip install sciencebeam-utils

CLI Tools

Find File Pairs

The preferred input layout is a directory containing a gzipped pdf (.pdf.gz) and gzipped xml (.nxml.gz), e.g.:

  • manuscript_1/
    • manuscript_1.pdf.gz
    • manuscript_1.nxml.gz
  • manuscript_2/
    • manuscript_2.pdf.gz
    • manuscript_2.nxml.gz

Using compressed files is optional but recommended to reduce file storage cost.

The parent directory per manuscript is optional. If that is not the case then the name before the extension must be identical (which is recommended in general).

Run:

python -m sciencebeam_utils.tools.find_file_pairs \
--data-path <source directory> \
--source-pattern *.pdf.gz --xml-pattern *.nxml.gz \
--out <output file list csv/tsv>

e.g.:

python -m sciencebeam_utils.tools.find_file_pairs \
--data-path gs://some-bucket/some-dataset \
--source-pattern *.pdf.gz --xml-pattern *.nxml.gz \
--out gs://some-bucket/some-dataset/file-list.tsv

That will create the TSV (tab separated) file file-list.tsv with the following columns:

  • source_url
  • xml_url

That file could also be generated using any other preferred method.

Split File List

To separate the file list into a training, validation and test dataset, the following script can be used:

python -m sciencebeam_utils.tools.split_csv_dataset \
--input <csv/tsv file list> \
--train 0.5 --validation 0.2 --test 0.3 --random --fill

e.g.:

python -m sciencebeam_utils.tools.split_csv_dataset \
--input gs://some-bucket/some-dataset/file-list.tsv \
--train 0.5 --validation 0.2 --test 0.3 --random --fill

That will create three separate files in the same directory:

  • file-list-train.tsv
  • file-list-validation.tsv
  • file-list-test.tsv

The file pairs will be randomly selected (--random) and one group will also include all remaining file pairs that wouldn't get include due to rounding (--fill).

As with the previous step, you may decide to use your own process instead.

Note: those files shouldn't change anymore once you used those files

Get Output Files

Since ScienceBeam is intended to convert files, there will be output files. To make it specific what the filenames are, the output files are also kept in a file list. This tool will generate the file list (it doesn't matter whether the files actually exist for this purpose).

e.g.

python -m sciencebeam_utils.tools.get_output_files \
  --source-file-list path/to/source/file-list-train.tsv \
  --source-file-column=source_url \
  --output-file-suffix=.xml \
  --output-file-list path/to/results/file-list.lst

By adding the --check argument, it will check whether the output files exist (see below).

Check File List

After generating an output file list, this tool can be used whether the output files exist or are complete.

e.g.

python -m sciencebeam_utils.tools.check_file_list \
  --file-list path/to/results/file-list.lst \
  --file-column=source_url \
  --limit=100

This will check the first 100 output files and report on it. The command will fail if none of the output files exist.

Metadata

Release files for sciencebeam-utils 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sciencebeam-utils 0.1.7
File Size Uploaded Provenance Actions
sciencebeam_utils-0.1.7.tar.gz 22.2 kB Without provenance Details for sciencebeam_utils-0.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sciencebeam-utils 0.1.7
File Interpreter ABI Platform Actions
sciencebeam_utils-0.1.7-py3-none-any.whl Python 3 none any Details for sciencebeam_utils-0.1.7-py3-none-any.whl

Total release size: 51.5 kB

Release files / sciencebeam_utils-0.1.7.tar.gz

Download URL sciencebeam_utils-0.1.7.tar.gz
Size 22.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f988f8a44cab9ba532a45e1e0d871e238b9dd5c8fe2c1be64ec915848bb28a09
BLAKE2b-256 checksum
How to use checksums
722f853dafb38ed75ad4facb1b3fd1ca57986a244d7672c3db93ee1fdbbfa217
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / sciencebeam_utils-0.1.7-py3-none-any.whl

Download URL sciencebeam_utils-0.1.7-py3-none-any.whl
Size 29.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24d57b20acdff22b5f798a440ea40a57113b855ff010a3bb606ff75e6684c4f0
BLAKE2b-256 checksum
How to use checksums
5db778fdde978440670bfd730ceede555ff877de151c60ad044ea052f8e27531
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for sciencebeam-utils 0.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page