File size: 16,116 Bytes
32e8dbc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
import pandas as pd
import os
# PII Detection Categories
PII_CATEGORIES = {
"Overall": ["Overall Accuracy"],
"Entity Types": ["Names", "Addresses", "Phone Numbers", "SSN", "Medical IDs", "Financial Info"],
"Document Types": ["Healthcare", "Financial", "Government", "Legal", "Personal"],
"Performance": ["Precision", "Recall", "F1 Score"],
"Efficiency": ["Processing Time", "Cost per Document"]
}
# Model type definitions
MODEL_TYPES = {
"Proprietary": "๐",
"Open Source": "๐"
}
def load_data():
"""Load and preprocess the PII detection evaluation data from CSV file."""
# Load from CSV file
csv_path = "results/pii_detection_results.csv"
if not os.path.exists(csv_path):
raise FileNotFoundError(f"Results file not found: {csv_path}. Please ensure the CSV file exists in the results folder.")
df = pd.read_csv(csv_path)
# Clean and prepare data
df = df.fillna('')
# Round numeric columns for better display
numeric_cols = [
'Overall Accuracy', 'Precision', 'Recall', 'F1 Score', 'Over-redaction Rate',
'Processing Time (s)', 'Cost per Document ($)',
'Healthcare Accuracy', 'Financial Accuracy', 'Government Accuracy',
'Legal Accuracy', 'Personal Accuracy'
]
for col in numeric_cols:
if col in df.columns:
df[col] = pd.to_numeric(df[col], errors='coerce').round(3)
return df
# Color palette matching DocumentProcessing style
COLORS = {
# Light mode colors
"white": "#FFFFFF",
"disc_pink": "#DE9DCC",
"code_coral": "#F25E45",
"data_green": "#6EB579",
"digital_pollen": "#F0C968",
"warm_black": "#1A1414",
"off_white": "#EFEBE7",
"pixel_mist": "#E2DBD9",
"soft_grey": "#C2B8AE",
"warm_grey": "#67594B",
# Dark mode colors
"disc_pink_dm": "#4F2B45",
"code_coral_dm": "#672D23",
"data_green_dm": "#2B412F",
"digital_pollen_dm": "#5B481A",
}
# Header content with PII detection focus
HEADER_CONTENT = f"""
<style>
/* Import fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
/* Root variables with custom color palette */
:root {{
--bg-primary: #1A1414;
--bg-secondary: rgba(239, 235, 231, 0.03);
--bg-card: rgba(239, 235, 231, 0.02);
--border-subtle: rgba(239, 235, 231, 0.08);
--border-default: rgba(239, 235, 231, 0.12);
--border-strong: rgba(239, 235, 231, 0.2);
--text-primary: #EFEBE7;
--text-secondary: #C2B8AE;
--text-muted: #67594B;
--accent-primary: #DE9DCC;
--accent-secondary: #F25E45;
--accent-tertiary: #6EB579;
--accent-quaternary: #F0C968;
--glow-primary: rgba(222, 157, 204, 0.4);
--glow-secondary: rgba(242, 94, 69, 0.4);
--glow-tertiary: rgba(110, 181, 121, 0.4);
}}
/* Global font and background */
.gradio-container {{
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
background: var(--bg-primary) !important;
color: var(--text-primary) !important;
}}
/* Headers and text */
h1, h2, h3, h4 {{
color: var(--text-primary) !important;
font-weight: 700 !important;
font-family: 'Inter', sans-serif !important;
}}
p, span, div {{
color: var(--text-primary) !important;
font-family: 'Inter', sans-serif !important;
}}
/* Dark containers */
.dark-container {{
background: var(--bg-card);
border: 1px solid var(--border-subtle);
border-radius: 20px;
padding: 28px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
backdrop-filter: blur(10px);
position: relative;
overflow: hidden;
}}
/* Section headers */
.section-header {{
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 24px;
}}
.section-icon {{
filter: drop-shadow(0 0 12px currentColor);
transition: all 0.3s ease;
}}
/* Enhanced table styling */
.v2-table-container {{
background: var(--bg-card);
border-radius: 16px;
overflow: hidden;
border: 1px solid var(--border-subtle);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(10px);
}}
.v2-styled-table {{
width: 100%;
border-collapse: collapse;
font-family: 'Inter', sans-serif;
font-size: 14px;
}}
.v2-styled-table thead {{
background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
}}
.v2-styled-table th {{
padding: 16px 12px;
text-align: left;
color: white;
font-weight: 600;
font-size: 13px;
text-transform: uppercase;
letter-spacing: 0.05em;
border: none;
position: relative;
}}
.v2-styled-table td {{
padding: 14px 12px;
border-bottom: 1px solid var(--border-subtle);
color: var(--text-primary);
transition: all 0.2s ease;
vertical-align: middle;
}}
.v2-styled-table tbody tr {{
transition: all 0.3s ease;
background: var(--bg-secondary);
}}
.v2-styled-table tbody tr:nth-child(even) {{
background: var(--bg-card);
}}
.v2-styled-table tbody tr:hover {{
background: rgba(222, 157, 204, 0.1);
box-shadow: 0 0 20px var(--glow-primary);
transform: scale(1.01);
}}
.model-name {{
font-weight: 600;
color: var(--accent-primary);
transition: all 0.2s ease;
}}
.numeric-cell {{
text-align: center;
font-family: 'SF Mono', monospace;
font-weight: 500;
}}
.score-cell {{
padding: 8px 12px;
}}
/* Scrollbar styling */
::-webkit-scrollbar {{
width: 8px;
height: 8px;
}}
::-webkit-scrollbar-track {{
background: var(--bg-secondary);
border-radius: 4px;
}}
::-webkit-scrollbar-thumb {{
background: var(--accent-secondary);
border-radius: 4px;
}}
::-webkit-scrollbar-thumb:hover {{
background: var(--accent-primary);
}}
</style>
<div style="
background: var(--bg-primary);
padding: 4rem 2rem;
border-radius: 16px;
margin-bottom: 0;
transition: all 0.3s ease;
position: relative;
">
<div style="max-width: 72rem; margin: 0 auto;">
<div style="text-align: center; margin-bottom: 4rem;">
<h1 style="
font-size: 4rem;
font-weight: 800;
line-height: 1.1;
background: linear-gradient(45deg, var(--accent-primary), var(--accent-secondary));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
margin-bottom: 0.5rem;
">
๐ LLM PII Detection Leaderboard
</h1>
<p style="
color: var(--text-secondary);
font-size: 1.25rem;
line-height: 1.75;
max-width: 800px;
margin: 0 auto;
text-align: center;
">
Comprehensive benchmark for language models' performance in detecting and redacting
personally identifiable information (PII) across various document types and scenarios.
<span style="
background: linear-gradient(to right, var(--accent-tertiary), var(--accent-quaternary));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
display: block;
margin-top: 1rem;
font-size: 1.5rem;
font-weight: 500;
">
"How well do LLMs protect sensitive information?"
</span>
</p>
</div>
<div style="
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1.5rem;
margin-top: 4rem;
">
<div style="
background: var(--bg-secondary);
border: 1px solid var(--border-subtle);
border-radius: 1rem;
padding: 2rem;
transition: all 0.3s ease;
text-align: center;
">
<div style="
font-size: 4rem;
font-weight: 800;
margin-bottom: 1rem;
background: linear-gradient(45deg, var(--accent-primary), var(--accent-secondary));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
">8</div>
<div style="color: var(--text-secondary); font-size: 1.5rem; margin-bottom: 1.5rem;">
Language Models
</div>
<div style="font-size: 1.125rem; line-height: 1.75; color: var(--text-primary);">
Leading proprietary & open source
</div>
<div style="color: var(--text-secondary); margin-top: 0.5rem;">
GPT-4o, Claude, Gemini, LLaMA, Mistral
</div>
</div>
<div style="
background: var(--bg-secondary);
border: 1px solid var(--border-subtle);
border-radius: 1rem;
padding: 2rem;
transition: all 0.3s ease;
text-align: center;
">
<div style="
font-size: 4rem;
font-weight: 800;
margin-bottom: 1rem;
background: linear-gradient(45deg, var(--accent-tertiary), var(--accent-quaternary));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
">5</div>
<div style="color: var(--text-secondary); font-size: 1.5rem; margin-bottom: 1.5rem;">
Document Types
</div>
<div style="font-size: 1.125rem; line-height: 1.75; color: var(--text-primary);">
Real-world scenarios
</div>
<div style="color: var(--text-secondary); margin-top: 0.5rem;">
Healthcare, Financial, Government, Legal, Personal
</div>
</div>
<div style="
background: var(--bg-secondary);
border: 1px solid var(--border-subtle);
border-radius: 1rem;
padding: 2rem;
transition: all 0.3s ease;
text-align: center;
">
<div style="
font-size: 4rem;
font-weight: 800;
margin-bottom: 1rem;
background: linear-gradient(45deg, var(--accent-secondary), var(--accent-primary));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
">94.1%</div>
<div style="color: var(--text-secondary); font-size: 1.5rem; margin-bottom: 1.5rem;">
Best Accuracy
</div>
<div style="font-size: 1.125rem; line-height: 1.75; color: var(--text-primary);">
State-of-the-art performance
</div>
<div style="color: var(--text-secondary); margin-top: 0.5rem;">
GPT-4o leading precision & recall
</div>
</div>
</div>
</div>
</div>
"""
# Methodology section adapted for PII detection
METHODOLOGY = """
<div style="max-width: 1200px; margin: 0 auto; padding: 2rem; color: var(--text-secondary); line-height: 1.7; font-size: 1rem;">
<h1 style="font-size: 2.5rem; font-weight: 700; margin: 3rem 0 1.5rem; color: var(--text-primary);
background: linear-gradient(to right, var(--accent-primary), var(--accent-secondary));
-webkit-background-clip: text; -webkit-text-fill-color: transparent;">
Methodology
</h1>
<p>Our evaluation methodology assesses language models' capabilities in detecting and handling personally identifiable information (PII) across realistic document scenarios. Each model is tested on synthetic documents containing embedded PII entities across 5 document categories.</p>
<h2 style="font-size: 1.75rem; font-weight: 600; margin: 2rem 0 1rem; color: var(--text-primary);">
Evaluation Process
</h2>
<ul style="list-style: none; padding: 0; margin: 1rem 0;">
<li style="padding-left: 2rem; position: relative; margin: 1rem 0; display: flex; align-items: flex-start;">
<span style="content: ''; position: absolute; left: 0; top: 0.75rem; width: 8px; height: 8px;
background: var(--accent-primary); border-radius: 50%;
box-shadow: 0 0 0 2px rgba(222, 157, 204, 0.2);"></span>
<span style="color: var(--accent-primary); font-weight: 600;">Model Selection:</span>
We evaluate leading language models across proprietary and open-source categories
</li>
<li style="padding-left: 2rem; position: relative; margin: 1rem 0; display: flex; align-items: flex-start;">
<span style="content: ''; position: absolute; left: 0; top: 0.75rem; width: 8px; height: 8px;
background: var(--accent-primary); border-radius: 50%;
box-shadow: 0 0 0 2px rgba(222, 157, 204, 0.2);"></span>
<span style="color: var(--accent-primary); font-weight: 600;">PII Detection:</span>
Each model processes documents with instructions to identify and classify PII entities
</li>
<li style="padding-left: 2rem; position: relative; margin: 1rem 0; display: flex; align-items: flex-start;">
<span style="content: ''; position: absolute; left: 0; top: 0.75rem; width: 8px; height: 8px;
background: var(--accent-primary); border-radius: 50%;
box-shadow: 0 0 0 2px rgba(222, 157, 204, 0.2);"></span>
<span style="color: var(--accent-primary); font-weight: 600;">Performance Metrics:</span>
Precision, Recall, F1 Score, Over-detection Rate, Processing Time, and Cost
</li>
<li style="padding-left: 2rem; position: relative; margin: 1rem 0; display: flex; align-items: flex-start;">
<span style="content: ''; position: absolute; left: 0; top: 0.75rem; width: 8px; height: 8px;
background: var(--accent-primary); border-radius: 50%;
box-shadow: 0 0 0 2px rgba(222, 157, 204, 0.2);"></span>
<span style="color: var(--accent-primary); font-weight: 600;">Domain Analysis:</span>
Specialized evaluation across Healthcare, Financial, Government, Legal, and Personal documents
</li>
</ul>
<h2 style="font-size: 1.75rem; font-weight: 600; margin: 2rem 0 1rem; color: var(--text-primary);">
Key Metrics Explained
</h2>
<div style="background: var(--bg-secondary); border: 1px solid var(--border-subtle); border-radius: 12px; padding: 1.5rem; margin: 1.5rem 0;">
<ul style="list-style: none; padding: 0; margin: 0;">
<li style="margin: 1rem 0;"><span style="color: var(--accent-tertiary); font-weight: 600;">Overall Accuracy:</span> Percentage of correctly identified and classified PII entities</li>
<li style="margin: 1rem 0;"><span style="color: var(--accent-tertiary); font-weight: 600;">Precision:</span> Of all flagged items, how many were actually PII (avoiding false positives)</li>
<li style="margin: 1rem 0;"><span style="color: var(--accent-tertiary); font-weight: 600;">Recall:</span> Of all PII present, how many were successfully detected (avoiding false negatives)</li>
<li style="margin: 1rem 0;"><span style="color: var(--accent-tertiary); font-weight: 600;">F1 Score:</span> Harmonic mean balancing precision and recall</li>
<li style="margin: 1rem 0;"><span style="color: var(--accent-secondary); font-weight: 600;">Over-detection Rate:</span> Percentage of non-PII incorrectly flagged (lower is better)</li>
</ul>
</div>
</div>
""" |