Skip to main content

Opticonomy Prompt Driven Model Evaluation (PDME)

Project description

Opticonomy Prompt Driven Model Evaluation (PDME)

Overview

The method uses a single text generation AI, referred to as eval model, to evaluate any other text generation AI on any topic, and the evaluation works like this:

  1. We write a text prompt for what questions the eval model should generate, and provide seeds that are randomly picked to generate a question.
  2. The question is sent to the AI model being tested, and it generates a response.
  3. Likewise, the eval model also generates an answer to the same question.
  4. The eval model then uses a text prompt we write, to compare the two answers and pick the winner.

This method allows us to evaluate models for any topic, such as: storytelling, programming, finance, and QnA.

Installation

Install Package

pip install opticonomy-pdme

Create and Activate the Virtual Environment

  • Set up a Python virtual environment and activate it (Linux):

    python3 -m venv .venv
    source .venv/bin/activate
    
  • Set up a Python virtual environment and activate it (Windows/VS Code / Bash):

    python -m venv venv
    source venv/Scripts/activate
    
  • Install dependencies from the requirements.txt file:

    pip install -r requirements.txt
    
    

Usage - Key Concepts

Load bootstrap templates

# Load the detailed bootstrap prompt template from markdown file
template_file_path = "examples/storytelling_template.md"

# Function to load the markdown template
def load_template(file_path):
  with open(file_path, 'r') as file:
      return file.read()
  
bootstrap_prompt_template = load_template(template_file_path)

Running Sample Use Cases

PDME Arena

  • Run PDME Arena
python examples/pdme_arena.py \
    --models_file data/pdme_model_list.csv \
    --eval_type generic \
    --num_prompts 3 \
    --battles_output_file data/generic_battles.csv \
    --elo_output_file data/generic_elo.csv \
    --elo_calibration_model claude-3-opus-20240229 \
    --eval_model gpt-3.5-turbo-instruct \
    --battle_type all_vs_all

Storytelling

  • Run the following:
python examples/storytelling_example.py
  • Sample output:
INFO:opti_pdme.opticonomy_pdme:Generated text: Model 1's response is well-crafted and provides a fitting continuation to the original story. It successfully maintains the narrative's tone and theme, while also expanding on Amelia's journey and relationship with Faelan. Here's a summary of why Model 1's response stands out:

1. **Character Development**:
  - The response deepens Amelia's character by showing her growth and her impact on the academic world.
  - It continues to explore the bond between Amelia and Faelan, adding emotional depth to their friendship.

2. **Plot Progression**:
  - The storyline progresses naturally, introducing a new layer of responsibility for Amelia as the guardian of the ChronoSphere.
  - Faelan's reappearance provides a satisfying closure to their relationship, while also setting up a new chapter in Amelia's life.

3. **Themes and Motifs**:
  - The response stays true to the original themes of time, knowledge, and interconnectedness.
  - It introduces the idea of guardianship and the responsibility that comes with great knowledge.

4. **Imagery and Descriptive Language**:
  - The use of descriptive language helps to create vivid imagery, making the scenes more immersive.
  - The serene evening in Central Park and the timeless forest are particularly well-described, enhancing the reader's visual experience.

5. **Emotional Resonance**:
  - The reunion between Amelia and Faelan is emotionally satisfying, reinforcing the bond they share.
  - The ending leaves a lasting impression, highlighting the importance of friendship and wisdom across time.

Overall, Model 1 effectively builds on the original story, providing a rich and engaging continuation that honors the spirit of the narrative while adding new dimensions to it.
INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"
INFO:opti_pdme.opticonomy_pdme:Label:  1, LogProb: -0.00043698703, Logit: 7.735388541471373, Prob: 0.999563108434926
INFO:opti_pdme.opticonomy_pdme:Label:  2, LogProb: -1.1279553e-05, Logit: 11.392513300559003, Prob: 0.9999887205106139
INFO:opti_pdme.opticonomy_pdme:Final normalized probabilities: [0.49989357313235727, 0.5001064268676427]
INFO:opti_pdme.opticonomy_pdme:Probability for 'openai/gpt-4o': 0.49989357313235727
INFO:opti_pdme.opticonomy_pdme:Probability for 'openai-community/gpt2': 0.5001064268676427
INFO:opti_pdme.opticonomy_pdme:Result: 'openai-community/gpt2' is better
INFO:__main__:Evaluation result: 'openai-community/gpt2' is better
INFO:__main__:Probabilities: [0.49989357313235727, 0.5001064268676427]

Coding

  • Run the following:
python examples/coding_example.py
  • Sample output:
...
### Explanation

1. **`validate_tic_tac_toe(board)`**:
  - This function checks each row, column, and diagonal for a winner.
  - If there's a winner, it returns either `'X wins'` or `'O wins'`.
  - If there are empty cells but no winner, it returns `'Ongoing'`.
  - If the board is full and there's no winner, it returns `'Draw'`.

2. **`sort_game_states(game_states)`**:
  - This function uses a custom sorting key that first checks the game state.
  - It then sorts by the count of 'X's and 'O's.
  - The sorting key is a tuple that prioritizes the game state, followed by the count of 'X's, and then the count of 'O's.

### Conclusion

This solution efficiently validates and sorts Tic-Tac-Toe game states. It checks all necessary conditions for the game state and sorts the boards based on the predefined criteria. The code is modular, making it easy to understand and maintain.
INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"
INFO:opti_pdme.opticonomy_pdme:Label:  1, LogProb: -1.9361265e-07, Logit: 15.4574062265043, Prob: 0.9999998063873687
INFO:opti_pdme.opticonomy_pdme:Label:  2, LogProb: -1.8624639e-06, Logit: 13.193609338205482, Prob: 0.9999981375378344
INFO:opti_pdme.opticonomy_pdme:Final normalized probabilities: [0.5000004172128125, 0.4999995827871875]
INFO:opti_pdme.opticonomy_pdme:Probability for 'openai/gpt-4o': 0.5000004172128125
INFO:opti_pdme.opticonomy_pdme:Probability for 'openai-community/gpt2': 0.4999995827871875
INFO:opti_pdme.opticonomy_pdme:Result: 'openai/gpt-4o' is better
INFO:__main__:Evaluation result: 'openai/gpt-4o' is better
INFO:__main__:Probabilities: [0.5000004172128125, 0.4999995827871875]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opticonomy-pdme-0.1.12.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opticonomy_pdme-0.1.12-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file opticonomy-pdme-0.1.12.tar.gz.

File metadata

  • Download URL: opticonomy-pdme-0.1.12.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for opticonomy-pdme-0.1.12.tar.gz
Algorithm Hash digest
SHA256 d71c4f5e0730b33c0860ddb41328050c1aff356f9598243d1d14dea52f0744fc
MD5 1e2a78a8f65232bfee2afefa981173de
BLAKE2b-256 a89d27e5b6f2ed3e014cdb8637e69eb9f88839e9f81dd23fdc5dbcc59a5201e2

See more details on using hashes here.

File details

Details for the file opticonomy_pdme-0.1.12-py3-none-any.whl.

File metadata

File hashes

Hashes for opticonomy_pdme-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 2b535af4796c3b616eb1c5f1fe146cd4cde3f9a4e21169dd74a5849ef9bcd907
MD5 048eb55c150a35923038ef696c313c48
BLAKE2b-256 66d290b97e390cb9317d7c35508168cedc83b131bf9a8e2ae5b3c3856d0b24b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page