Spaces:
Runtime error
Runtime error
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247import pandas as pdimport plotly.express as pximport streamlit as st
# Prepare data
refusal_data = { "GPT-4o": { "Overall": 0.0, "Adaptive Reasoning Under Uncertainty": 0.0, "Analogical Reasoning and Transfer": 0.0, "Multi-Step Problem Decomposition": 0.0, "Temporal Reasoning and Sequencing": 0.0, "Bias and Fallacy Recognition": 0.0, "Cognitive Diversity Simulation": 0.0, "Recursive Improvement Analysis": 0.0, "Self-Reflection and Awareness": 0.0, }, "o1-mini": { "Overall": 5.75, "Adaptive Reasoning Under Uncertainty": 2.0, "Analogical Reasoning and Transfer": 0.0, "Multi-Step Problem Decomposition": 8.0, "Temporal Reasoning and Sequencing": 2.0, "Bias and Fallacy Recognition": 0.0, "Cognitive Diversity Simulation": 4.0, "Recursive Improvement Analysis": 20.0, "Self-Reflection and Awareness": 10.0, }, "o1-preview": { "Overall": 6.5, "Adaptive Reasoning Under Uncertainty": 4.0, "Analogical Reasoning and Transfer": 0.0, "Multi-Step Problem Decomposition": 8.0, "Temporal Reasoning and Sequencing": 2.0, "Bias and Fallacy Recognition": 0.0, "Cognitive Diversity Simulation": 6.0, "Recursive Improvement Analysis": 22.0, "Self-Reflection and Awareness": 10.0, }, "Claude 3.5 Sonnet": { "Overall": 9.5, "Adaptive Reasoning Under Uncertainty": 4.0, "Analogical Reasoning and Transfer": 4.0, "Multi-Step Problem Decomposition": 6.0, "Temporal Reasoning and Sequencing": 0.0, "Bias and Fallacy Recognition": 2.0, "Cognitive Diversity Simulation": 8.0, "Recursive Improvement Analysis": 36.0, "Self-Reflection and Awareness": 16.0, }, "Claude 3.5 Sonnet (new)": { "Overall": 2.75, "Adaptive Reasoning Under Uncertainty": 2.0, "Analogical Reasoning and Transfer": 0.0, "Multi-Step Problem Decomposition": 4.0, "Temporal Reasoning and Sequencing": 0.0, "Bias and Fallacy Recognition": 0.0, "Cognitive Diversity Simulation": 6.0, "Recursive Improvement Analysis": 8.0, "Self-Reflection and Awareness": 2.0, },}
refusal_hedge_data = { "GPT-4o": { "Overall": 0.75, "Adaptive Reasoning Under Uncertainty": 0.0, "Analogical Reasoning and Transfer": 0.0, "Multi-Step Problem Decomposition": 2.0, "Temporal Reasoning and Sequencing": 0.0, "Bias and Fallacy Recognition": 0.0, "Cognitive Diversity Simulation": 0.0, "Recursive Improvement Analysis": 4.0, "Self-Reflection and Awareness": 0.0, }, "o1-mini": { "Overall": 6.0, "Adaptive Reasoning Under Uncertainty": 2.0, "Analogical Reasoning and Transfer": 0.0, "Multi-Step Problem Decomposition": 8.0, "Temporal Reasoning and Sequencing": 2.0, "Bias and Fallacy Recognition": 0.0, "Cognitive Diversity Simulation": 4.0, "Recursive Improvement Analysis": 22.0, "Self-Reflection and Awareness": 10.0, }, "o1-preview": { "Overall": 6.5, "Adaptive Reasoning Under Uncertainty": 4.0, "Analogical Reasoning and Transfer": 0.0, "Multi-Step Problem Decomposition": 8.0, "Temporal Reasoning and Sequencing": 2.0, "Bias and Fallacy Recognition": 0.0, "Cognitive Diversity Simulation": 6.0, "Recursive Improvement Analysis": 22.0, "Self-Reflection and Awareness": 10.0, }, "Claude 3.5 Sonnet": { "Overall": 12.5, "Adaptive Reasoning Under Uncertainty": 4.0, "Analogical Reasoning and Transfer": 4.0, "Multi-Step Problem Decomposition": 6.0, "Temporal Reasoning and Sequencing": 0.0, "Bias and Fallacy Recognition": 2.0, "Cognitive Diversity Simulation": 8.0, "Recursive Improvement Analysis": 48.0, "Self-Reflection and Awareness": 28.0, }, "Claude 3.5 Sonnet (new)": { "Overall": 11.25, "Adaptive Reasoning Under Uncertainty": 6.0, "Analogical Reasoning and Transfer": 6.0, "Multi-Step Problem Decomposition": 6.0, "Temporal Reasoning and Sequencing": 4.0, "Bias and Fallacy Recognition": 2.0, "Cognitive Diversity Simulation": 8.0, "Recursive Improvement Analysis": 24.0, "Self-Reflection and Awareness": 34.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
TITLE = "Refusal Rate Leaderboard"
HEATMAP_HEIGHT = 600HEATMAP_WIDTH = 800
st.set_page_config(page_title=TITLE, layout="wide")
## Core
st.title(TITLE)st.write( "Leaderboard of refusal rates across the GPT-4o, o1-mini, o1-preview, and Claude 3.5 Sonnet language models.")st.divider()
st.markdown( """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.
_For an in-depth overview of our evaluation methods and insights, please see our [analysis post](/blog/comparing-llm-refusal-behavior)._
## Leaderboards""")
# Data Heatmaps
for df, title in [ (df_refusal, "Refusal Rates"), (df_refusal_hedge, "Refusal & Hedge Rates"),]: df_heatmap = df.melt( id_vars=["Model"], value_vars=categories, var_name="Prompt Category", value_name="%", )
fig = px.density_heatmap( df_heatmap, y="Prompt Category", x="Model", z="%", color_continuous_scale="reds" )
# Add value annotations to cells annotations = [] for _, row in df_heatmap.iterrows(): annotations.append( dict( x=row["Model"], y=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( """## Understanding Refusals
Language models decline to engage with prompts in two primary ways:
- Direct refusals: Explicit statements like "I cannot help with that request," and- Hedged responses: Indirect avoidance through statements like "I cannot provide specific advice, but..."
These refusal patterns matter because they directly impact:
- Research: Provides insights into model limitations and areas for improvement,- Application Development: Helps developers select models with appropriate engagement levels, and- User Experience: Affects how effectively AI systems can meet user needs
### Key Findings
Our comparative analysis reveals several notable patterns:
- Self-reflection tasks consistently generate 2-3x higher refusal rates,- GPT-4o shows minimal refusals across categories, and- Models demonstrate varying levels of caution in different reasoning domains
For detailed analysis and discussion of these patterns, visit the results section of our [analysis post](/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](/docs/mandoline-core-concepts#metrics) that captures refusals, hedges, and earnest compliance, and- Detailed analysis of both explicit refusals and hedged responses
For complete methodological details, visit the methods section of our [analysis post](/blog/comparing-llm-refusal-behavior#methods).
## Future Developments
This analysis represents an initial exploration into model refusal patterns. We maintain regular updates 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.""")
st.divider()st.write("_Last updated: October 30, 2024_")app.pyAdded+247