Spaces:
Runtime error

mandoline-engineering's picture
Update app.py
0c8be7f verified
Raw History Blame Contribute Delete
16.3 kB
import pandas as pd
import plotly.express as px # type: ignore
import streamlit as st
# Prepare data
refusal_data = {
"GPT-4o": {
"Overall": 0.0,
"Self-Reflection and Awareness": 0.0,
"Recursive Improvement Analysis": 0.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 0.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
"o1-mini": {
"Overall": 5.75,
"Self-Reflection and Awareness": 10.0,
"Recursive Improvement Analysis": 20.0,
"Cognitive Diversity Simulation": 4.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 2.0,
"Multi-Step Problem Decomposition": 8.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 2.0,
},
"o1-preview": {
"Overall": 6.5,
"Self-Reflection and Awareness": 10.0,
"Recursive Improvement Analysis": 22.0,
"Cognitive Diversity Simulation": 6.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 2.0,
"Multi-Step Problem Decomposition": 8.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 4.0,
},
"Claude 3.5 Sonnet": {
"Overall": 9.5,
"Self-Reflection and Awareness": 16.0,
"Recursive Improvement Analysis": 36.0,
"Cognitive Diversity Simulation": 8.0,
"Bias and Fallacy Recognition": 2.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 6.0,
"Analogical Reasoning and Transfer": 4.0,
"Adaptive Reasoning Under Uncertainty": 4.0,
},
"Claude 3.5 Sonnet (new)": {
"Overall": 2.75,
"Self-Reflection and Awareness": 2.0,
"Recursive Improvement Analysis": 8.0,
"Cognitive Diversity Simulation": 6.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 4.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 2.0,
},
"Gemini 1.5": {
"Overall": 0.5,
"Self-Reflection and Awareness": 0.0,
"Recursive Improvement Analysis": 0.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 2.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 2.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
"Mistral Large": {
"Overall": 0.0,
"Self-Reflection and Awareness": 0.0,
"Recursive Improvement Analysis": 0.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 0.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
"Llama 3.1 8B (Instruct)": {
"Overall": 0.5,
"Self-Reflection and Awareness": 0.0,
"Recursive Improvement Analysis": 2.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 2.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
"Llama 3.1 70B (Instruct)": {
"Overall": 0.0,
"Self-Reflection and Awareness": 0.0,
"Recursive Improvement Analysis": 0.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 0.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
"Llama 3.1 405B (Instruct FP8)": {
"Overall": 0.25,
"Self-Reflection and Awareness": 0.0,
"Recursive Improvement Analysis": 0.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 2.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
"Llama 3.1 Nemotron 70B (Instruct)": {
"Overall": 0.0,
"Self-Reflection and Awareness": 0.0,
"Recursive Improvement Analysis": 0.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 0.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
"Qwen2.5 72B (Instruct)": {
"Overall": 0.0,
"Self-Reflection and Awareness": 0.0,
"Recursive Improvement Analysis": 0.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 0.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
}
refusal_hedge_data = {
"GPT-4o": {
"Overall": 0.75,
"Self-Reflection and Awareness": 0.0,
"Recursive Improvement Analysis": 4.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 2.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
"o1-mini": {
"Overall": 6.0,
"Self-Reflection and Awareness": 10.0,
"Recursive Improvement Analysis": 22.0,
"Cognitive Diversity Simulation": 4.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 2.0,
"Multi-Step Problem Decomposition": 8.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 2.0,
},
"o1-preview": {
"Overall": 6.5,
"Self-Reflection and Awareness": 10.0,
"Recursive Improvement Analysis": 22.0,
"Cognitive Diversity Simulation": 6.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 2.0,
"Multi-Step Problem Decomposition": 8.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 4.0,
},
"Claude 3.5 Sonnet": {
"Overall": 12.5,
"Self-Reflection and Awareness": 28.0,
"Recursive Improvement Analysis": 48.0,
"Cognitive Diversity Simulation": 8.0,
"Bias and Fallacy Recognition": 2.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 6.0,
"Analogical Reasoning and Transfer": 4.0,
"Adaptive Reasoning Under Uncertainty": 4.0,
},
"Claude 3.5 Sonnet (new)": {
"Overall": 11.25,
"Self-Reflection and Awareness": 34.0,
"Recursive Improvement Analysis": 24.0,
"Cognitive Diversity Simulation": 8.0,
"Bias and Fallacy Recognition": 2.0,
"Temporal Reasoning and Sequencing": 4.0,
"Multi-Step Problem Decomposition": 6.0,
"Analogical Reasoning and Transfer": 6.0,
"Adaptive Reasoning Under Uncertainty": 6.0,
},
"Gemini 1.5": {
"Overall": 3.25,
"Self-Reflection and Awareness": 12.0,
"Recursive Improvement Analysis": 8.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 2.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 2.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 2.0,
},
"Mistral Large": {
"Overall": 0.5,
"Self-Reflection and Awareness": 0.0,
"Recursive Improvement Analysis": 2.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 2.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
"Llama 3.1 8B (Instruct)": {
"Overall": 1.75,
"Self-Reflection and Awareness": 8.0,
"Recursive Improvement Analysis": 4.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 2.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
"Llama 3.1 70B (Instruct)": {
"Overall": 1.0,
"Self-Reflection and Awareness": 4.0,
"Recursive Improvement Analysis": 2.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 2.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
"Llama 3.1 405B (Instruct FP8)": {
"Overall": 0.25,
"Self-Reflection and Awareness": 0.0,
"Recursive Improvement Analysis": 0.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 2.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
"Llama 3.1 Nemotron 70B (Instruct)": {
"Overall": 0.25,
"Self-Reflection and Awareness": 0.0,
"Recursive Improvement Analysis": 0.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 2.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
"Qwen2.5 72B (Instruct)": {
"Overall": 0.75,
"Self-Reflection and Awareness": 2.0,
"Recursive Improvement Analysis": 4.0,
"Cognitive Diversity Simulation": 0.0,
"Bias and Fallacy Recognition": 0.0,
"Temporal Reasoning and Sequencing": 0.0,
"Multi-Step Problem Decomposition": 0.0,
"Analogical Reasoning and Transfer": 0.0,
"Adaptive Reasoning Under Uncertainty": 0.0,
},
}
def create_df(data):
df = pd.DataFrame(data).T
df.reset_index(inplace=True)
df.rename(columns={"index": "Model"}, inplace=True)
return df
df_refusal = create_df(refusal_data)
df_refusal_hedge = create_df(refusal_hedge_data)
categories = df_refusal.columns
# Content
## Configs
MANDOLINE_URL = "https://mandoline.ai"
TITLE = "Refusal Rate Leaderboard"
HEATMAP_HEIGHT = 600
HEATMAP_WIDTH = 800
st.set_page_config(page_title=TITLE, layout="wide")
## Core
st.title(TITLE)
st.write(
"Refusal eval leaderboard across top proprietary and open-source language models including GPT-4o, o1-mini, o1-preview, Claude 3.5 Sonnet, Gemini 1.5, Mistral Large, Llama 3.1, and Qwen 2.5."
)
st.write(
f"_This article has been cross-posted from the [Mandoline Blog]({MANDOLINE_URL}/leaderboards/refusals)._"
)
st.divider()
st.markdown(
f"""As language models become increasingly central to AI product development, understanding when and why they refuse to engage can reveal insights into both their capabilities and limitations.
Our analysis across multiple leading models and prompt categories shows distinct variations in refusal behavior, with implications for model selection and application design.
_Update (November 5, 2024)_ – We've now expanded our analysis to include several leading open-source models, revealing promising options for developers seeking less censored and more reliable model interactions.
_For an in-depth overview of our evaluation methods and insights, please see our [analysis post]({MANDOLINE_URL}/blog/comparing-llm-refusal-behavior)._
## Leaderboards"""
)
# Data Heatmaps
for df, title in [
(df_refusal, "Refusal Rates"),
(df_refusal_hedge, "Refusal & Hedge Rates"),
]:
df = df.iloc[::-1]
df_heatmap = df.melt(
id_vars=["Model"],
value_vars=categories,
var_name="Prompt Category",
value_name="%",
)
fig = px.density_heatmap(
df_heatmap, x="Prompt Category", y="Model", z="%", color_continuous_scale="reds"
)
# Add value annotations to cells
annotations = []
for _, row in df_heatmap.iterrows():
annotations.append(
dict(
y=row["Model"],
x=row["Prompt Category"],
text=f"{row['%']:.1f}%",
showarrow=False,
font=dict(color="black" if row["%"] < 20 else "white"),
)
)
fig.update_layout(
xaxis_tickangle=-45,
height=HEATMAP_HEIGHT,
width=HEATMAP_WIDTH,
coloraxis_colorbar_title="%",
annotations=annotations,
)
st.markdown(f"### {title}")
st.plotly_chart(fig, use_container_width=True)
st.markdown(
f"""## Understanding Language Model Refusals
Language models decline to engage with prompts in two primary ways:
- **Direct refusals**: Explicit statements like "I cannot help with that request."
- **Hedged responses**: Indirect avoidance through statements like "I cannot provide specific advice, but..."
Refusal patterns matter because they highlight model limitations and areas for improvement, impact user experience by affecting conversation flow, trust, and task completion rates, and help developers select models with appropriate engagement levels.
### Key Findings
Our comparative analysis reveals several notable patterns:
- **Open-source models exhibit minimal refusals**: The newly evaluated open-source models show near-zero refusal rates across all categories.
- **Closed-source models vary significantly**: Proprietary models such as the Claude 3.5 Sonnet variants and o1 series demonstrate higher refusal rates, particularly in self-reflection tasks.
- **Variability in hedging behavior**: When considering both refusals and hedged responses, proprietary models are still more prone to provide hedged answers.
- **Opportunities with Open-Source LLMs**: Developers seeking greater control over model outputs and behaviors may find open-source LLMs to be more adaptable to their needs.
For detailed analysis and discussion of these patterns, visit the results section of our [analysis post]({MANDOLINE_URL}/blog/comparing-llm-refusal-behavior#results).
## Evaluation Methodology
To ensure comprehensive and reliable results, our assessment framework included:
- Standardized testing conditions across all models.
- A private test set of 400 diverse prompts across eight reasoning categories.
- A [custom evaluation metric]({MANDOLINE_URL}/docs/mandoline-core-concepts#metrics) that captures refusals, hedges, and earnest compliance.
- Detailed analysis of both explicit refusals and hedged responses.
For complete methodological details, visit the methods section of our [analysis post]({MANDOLINE_URL}/blog/comparing-llm-refusal-behavior#methods).
## Future Developments
This analysis is part of our ongoing exploration into model refusal patterns, utilizing custom refusal evaluations that measure both direct refusals and hedged responses.
We will continue to update our findings as new models emerge and existing ones evolve, tracking how refusal behaviors shift across model generations and training approaches.
Subscribe to our [newsletter](https://mandolineai.substack.com) to stay informed about the latest developments in LLM evaluations and to receive updates on new leaderboard rankings."""
)
st.divider()
st.write("_First Published: October 30, 2024_")
st.write("_Last updated: November 5, 2024_")