Skip to main content

💬 Important

On June 26 2024, Linux Foundation announced the merger of its financial services umbrella, the Fintech Open Source Foundation (FINOS <https://finos.org>), with OS-Climate, an open source community dedicated to building data technologies, modelling, and analytic tools that will drive global capital flows into climate change mitigation and resilience; OS-Climate projects are in the process of transitioning to the FINOS governance framework <https://community.finos.org/docs/governance>; read more on finos.org/press/finos-join-forces-os-open-source-climate-sustainability-esg <https://finos.org/press/finos-join-forces-os-open-source-climate-sustainability-esg>_

OSC Transformer Pre-Steps

An OS-Climate Project Join OS-Climate on Slack Source code on GitHub PyPI package Built using PDM Project generated with PyScaffold OpenSSF Scorecard

OS-Climate Transformer Pre-Steps Tool

This code provides you with a cli tool with the possibility to extract data from a pdf to a json document and to create a training data set for a later usage in the context of transformer models to extract relevant information, but it can also be used independently.

Quick start

Install via PyPi

You can simply install the package via:

$ pip install osc-transformer-presteps

Afterwards, you can use the tooling as a CLI tool by typing:

$ osc-transformer-presteps

We are using Typer to provide a user-friendly CLI. All details and help will be shown within the CLI itself and are not described here in more detail.

Example 1: Extracting Data from PDFs

Assume the folder structure is as follows:

project/
├-input/
│ ├-file_1.pdf
│ ├-file_2.pdf
│ └─file_3.pdf
├-logs/
└─output/

Now, after installing osc-transformer-presteps, run the following command to extract data from the PDFs to JSON:

$ osc-transformer-presteps extraction run-local-extraction 'input' --output-folder='output' --logs-folder='logs' --force

Note: The --force flag overcomes encryption. Please check if this is a legal action in your jurisdiction.

Example 2: Curating a New Training Data Set for Relevance Detector

To perform curation, you will need a KPI mapping file and an annotations file. Here are examples of such files:

KPI Mapping File:

kpi_mapping.csv

kpi_id

question

sectors

add_year

kpi_category

0

What is the company name?

“OG, CM, CU”

FALSE

TEXT

  • kpi_id: The unique identifier for each KPI.

  • question: The specific question being asked to extract relevant information.

  • sectors: The industry sectors to which the KPI applies.

  • add_year: Indicates whether to include the year in the extracted data (TRUE/FALSE).

  • kpi_category: The category of the KPI, typically specifying the data type (e.g., TEXT).

Annotation File:

annotations_file.xlsx

company

source_file

source_page

kpi_id

year

answer

data_type

relevant_paragraphs

annotator

sector

Royal Dutch Shell plc

Test.pdf

[1]

1

2019

2019

TEXT

[“Sustainability Report 2019”]

1qbit_edited_kpi_extraction_Carolin.xlsx

OG

  • company: The name of the company being analyzed.

  • source_file: The document from which data is extracted.

  • source_page: The page number(s) containing the relevant information.

  • kpi_id: The ID of the KPI associated with the data.

  • year: The year to which the data refers.

  • answer: The specific data or text extracted as an answer.

  • data_type: The type of the extracted data (e.g., TEXT or TABLE).

  • relevant_paragraphs: The paragraph(s) or context where the data was found.

  • annotator: The person or tool that performed the annotation.

  • sector: The industry sector the company belongs to.

You can find demo files in the demo/curation/input folder.

Assume the folder structure is as follows:

project/
├-input/
│ ├-data_from_extraction/
│ │ ├-file_1.json
│ │ ├-file_2.json
│ │ └─file_3.json
│ ├-kpi_mapping/
│ │ └─kpi_mapping.csv
│ ├-annotations_file/
│ │ └─annotations_file.xlsx
├-logs/
└─output/

Now, you can run the following command to curate a new training data set:

$ osc-transformer-presteps relevance-curation run-local-curation 'input/-data_from_extraction/file_1.json' 'input/annotations_file/annotations_file.xlsx' 'input/kpi_mapping/kpi_mapping.csv'

Note: The previous comment may need some adjustment when running on different machine like windows due to the slash.

Example 3: Curating a New Training Data Set for KPI Detector

To perform curation, you will need the extracted json files and kpi mappinf file and annotations file (the same as described above).

Assume the folder structure is as follows:

project/
├-input/
│ ├-data_from_extraction/
│ │ ├-file_1.json
│ │ ├-file_2.json
│ │ └─file_3.json
│ ├-kpi_mapping/
│ │ └─kpi_mapping.csv
│ ├-annotations_file/
│ │ └─annotations_file.xlsx
│ ├-relevance_detection_file/
│ │ └─relevance_detection.csv
├-logs/
└─output/

Now, you can run the following command to curate a new training data set:

$ osc-transformer-presteps kpi-curation run-local-kpi-curation  'input/annotations_file/' 'input/data_from_extraction/' 'output/' 'kpi_mapping/kpi_mapping_file.csv' 'relevance_detection_file/relevance_file.xlsx'  --val-ratio 0.2 --agg-annotation "" --find-new-answerable --create-unanswerable

Note: The previous comment may need some adjustment when running on different machine like windows due to the slash.

Important Note on Annotations

When performing curation, it is crucial that all JSON files used for this process are listed in the demo/curation/input/test_annotation.xlsx file. Failure to include these files in the annotation file will result in corrupted output.

Ensure that every JSON file involved in the curation process is mentioned in the annotation file to maintain the integrity of the resulting output.

Developer space

Use Code Directly Without CLI via Github Repository

First, clone the repository to your local environment:

$ git clone https://github.com/os-climate/osc-transformer-presteps

We are using pdm to manage the packages and tox for a stable test framework. First, install pdm (possibly in a virtual environment) via:

$ pip install pdm

Afterwards, sync your system via:

$ pdm sync

You will find multiple demos on how to proceed in the demo folder.

pdm

To add new dependencies, use pdm. For example, you can add numpy via:

$ pdm add numpy

For more detailed descriptions, check the PDM project homepage.

tox

For running linting tools, we use tox. You can run this outside of your virtual environment:

$ pip install tox
$ tox -e lint
$ tox -e test

This will automatically apply checks on your code and run the provided pytests. See more details on tox.

Metadata

Release files for osc-transformer-presteps 0.1.9

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

Source distribution (sdist)

Source distribution for osc-transformer-presteps 0.1.9
File Size Uploaded
osc_transformer_presteps-0.1.9.tar.gz 2.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for osc-transformer-presteps 0.1.9
File Interpreter ABI Platform
osc_transformer_presteps-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 2.2 MB

Release files / osc_transformer_presteps-0.1.9.tar.gz

Download URL osc_transformer_presteps-0.1.9.tar.gz
Size 2.1 MB
Tags Source
SHA-256 checksum
How to use checksums
a25305f1bf9e837f84e5d6faaa881a6695d68f0ba14ab7e0a00131dd9d49189d
BLAKE2b-256 checksum
How to use checksums
afc9c0293df89bca0bde860d9ed7696da153f84dcea813b2fb70d03dc73f51f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 3, 2025.

Transparency log

Release files / osc_transformer_presteps-0.1.9-py3-none-any.whl

Download URL osc_transformer_presteps-0.1.9-py3-none-any.whl
Size 49.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
908d9f4da97e59be2e01241ccbfc9dafcf0acb9430a4e8c2360787235ecef301
BLAKE2b-256 checksum
How to use checksums
a24cfac679f47093ece5683589b69369eb49cc3d07f957e0766198475cc9dcb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 3, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.6

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

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