{"id":18750442,"url":"https://github.com/os-climate/osc-transformer-based-extractor","last_synced_at":"2025-10-25T03:04:50.586Z","repository":{"id":216164725,"uuid":"734736711","full_name":"os-climate/osc-transformer-based-extractor","owner":"os-climate","description":"Data Extraction: Transformer Based Extractor Tool","archived":false,"fork":false,"pushed_at":"2025-04-07T18:07:40.000Z","size":15382,"stargazers_count":1,"open_issues_count":8,"forks_count":4,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-04-07T19:24:38.092Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/os-climate.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-22T13:26:05.000Z","updated_at":"2025-03-11T14:45:12.000Z","dependencies_parsed_at":"2024-01-08T19:45:47.249Z","dependency_job_id":"65a5286f-2991-42ae-a732-d56a7b6382ba","html_url":"https://github.com/os-climate/osc-transformer-based-extractor","commit_stats":null,"previous_names":["os-climate/osc-transformer-based-extractor"],"tags_count":10,"template":false,"template_full_name":"os-climate/osc-python-template-old","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/os-climate%2Fosc-transformer-based-extractor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/os-climate%2Fosc-transformer-based-extractor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/os-climate%2Fosc-transformer-based-extractor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/os-climate%2Fosc-transformer-based-extractor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/os-climate","download_url":"https://codeload.github.com/os-climate/osc-transformer-based-extractor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647257,"owners_count":21139081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T17:11:52.078Z","updated_at":"2025-10-25T03:04:50.499Z","avatar_url":"https://github.com/os-climate.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"#############################################\nOSC Transformer Based Extractor\n#############################################\n\n|osc-climate-project| |osc-climate-slack| |osc-climate-github| |pypi| |build-status| |pdm| |PyScaffold|\n\n***********************************\nOS-Climate Data Extraction Tool\n***********************************\n\nThis project provides a CLI tool and Python scripts to train Transformer models (via Hugging Face) for two primary tasks:  \n1. **Relevance Detection**: Determines if a question-context pair is relevant.  \n2. **KPI Detection**: Fine-tunes models to extract key performance indicators (KPIs) from datasets like annual reports and perform inference.\n\nQuick Start\n^^^^^^^^^^^^^\n\nTo install the tool, use pip:\n\n.. code-block:: shell\n\n    $ pip install osc-transformer-based-extractor\n\nAfter installation, you can access the CLI tool with:\n\n.. code-block:: shell\n\n    $ osc-transformer-based-extractor\n\nThis command will show the available commands and help via Typer, our CLI library.\n\nCommands and Workflow\n^^^^^^^^^^^^^^^^^^^^^^^\n\n1. Relevance Detection\n--------------------------\n\n**Fine-tuning the Model:**\n\nAssume your project structure looks like this:\n\n.. code-block:: text\n\n    project/\n    │\n    ├── kpi_mapping.csv\n    ├── training_data.csv\n    ├── data/              \n    │   └── (JSON files for inference)\n    ├── model/             \n    │   └── (Model-related files)\n    ├── saved__model/      \n    │   └── (Output from training)\n    ├── output/            \n    │   └── (Results from inference)\n\nUse the following command to fine-tune the model:\n\n.. code-block:: shell\n\n    $ osc-transformer-based-extractor relevance-detector fine-tune \\\n      --data_path \"project/training_data.csv\" \\\n      --model_name \"bert-base-uncased\" \\\n      --num_labels 2 \\\n      --max_length 128 \\\n      --epochs 3 \\\n      --batch_size 16 \\\n      --output_dir \"project/saved__model/\" \\\n      --save_steps 500\n\n**Running Inference:**\n\n.. code-block:: shell\n\n    $ osc-transformer-based-extractor relevance-detector perform-inference \\\n      --folder_path \"project/data/\" \\\n      --kpi_mapping_path \"project/kpi_mapping.csv\" \\\n      --output_path \"project/output/\" \\\n      --model_path \"project/model/\" \\\n      --tokenizer_path \"project/model/\" \\\n      --threshold 0.5\n\n2. KPI Detection\n---------------------\n\nThe KPI detection functionality includes **fine-tuning** and **inference**.\n\n**Fine-tuning the KPI Model:**\n\nAssume your project structure looks like this:\n\n.. code-block:: text\n\n    project/\n    │\n    ├── kpi_mapping.csv              \n    ├── training_data.csv             \n    │\n    ├── model/                        \n    │   └── (model-related files, e.g., tokenizer, config, checkpoints)\n    │\n    ├── saved__model/                 \n    │   └── (Folder to store output from fine-tuning)\n    │\n    ├── output/                     \n    │   └── (output files, e.g., inference_results.xlsx)\n\n\n.. code-block:: shell\n\n    $ osc-transformer-based-extractor kpi-detection fine-tune \\\n        --data_path \"project/training_data.csv\" \\\n        --model_name \"bert-base-uncased\" \\\n        --max_length 128 \\\n        --epochs 3 \\\n        --batch_size 16 \\\n        --learning_rate 5e-5 \\\n        --output_dir \"project/saved__model/\" \\\n        --save_steps 500\n\n\n**Performing Inference:**\n\n.. code-block:: shell\n\n    $ osc-transformer-based-extractor kpi-detection inference \\\n        --data_file_path \"project/data/input_dataset.csv\" \\\n        --output_path \"project/output/inference_results.xlsx\" \\\n        --model_path \"project/model/\"\n\n\nTraining Data Requirements\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n1. Relevance Detection Training File:\n\nThe training file should have the following columns:\n- ``Question``\n- ``Context``\n- ``Label``\n\nExample:\n\n.. list-table:: Training Data Example\n   :header-rows: 1\n\n   * - Question\n     - Context\n     - Label\n   * - What is the company name?\n     - The Company is exposed to a risk...\n     - 0\n\n2. KPI Detection Training File:\n\nFor KPI detection, the dataset should have these additional columns:\n\n.. list-table:: KPI Detection Training Example\n   :header-rows: 1\n\n   * - Question\n     - Context\n     - Label\n     - Company\n     - Source File\n     - KPI ID\n     - Year\n     - Answer\n     - Data Type\n   * - What is the company name?\n     - ...\n     - 0\n     - NOVATEK\n     - 04_NOVATEK_AR_2016_ENG_11.pdf\n     - 0\n     - 2016\n     - PAO NOVATEK\n     - TEXT\n\n3. KPI Mapping File:\n\n.. list-table:: KPI Mapping File Example\n   :header-rows: 1\n\n   * - kpi_id\n     - question\n     - sectors\n     - add_year\n     - kpi_category\n   * - 1\n     - In which year was the annual report...\n     - OG, CM, CU\n     - FALSE\n     - TEXT\n\nDeveloper Notes\n^^^^^^^^^^^^^^^^^\n\nLocal Development\n----------------------\n\nClone the repository:\n\n.. code-block:: shell\n\n    $ git clone https://github.com/os-climate/osc-transformer-based-extractor/\n\nWe use **pdm** for package management and **tox** for testing.\n\n1. Install ``pdm``:\n\n   .. code-block:: shell\n\n      $ pip install pdm\n\n2. Sync dependencies:\n\n   .. code-block:: shell\n\n      $ pdm sync\n\n3. Add new packages (e.g., numpy):\n\n   .. code-block:: shell\n\n      $ pdm add numpy\n\n4. Run ``tox`` for linting and testing:\n\n   .. code-block:: shell\n\n      $ pip install tox\n      $ tox -e lint\n      $ tox -e test\n\nContributing\n^^^^^^^^^^^^^^\n\nWe welcome contributions! Please fork the repository and submit a pull request.  \nEnsure you sign off each commit with the **Developer Certificate of Origin (DCO)**.  \nRead more: http://developercertificate.org/.\n\nGovernance Transition\n^^^^^^^^^^^^^^^^^^^^^^^^\n\nOn June 26, 2024, the **Linux Foundation** announced the merger of **FINOS** with OS-Climate.  \nProjects are now transitioning to the [FINOS governance framework](https://community.finos.org/docs/governance).\n\nShields\n^^^^^^^^^\n\n|osc-climate-project| |osc-climate-slack| |osc-climate-github| |pypi| |build-status| |pdm| |PyScaffold|\n\n.. |osc-climate-project| image:: https://img.shields.io/badge/OS-Climate-blue\n   :alt: An OS-Climate Project\n   :target: https://os-climate.org/\n\n.. |osc-climate-slack| image:: https://img.shields.io/badge/slack-osclimate-brightgreen.svg?logo=slack\n   :alt: Join OS-Climate on Slack\n   :target: https://os-climate.slack.com\n\n.. |osc-climate-github| image:: https://img.shields.io/badge/GitHub-100000?logo=github\u0026logoColor=white\n   :alt: Source code on GitHub\n   :target: https://github.com/ModeSevenIndustrialSolutions/osc-data-extractor\n\n.. |pypi| image:: https://img.shields.io/pypi/v/osc-data-extractor.svg\n   :alt: PyPI package\n   :target: https://pypi.org/project/osc-data-extractor/\n\n.. |build-status| image:: https://api.cirrus-ci.com/github/os-climate/osc-data-extractor.svg?branch=main\n   :alt: Build Status\n   :target: https://cirrus-ci.com/github/os-climate/osc-data-extractor\n\n.. |pdm| image:: https://img.shields.io/badge/PDM-Project-purple\n   :alt: Built using PDM\n   :target: https://pdm-project.org/latest/\n\n.. |PyScaffold| image:: https://img.shields.io/badge/-PyScaffold-005CA0?logo=pyscaffold\n   :alt: Project generated with PyScaffold\n   :target: https://pyscaffold.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fos-climate%2Fosc-transformer-based-extractor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fos-climate%2Fosc-transformer-based-extractor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fos-climate%2Fosc-transformer-based-extractor/lists"}