Skip to content
Center-for-Applied-AIPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

2 watching

Forks

Latest commit

 

History

34 Commits

Folders and files

Repository files navigation

Overview

This project extracts commodity-related data in tabular form from raw investor call transcripts using OpenAI's structured outputs.

Key Components

Directory Structure

  • data/: Stores raw, intermediate, and final outputs and hand-coded data (raw/, temp/, clean/, hand).
  • project/: Contains main scripts (s1_prepare_paragraphs.py, s2_call_gpt.py, s3_parse_gpt_responses.py, and utilities).
  • project/restart/: Contains s2_call_gpt_restart.py to resume interrupted API calls.
  • config.yaml: Central configuration file (paths, thresholds, model settings).
  • requirements.txt: Python dependencies.

Scripts

s1_prepare_paragraphs.py

  • Splits raw text into paragraphs and flags those with keywords near numbers.
  • Outputs:
    • paragraphs_all_df.feather: All paragraphs.
    • paragraphs_with_keyword_df.feather: Filtered paragraphs.

s2_call_gpt.py

  • Calls GPT API with filtered paragraphs, saving responses as JSON batches in data/temp/batches/.

project/restart/s2_call_gpt_restart.py

  • Resumes interrupted GPT calls by skipping completed batches.

s3_parse_gpt_responses.py

  • Parses GPT JSON responses into a structured DataFrame.
  • Validates and cleans data:
    • Ensures quotes appear in text.
    • Checks numeric ranges and maps units/commodities.
  • Outputs:
    • output.html and output.xlsx.

utils.py and utils_parse.py

  • Text cleaning, keyword matching, and parsing logic.

Configuration (config.yaml)

  • Model name: gpt-4o-2024-08-06 by default.
  • Input file and prompt paths: data/raw/input.csv and data/hand/prompts/prompt13.txt by default.
  • Thresholds: Controls for fuzzy matching, word distance, and numeric tolerances.
  • Allowed Commodities: Defines recognized commodities.

Setup Instructions

  1. Clone the repo and install dependencies into a python3.12 environment
    git clone git@github.com:Center-for-Applied-AI/calls.git
    cd calls
    pyenv install 3.12 
    pyenv local 3.12 
    pip install virtualenv 
    virtualenv .venv 
    source .venv/bin/activate
    pip install -r requirements.txt
  2. Place your OpenAI API key in a file named secrets.txt in the root directory.

Running the Pipeline

Once in a virtual environment, run scripts from the root directory as:

python project/s1_prepare_paragraphs.py
python project/s2_call_gpt_restart.py
python project/s3_parse_gpt_responses.py

Data Flow

  1. Raw Data → s1_prepare_paragraphs.py: Paragraphs split, flagged, and stored as Feather files.
  2. Paragraphs with Keywords → s2_call_gpt.py: GPT processes paragraphs; JSON responses saved.
  3. GPT Responses → s3_parse_gpt_responses.py: Parsed and validated structured data.
  4. Final Dataset → Outputs: Exported to output.html and output.xlsx.

Interrupted GPT Calls:

If s2_call_gpt.py crashes or times out, you may resume it by running s2_call_gpt_restart.py:

python project/restart/s2_call_gpt_restart.py

Data Dictionary

The following variables are created during the parsing and validation process:

  • paragraph_id: Unique identifier for each paragraph.
  • date: Date associated with the investor call.
  • firm_name: Name of the firm in the transcript.
  • keyword_flag: Boolean indicating if a keyword was detected in proximity to a number.
  • keyword_array: List of detected keywords.
  • keyword_min_distances: Minimum distance between keywords and numbers.
  • price_expectation: Boolean indicating if price expectations were identified.
  • quote: Extracted quote related to commodity price or expectations.
  • quote_extended: Extended quote including one sentence before and after the original quote.
  • quote_in_paragraph_check: Boolean indicating if the quote appears in the paragraph.
  • quote_in_paragraph_fuzzy_check: Boolean indicating if the quote appears in the paragraph under fuzzy matching.
  • price_lower: Lower bound of the price range (if applicable).
  • price_upper: Upper bound of the price range (if applicable).
  • price_range_check: Boolean indicating if the price range is valid (upper >= lower).
  • price_lower_in_quote_check: Boolean indicating if the lower price appears in the quote.
  • price_upper_in_quote_check: Boolean indicating if the upper price appears in the quote.
  • price_lower_in_paragraph_check: Boolean indicating if the lower price appears in the paragraph.
  • price_upper_in_paragraph_check: Boolean indicating if the upper price appears in the paragraph.
  • numbers_in_text_combined_check: Combined check for the presence of numeric values across quote and paragraph.
  • confidence: Confidence score of the parsed response.
  • unit: Standardized unit of measurement.
  • unit_numeral_check: Boolean indicating if the unit is not a large numerical descriptor (e.g., million, billion).
  • good_subtype_stock_check: Boolean indicating if the good subtype is not stock-related.
  • quote_extended_check: Boolean indicating if the quote appears in the extended quote under fuzzy matching.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages