A flexible scoring library using OpenAI models.
Project description
Flexible Scorer Library
Flexible Scorer is a Python library that allows you to evaluate and score text content based on custom criteria using OpenAI's GPT models. It provides a systematic way to assess texts, taking advantage of AI's capabilities to interpret and analyze content according to user-defined parameters.
Features
- Customizable Criteria:Score texts based on any criteria you define (e.g., humor, clarity, relevance)
- Scalable Scoring System: Utilizes a 1 to 10 scale for nuanced evaluations
- OpenAI GPT Integration: Leverages powerful language models for deep text analysis
- Probability Analysis: Computes weighted scores using token log probabilities
- Visualization Tools: Includes functions to plot and visualize scoring results using Plotly
Installation
Installation through PIP manager
pip install flexiblescorer
Dependencies
- numpy
- openai
- plotly
- scipy
Getting Started
Set OpenAI API key as environment
Enter OpenAI API key to use model
a. For Windows Users
set OPENAI_API_KEY=your-api-key-here
b. For macOS and Linux Users
export OPENAI_API_KEY=your-api-key-here
Replace 'your-api-key-here' with your actual OpenAI API key, which you can obtain from your OpenAI account
Basic Usage Example
from flexible_scorer import FlexibleScorer
# Define your evaluation criteria
criteria = "humor"
# Initialize the scorer with the criteria
scorer = FlexibleScorer(criteria)
# Texts to evaluate
texts = [
"Why don't scientists trust atoms? Because they make up everything!",
"This is a serious statement without any humor.",
"Why did the math book look sad? Because it had too many problems."
]
# Additional instructions (optional)
additional_instructions = "Consider clever wordplay and puns in your evaluation."
# Score the texts
scores = []
for text in texts:
score = scorer.score(text, additional_instructions)
scores.append(score)
print(f"Text: {text}\nScore: {score}\n")
# Plot the results
scorer.plot_results(texts, scores)
- FlexibleScorer: The main class used to score texts based on your criteria
- criteria: A String defining what aspect you want to evaluate (e.g., "humor", "clarity")
- score(): Method to evaluate a single text. Optionally, you can provide additional instructions to guide the evaluation
- plot_results(): Method to visualize the scores of multiple texts
API Reference
FlexibleScorer
Initialization
scorer = FlexibleScorer(criteria, model='gpt-4')
- criteria (str): The criteria upon which to evaluate the text
- model (str, optional): The OpenAI GPT model to use (default is 'gpt-4')
Methods
- score(text, additional_instructions='')
- text(str): The text content to evaluate
- additional_instructions (str, optional): Extra guidelines for the evaluations
- Returns (float): A normalized score between 0 and 1
- plot_results(texts, scores)
- texts (list of str): A list of text contents evaluated
- scores (list of float): Corresponding scores for the texts
- Displays: An interactive bar chart of the results
OpenAI API Usage
This library uses the OpenAI API under the hood. Ensure you comply with OpenAI's Usage Policies when using this package
License
This project is licensed under the MIT License
Contributing
Contributions are welcome! Please open an issue or submit a pull request on Github
Acknowledgments
- Thanks to OpenAI for providing access to their powerful language models
- Inspired by the need for flexible and customizable text evaluation tools
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flexible_scorer-0.1.14.tar.gz.
File metadata
- Download URL: flexible_scorer-0.1.14.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4380bb9baa93ac37c0bbeff857e4e56e91635a0e87b6f885ddf4072b98c53cea
|
|
| MD5 |
58f16ef7e1fea8cf8162994f9b6a1477
|
|
| BLAKE2b-256 |
67c2a224f72f7e9d678f3dd9b9d49d46dd89ab98262aff0d29eaf6301eabf07f
|
File details
Details for the file flexible_scorer-0.1.14-py3-none-any.whl.
File metadata
- Download URL: flexible_scorer-0.1.14-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a31d9ecd56c6c9089ff3b27b620d0284fee5010ce05e47aa63151f8cddb5a871
|
|
| MD5 |
945ec703f65fa2bf11b29d17eabef3d8
|
|
| BLAKE2b-256 |
3cc37868ba6563cfd79d211bdb5f9ffce5401e8e811ff63ee32bb5d9a06c44c0
|