Rank results by recall minus false alerts and rescale charts
#29
by jfbrown95 - opened
- README.md +53 -55
- assets/bug-tradeoff.svg +0 -0
- assets/lint-tradeoff.svg +7 -14
- assets/security-tradeoff.svg +0 -0
- tradeoff.py +47 -55
README.md
CHANGED
|
@@ -26,11 +26,9 @@ Pairs come from open-source projects in Rust, JavaScript, TypeScript, Python, Go
|
|
| 26 |
|
| 27 |
## Reading the results
|
| 28 |
|
| 29 |
-
Each
|
| 30 |
|
| 31 |
-
The
|
| 32 |
-
|
| 33 |
-
Private method predictions stay private, so the curves use public predictions only. The lint public split has 214 clean methods: its 5% limit permits at most 10 false alerts. The bug and security limits permit 128 and 74 false alerts respectively.
|
| 34 |
|
| 35 |
## Bugs
|
| 36 |
|
|
@@ -40,27 +38,27 @@ Private method predictions stay private, so the curves use public predictions on
|
|
| 40 |
|
| 41 |
### Public — 2,220 pairs
|
| 42 |
|
| 43 |
-
| Model | Recall
|
| 44 |
-
| --- | ---: | ---: | ---: | ---: |
|
| 45 |
-
| [DiffusionGemma Jev](https://github.com/razorback16/openjev) |
|
| 46 |
-
| [Jev](https://typesafe.ai/blog/introducing-system-one-models-and-jev) |
|
| 47 |
-
| [
|
| 48 |
-
| [
|
| 49 |
-
| [
|
| 50 |
-
| [
|
| 51 |
-
| [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) |
|
| 52 |
|
| 53 |
### Private — 498 pairs
|
| 54 |
|
| 55 |
-
| Model | Recall
|
| 56 |
| --- | ---: | ---: | ---: | ---: |
|
| 57 |
-
| [DiffusionGemma Jev](https://github.com/razorback16/openjev) | 35.8% |
|
| 58 |
-
| [TypeLLM](https://typellm.ai/docs) | 11.3% |
|
| 59 |
-
| [Jev](https://typesafe.ai/blog/introducing-system-one-models-and-jev) | 20.0% |
|
| 60 |
-
| [Span-01](https://www.respan.ai/docs/documentation/span-01/concept) | 28.5% |
|
| 61 |
-
| [SemiF](https://github.com/TheoLeeCJ/SemIf) | 44.3% |
|
| 62 |
-
| [Liquid d1](https://docs.liquid.ai/lfm/models/decision-models) | 5.2% |
|
| 63 |
-
| [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) | 79.5% |
|
| 64 |
|
| 65 |
## Security
|
| 66 |
|
|
@@ -70,27 +68,27 @@ Private method predictions stay private, so the curves use public predictions on
|
|
| 70 |
|
| 71 |
### Public — 1,311 pairs
|
| 72 |
|
| 73 |
-
| Model | Recall
|
| 74 |
-
| --- | ---: | ---: | ---: | ---: |
|
| 75 |
-
| [
|
| 76 |
-
| [
|
| 77 |
-
| [
|
| 78 |
-
| [
|
| 79 |
-
| [
|
| 80 |
-
| [SemiF](https://github.com/TheoLeeCJ/SemIf) |
|
| 81 |
-
| [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) |
|
| 82 |
|
| 83 |
### Private — 439 pairs
|
| 84 |
|
| 85 |
-
| Model | Recall
|
| 86 |
| --- | ---: | ---: | ---: | ---: |
|
| 87 |
-
| [Liquid d1](https://docs.liquid.ai/lfm/models/decision-models) | 34.2% |
|
| 88 |
-
| [Jev](https://typesafe.ai/blog/introducing-system-one-models-and-jev) | 20.6% |
|
| 89 |
-
| [DiffusionGemma Jev](https://github.com/razorback16/openjev) | 21.9% |
|
| 90 |
-
| [TypeLLM](https://typellm.ai/docs) | 8.8% |
|
| 91 |
-
| [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) | 100.0% |
|
| 92 |
-
| [SemiF](https://github.com/TheoLeeCJ/SemIf) | 100.0% |
|
| 93 |
-
| [Span-01](https://www.respan.ai/docs/documentation/span-01/concept) | 8.0% |
|
| 94 |
|
| 95 |
## Perch Lint Bench
|
| 96 |
|
|
@@ -100,27 +98,27 @@ Private method predictions stay private, so the curves use public predictions on
|
|
| 100 |
|
| 101 |
### Public — 214 pairs
|
| 102 |
|
| 103 |
-
| Model | Recall
|
| 104 |
-
| --- | ---: | ---: | ---: | ---: |
|
| 105 |
-
| [
|
| 106 |
-
| [
|
| 107 |
-
| [Liquid d1](https://docs.liquid.ai/lfm/models/decision-models) |
|
| 108 |
-
| [DiffusionGemma Jev](https://github.com/razorback16/openjev) |
|
| 109 |
-
| [Span-01](https://www.respan.ai/docs/documentation/span-01/concept) |
|
| 110 |
-
| [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) |
|
| 111 |
-
| [SemiF](https://github.com/TheoLeeCJ/SemIf) |
|
| 112 |
|
| 113 |
### Private — 71 pairs
|
| 114 |
|
| 115 |
-
| Model | Recall
|
| 116 |
| --- | ---: | ---: | ---: | ---: |
|
| 117 |
-
| [TypeLLM](https://typellm.ai/docs) | 59.2% |
|
| 118 |
-
| [Jev](https://typesafe.ai/blog/introducing-system-one-models-and-jev) | 53.5% |
|
| 119 |
-
| [Liquid d1](https://docs.liquid.ai/lfm/models/decision-models) | 49.3% |
|
| 120 |
-
| [DiffusionGemma Jev](https://github.com/razorback16/openjev) | 53.5% |
|
| 121 |
-
| [Span-01](https://www.respan.ai/docs/documentation/span-01/concept) | 45.1% |
|
| 122 |
-
| [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) | 50.7% |
|
| 123 |
-
| [SemiF](https://github.com/TheoLeeCJ/SemIf) | 42.3% |
|
| 124 |
|
| 125 |
<!-- END TRADEOFF_RESULTS -->
|
| 126 |
|
|
|
|
| 26 |
|
| 27 |
## Reading the results
|
| 28 |
|
| 29 |
+
Each line shows how many issues a model finds and what percentage of clean methods it wrongly flags as its score cutoff changes. Higher and farther left is better.
|
| 30 |
|
| 31 |
+
The tables use each run's recorded alert settings. A value of 20% under ‘Clean methods wrongly flagged’ means one in five clean methods received an alert. Models are ranked by recall minus that percentage. Bold marks the best displayed value in each column; cost compares priced runs captured here.
|
|
|
|
|
|
|
| 32 |
|
| 33 |
## Bugs
|
| 34 |
|
|
|
|
| 38 |
|
| 39 |
### Public — 2,220 pairs
|
| 40 |
|
| 41 |
+
| Model | Recall | Clean methods wrongly flagged | Recall − false-positive rate | Inference cost |
|
| 42 |
+
| --- | ---: | ---: | ---: | ---: |
|
| 43 |
+
| [DiffusionGemma Jev](https://github.com/razorback16/openjev) | 33.4% | 27.1% | **6.3%** | $0.239 |
|
| 44 |
+
| [Jev](https://typesafe.ai/blog/introducing-system-one-models-and-jev) | 17.7% | 12.7% | 5.0% | $0.551 |
|
| 45 |
+
| [SemiF](https://github.com/TheoLeeCJ/SemIf) | 43.0% | 39.7% | 3.3% | $0.239 |
|
| 46 |
+
| [TypeLLM](https://typellm.ai/docs) | 8.3% | 5.5% | 2.7% | $0.576 |
|
| 47 |
+
| [Span-01](https://www.respan.ai/docs/documentation/span-01/concept) | 25.3% | 22.6% | 2.7% | **$0.182** |
|
| 48 |
+
| [Liquid d1](https://docs.liquid.ai/lfm/models/decision-models) | 4.1% | **2.5%** | 1.6% | Free tier |
|
| 49 |
+
| [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) | **81.9%** | 80.9% | 1.0% | ~$0.210 |
|
| 50 |
|
| 51 |
### Private — 498 pairs
|
| 52 |
|
| 53 |
+
| Model | Recall | Clean methods wrongly flagged | Recall − false-positive rate | Inference cost |
|
| 54 |
| --- | ---: | ---: | ---: | ---: |
|
| 55 |
+
| [DiffusionGemma Jev](https://github.com/razorback16/openjev) | 35.8% | 27.3% | **8.6%** | $0.054 |
|
| 56 |
+
| [TypeLLM](https://typellm.ai/docs) | 11.3% | 5.8% | 5.6% | $0.129 |
|
| 57 |
+
| [Jev](https://typesafe.ai/blog/introducing-system-one-models-and-jev) | 20.0% | 15.6% | 4.5% | $0.123 |
|
| 58 |
+
| [Span-01](https://www.respan.ai/docs/documentation/span-01/concept) | 28.5% | 24.3% | 4.2% | **$0.040** |
|
| 59 |
+
| [SemiF](https://github.com/TheoLeeCJ/SemIf) | 44.3% | 41.8% | 2.6% | $0.054 |
|
| 60 |
+
| [Liquid d1](https://docs.liquid.ai/lfm/models/decision-models) | 5.2% | **3.0%** | 2.2% | Free tier |
|
| 61 |
+
| [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) | **79.5%** | 80.1% | -0.6% | ~$0.047 |
|
| 62 |
|
| 63 |
## Security
|
| 64 |
|
|
|
|
| 68 |
|
| 69 |
### Public — 1,311 pairs
|
| 70 |
|
| 71 |
+
| Model | Recall | Clean methods wrongly flagged | Recall − false-positive rate | Inference cost |
|
| 72 |
+
| --- | ---: | ---: | ---: | ---: |
|
| 73 |
+
| [Jev](https://typesafe.ai/blog/introducing-system-one-models-and-jev) | 34.6% | 23.6% | **11.0%** | $0.507 |
|
| 74 |
+
| [TypeLLM](https://typellm.ai/docs) | 27.8% | 17.4% | 10.5% | $0.566 |
|
| 75 |
+
| [Liquid d1](https://docs.liquid.ai/lfm/models/decision-models) | 55.6% | 46.8% | 8.8% | Free tier |
|
| 76 |
+
| [DiffusionGemma Jev](https://github.com/razorback16/openjev) | 33.1% | 25.8% | 7.3% | **$0.208** |
|
| 77 |
+
| [Span-01](https://www.respan.ai/docs/documentation/span-01/concept) | 21.0% | **17.2%** | 3.9% | $0.251 |
|
| 78 |
+
| [SemiF](https://github.com/TheoLeeCJ/SemIf) | **100.0%** | 99.9% | 0.1% | **$0.208** |
|
| 79 |
+
| [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) | **100.0%** | 100.0% | 0.0% | ~$1.432 |
|
| 80 |
|
| 81 |
### Private — 439 pairs
|
| 82 |
|
| 83 |
+
| Model | Recall | Clean methods wrongly flagged | Recall − false-positive rate | Inference cost |
|
| 84 |
| --- | ---: | ---: | ---: | ---: |
|
| 85 |
+
| [Liquid d1](https://docs.liquid.ai/lfm/models/decision-models) | 34.2% | 29.0% | **5.2%** | Free tier |
|
| 86 |
+
| [Jev](https://typesafe.ai/blog/introducing-system-one-models-and-jev) | 20.6% | 16.7% | 3.9% | $0.182 |
|
| 87 |
+
| [DiffusionGemma Jev](https://github.com/razorback16/openjev) | 21.9% | 18.5% | 3.3% | **$0.074** |
|
| 88 |
+
| [TypeLLM](https://typellm.ai/docs) | 8.8% | **6.2%** | 2.5% | $0.203 |
|
| 89 |
+
| [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) | **100.0%** | 100.0% | 0.0% | ~$0.528 |
|
| 90 |
+
| [SemiF](https://github.com/TheoLeeCJ/SemIf) | **100.0%** | 100.0% | 0.0% | **$0.074** |
|
| 91 |
+
| [Span-01](https://www.respan.ai/docs/documentation/span-01/concept) | 8.0% | 8.1% | -0.1% | $0.091 |
|
| 92 |
|
| 93 |
## Perch Lint Bench
|
| 94 |
|
|
|
|
| 98 |
|
| 99 |
### Public — 214 pairs
|
| 100 |
|
| 101 |
+
| Model | Recall | Clean methods wrongly flagged | Recall − false-positive rate | Inference cost |
|
| 102 |
+
| --- | ---: | ---: | ---: | ---: |
|
| 103 |
+
| [TypeLLM](https://typellm.ai/docs) | **61.7%** | 2.8% | **58.9%** | $0.050 |
|
| 104 |
+
| [Jev](https://typesafe.ai/blog/introducing-system-one-models-and-jev) | 50.0% | **0.5%** | 49.5% | $0.048 |
|
| 105 |
+
| [Liquid d1](https://docs.liquid.ai/lfm/models/decision-models) | 49.1% | 0.9% | 48.1% | Free tier |
|
| 106 |
+
| [DiffusionGemma Jev](https://github.com/razorback16/openjev) | 52.8% | 5.1% | 47.7% | $0.018 |
|
| 107 |
+
| [Span-01](https://www.respan.ai/docs/documentation/span-01/concept) | 50.0% | 11.2% | 38.8% | $0.014 |
|
| 108 |
+
| [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) | 38.8% | 37.4% | 1.4% | **~$0.010** |
|
| 109 |
+
| [SemiF](https://github.com/TheoLeeCJ/SemIf) | 32.2% | 31.3% | 0.9% | $0.018 |
|
| 110 |
|
| 111 |
### Private — 71 pairs
|
| 112 |
|
| 113 |
+
| Model | Recall | Clean methods wrongly flagged | Recall − false-positive rate | Inference cost |
|
| 114 |
| --- | ---: | ---: | ---: | ---: |
|
| 115 |
+
| [TypeLLM](https://typellm.ai/docs) | **59.2%** | 5.6% | **53.5%** | $0.016 |
|
| 116 |
+
| [Jev](https://typesafe.ai/blog/introducing-system-one-models-and-jev) | 53.5% | **1.4%** | 52.1% | $0.016 |
|
| 117 |
+
| [Liquid d1](https://docs.liquid.ai/lfm/models/decision-models) | 49.3% | **1.4%** | 47.9% | Free tier |
|
| 118 |
+
| [DiffusionGemma Jev](https://github.com/razorback16/openjev) | 53.5% | 8.5% | 45.1% | $0.006 |
|
| 119 |
+
| [Span-01](https://www.respan.ai/docs/documentation/span-01/concept) | 45.1% | 8.5% | 36.6% | $0.005 |
|
| 120 |
+
| [CLM-v0.1-8B](https://huggingface.co/Contrastive-LM/CLM-v0.1-8B) | 50.7% | 49.3% | 1.4% | **~$0.003** |
|
| 121 |
+
| [SemiF](https://github.com/TheoLeeCJ/SemIf) | 42.3% | 45.1% | -2.8% | $0.006 |
|
| 122 |
|
| 123 |
<!-- END TRADEOFF_RESULTS -->
|
| 124 |
|
assets/bug-tradeoff.svg
CHANGED
|
|
|
|
assets/lint-tradeoff.svg
CHANGED
|
|
|
|
assets/security-tradeoff.svg
CHANGED
|
|
|
|
tradeoff.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
-
"""Rebuild public false-alert curves and benchmark result tables.
|
| 3 |
|
| 4 |
-
The public curves sweep
|
| 5 |
-
|
| 6 |
-
tables use only the aggregate results already published in results-current.jsonl.
|
| 7 |
"""
|
| 8 |
|
| 9 |
from __future__ import annotations
|
|
@@ -12,7 +11,7 @@ import argparse
|
|
| 12 |
from collections import defaultdict
|
| 13 |
import html
|
| 14 |
import json
|
| 15 |
-
from math import
|
| 16 |
from pathlib import Path
|
| 17 |
from tempfile import TemporaryDirectory
|
| 18 |
from urllib.request import urlopen
|
|
@@ -39,7 +38,6 @@ COLORS = {
|
|
| 39 |
"semif": "#b14b39",
|
| 40 |
}
|
| 41 |
ORDER = tuple(NAMES)
|
| 42 |
-
CAP = 0.05
|
| 43 |
|
| 44 |
|
| 45 |
def lines(path: Path) -> list[dict]:
|
|
@@ -94,18 +92,13 @@ def curve(labels: dict[tuple[str, str], int], prediction_path: Path) -> tuple[li
|
|
| 94 |
return points, sum(labels.values()), len(labels) - sum(labels.values())
|
| 95 |
|
| 96 |
|
| 97 |
-
def recall_at_cap(points: list[tuple[int, int]], positives: int, negatives: int) -> float:
|
| 98 |
-
limit = floor(CAP * negatives)
|
| 99 |
-
return max(tp for fp, tp in points if fp <= limit) / positives
|
| 100 |
-
|
| 101 |
-
|
| 102 |
def operating_metrics(row: dict) -> tuple[float, float, float]:
|
| 103 |
counts = row["confusion"]
|
| 104 |
positives = counts["tp"] + counts["fn"]
|
| 105 |
negatives = counts["fp"] + counts["tn"]
|
| 106 |
recall = counts["tp"] / positives
|
| 107 |
-
|
| 108 |
-
return recall,
|
| 109 |
|
| 110 |
|
| 111 |
def money(row: dict) -> str:
|
|
@@ -125,49 +118,54 @@ def percent(value: float) -> str:
|
|
| 125 |
return f"{100 * value:.1f}%"
|
| 126 |
|
| 127 |
|
| 128 |
-
def
|
| 129 |
-
ordered = sorted(rows, key=lambda row: (-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
for
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
return "\n".join(table)
|
| 137 |
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
|
| 140 |
-
ordered = sorted(rows, key=lambda row: (-operating_metrics(row)[2], ORDER.index(row["model_id"])))
|
| 141 |
-
table = ["| Model | Recall at current cutoff | False alerts / 1,000 clean at current cutoff | TPR − FPR at current cutoff | Inference cost |",
|
| 142 |
"| --- | ---: | ---: | ---: | ---: |"]
|
| 143 |
for row in ordered:
|
| 144 |
-
recall,
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
return "\n".join(table)
|
| 147 |
|
| 148 |
|
| 149 |
-
def svg(domain: str, curves: dict[str, tuple[list[tuple[int, int]], int, int]],
|
| 150 |
-
current: dict[str, dict], output: Path) -> None:
|
| 151 |
width, height = 1120, 580
|
| 152 |
left, right, top, bottom = 90, 40, 126, 82
|
| 153 |
plot_w, plot_h = width - left - right, height - top - bottom
|
| 154 |
-
# The chart concentrates on the
|
| 155 |
-
|
| 156 |
-
|
| 157 |
|
| 158 |
def x(fp: int, negatives: int) -> float:
|
| 159 |
-
return left + (fp / negatives *
|
| 160 |
|
| 161 |
def y(tp: int, positives: int) -> float:
|
| 162 |
-
return top + (1 - tp / positives) * plot_h
|
| 163 |
|
| 164 |
title = {"bug": "Bug detection", "security": "Security detection", "lint": "Perch Lint Bench"}[domain]
|
| 165 |
out = [f'<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}" viewBox="0 0 {width} {height}" role="img" aria-labelledby="title desc">',
|
| 166 |
f'<title id="title">{title}: recall versus false alerts</title>',
|
| 167 |
-
'<desc id="desc">Seven model score curves on the public benchmark. Higher and farther left is better.
|
| 168 |
f'<rect width="{width}" height="{height}" rx="16" fill="#101318"/>',
|
| 169 |
f'<text x="{left}" y="43" fill="#f2f5fa" font-family="Arial,sans-serif" font-weight="700" font-size="28">{html.escape(title)}</text>',
|
| 170 |
-
f'<text x="{left}" y="70" fill="#aeb9c7" font-family="Arial,sans-serif" font-size="16">Public methods ·
|
| 171 |
for i, model in enumerate(ORDER):
|
| 172 |
col = i % 4
|
| 173 |
row = i // 4
|
|
@@ -175,27 +173,23 @@ def svg(domain: str, curves: dict[str, tuple[list[tuple[int, int]], int, int]],
|
|
| 175 |
ly = 91 + row * 22
|
| 176 |
out += [f'<line x1="{lx}" y1="{ly}" x2="{lx + 24}" y2="{ly}" stroke="{COLORS[model]}" stroke-width="4"/>',
|
| 177 |
f'<text x="{lx + 32}" y="{ly + 5}" fill="#e1e7ef" font-family="Arial,sans-serif" font-size="15">{html.escape(NAMES[model][0])}</text>']
|
| 178 |
-
|
|
|
|
| 179 |
px = left + value / x_max * plot_w
|
| 180 |
out += [f'<line x1="{px:.1f}" y1="{top}" x2="{px:.1f}" y2="{top + plot_h}" stroke="#29303a"/>',
|
| 181 |
-
f'<text x="{px:.1f}" y="{top + plot_h + 25}" text-anchor="middle" fill="#aeb9c7" font-family="Arial,sans-serif" font-size="14">{value}</text>']
|
| 182 |
-
|
| 183 |
-
|
|
|
|
| 184 |
out += [f'<line x1="{left}" y1="{py:.1f}" x2="{left + plot_w}" y2="{py:.1f}" stroke="#29303a"/>',
|
| 185 |
f'<text x="{left - 12}" y="{py + 5:.1f}" text-anchor="end" fill="#aeb9c7" font-family="Arial,sans-serif" font-size="14">{value}%</text>']
|
| 186 |
-
cap_x = left + 50 / x_max * plot_w
|
| 187 |
-
out.append(f'<line x1="{cap_x:.1f}" y1="{top}" x2="{cap_x:.1f}" y2="{top + plot_h}" stroke="#ced8e4" stroke-width="1.5" stroke-dasharray="5 6"/>')
|
| 188 |
-
out.append(f'<text x="{cap_x + 6:.1f}" y="{top + 18}" fill="#ced8e4" font-family="Arial,sans-serif" font-size="13">5% false-alert limit</text>')
|
| 189 |
for model in ORDER:
|
| 190 |
points, positives, negatives = curves[model]
|
| 191 |
-
visible = [(fp, tp) for fp, tp in points if fp / negatives *
|
| 192 |
if len(visible) > 1:
|
| 193 |
positions = " ".join(f"{x(fp, negatives):.2f},{y(tp, positives):.2f}" for fp, tp in visible)
|
| 194 |
out.append(f'<polyline points="{positions}" fill="none" stroke="{COLORS[model]}" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round"/>')
|
| 195 |
-
|
| 196 |
-
if false_alerts <= x_max:
|
| 197 |
-
out.append(f'<circle cx="{left + false_alerts / x_max * plot_w:.2f}" cy="{top + (1 - recall) * plot_h:.2f}" r="5" fill="{COLORS[model]}" stroke="#fff" stroke-width="1.5"/>')
|
| 198 |
-
out += [f'<text x="{left + plot_w / 2:.1f}" y="{height - 23}" text-anchor="middle" fill="#e1e7ef" font-family="Arial,sans-serif" font-size="17">False alerts per 1,000 clean methods →</text>',
|
| 199 |
f'<text transform="translate(23 {top + plot_h / 2:.1f}) rotate(-90)" text-anchor="middle" fill="#e1e7ef" font-family="Arial,sans-serif" font-size="17">Actual issues found (recall) →</text>',
|
| 200 |
'</svg>']
|
| 201 |
output.parent.mkdir(parents=True, exist_ok=True)
|
|
@@ -204,9 +198,8 @@ def svg(domain: str, curves: dict[str, tuple[list[tuple[int, int]], int, int]],
|
|
| 204 |
|
| 205 |
def render_sections(results: list[dict], curves_by_domain: dict[str, dict], output_dir: Path) -> str:
|
| 206 |
sections = ["## Reading the results", "",
|
| 207 |
-
"Each
|
| 208 |
-
"The
|
| 209 |
-
"Private method predictions stay private, so the curves use public predictions only. The lint public split has 214 clean methods: its 5% limit permits at most 10 false alerts. The bug and security limits permit 128 and 74 false alerts respectively.", ""]
|
| 210 |
for domain in ("bug", "security", "lint"):
|
| 211 |
title = {"bug": "Bugs", "security": "Security", "lint": "Perch Lint Bench"}[domain]
|
| 212 |
link = {"bug": "bug-pairs-public", "security": "security-pairs-public", "lint": "perch-lint-bench-public"}[domain]
|
|
@@ -214,15 +207,14 @@ def render_sections(results: list[dict], curves_by_domain: dict[str, dict], outp
|
|
| 214 |
private = [r for r in results if r["domain"] == domain and r["track"] == "private"]
|
| 215 |
if set(r["model_id"] for r in public) != set(ORDER) or set(r["model_id"] for r in private) != set(ORDER):
|
| 216 |
raise ValueError(f"Unexpected models in {domain} results")
|
| 217 |
-
current = {r["model_id"]: r for r in public}
|
| 218 |
image = output_dir / f"{domain}-tradeoff.svg"
|
| 219 |
-
svg(domain, curves_by_domain[domain],
|
| 220 |
sections += [f"## {title}", "", f"[Public pairs](https://huggingface.co/datasets/perchscan/{link})", "",
|
| 221 |
f"", "",
|
| 222 |
f"### Public — {public[0]['benchmark_pairs']:,} pairs", "",
|
| 223 |
-
|
| 224 |
f"### Private — {private[0]['benchmark_pairs']:,} pairs", "",
|
| 225 |
-
|
| 226 |
return "\n".join(sections)
|
| 227 |
|
| 228 |
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
+
"""Rebuild public recall/false-alert curves and benchmark result tables.
|
| 3 |
|
| 4 |
+
The public curves sweep saved method scores. Tables use recorded scan alerts;
|
| 5 |
+
private tables use only aggregates in results-current.jsonl.
|
|
|
|
| 6 |
"""
|
| 7 |
|
| 8 |
from __future__ import annotations
|
|
|
|
| 11 |
from collections import defaultdict
|
| 12 |
import html
|
| 13 |
import json
|
| 14 |
+
from math import isfinite
|
| 15 |
from pathlib import Path
|
| 16 |
from tempfile import TemporaryDirectory
|
| 17 |
from urllib.request import urlopen
|
|
|
|
| 38 |
"semif": "#b14b39",
|
| 39 |
}
|
| 40 |
ORDER = tuple(NAMES)
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
def lines(path: Path) -> list[dict]:
|
|
|
|
| 92 |
return points, sum(labels.values()), len(labels) - sum(labels.values())
|
| 93 |
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
def operating_metrics(row: dict) -> tuple[float, float, float]:
|
| 96 |
counts = row["confusion"]
|
| 97 |
positives = counts["tp"] + counts["fn"]
|
| 98 |
negatives = counts["fp"] + counts["tn"]
|
| 99 |
recall = counts["tp"] / positives
|
| 100 |
+
false_positive_rate = counts["fp"] / negatives
|
| 101 |
+
return recall, false_positive_rate, recall - false_positive_rate
|
| 102 |
|
| 103 |
|
| 104 |
def money(row: dict) -> str:
|
|
|
|
| 118 |
return f"{100 * value:.1f}%"
|
| 119 |
|
| 120 |
|
| 121 |
+
def results_table(rows: list[dict]) -> str:
|
| 122 |
+
ordered = sorted(rows, key=lambda row: (-operating_metrics(row)[2], ORDER.index(row["model_id"])))
|
| 123 |
+
metrics = {row["model_id"]: operating_metrics(row) for row in ordered}
|
| 124 |
+
best_recall = max(round(value[0] * 100, 1) for value in metrics.values())
|
| 125 |
+
best_false_positive_rate = min(round(value[1] * 100, 1) for value in metrics.values())
|
| 126 |
+
best_net_recall = max(round(value[2] * 100, 1) for value in metrics.values())
|
| 127 |
+
priced_costs = [round(row["inference_cost_usd"], 3) for row in ordered if row.get("inference_cost_usd") is not None]
|
| 128 |
+
best_priced_cost = min(priced_costs) if priced_costs else None
|
|
|
|
| 129 |
|
| 130 |
+
def mark(value: str, winner: bool) -> str:
|
| 131 |
+
return f"**{value}**" if winner else value
|
| 132 |
|
| 133 |
+
table = ["| Model | Recall | Clean methods wrongly flagged | Recall − false-positive rate | Inference cost |",
|
|
|
|
|
|
|
| 134 |
"| --- | ---: | ---: | ---: | ---: |"]
|
| 135 |
for row in ordered:
|
| 136 |
+
recall, false_positive_rate, j = metrics[row["model_id"]]
|
| 137 |
+
cost = row.get("inference_cost_usd")
|
| 138 |
+
table.append("| " + " | ".join((
|
| 139 |
+
model_link(row["model_id"]),
|
| 140 |
+
mark(percent(recall), round(recall * 100, 1) == best_recall),
|
| 141 |
+
mark(percent(false_positive_rate), round(false_positive_rate * 100, 1) == best_false_positive_rate),
|
| 142 |
+
mark(percent(j), round(j * 100, 1) == best_net_recall),
|
| 143 |
+
mark(money(row), cost is not None and round(cost, 3) == best_priced_cost),
|
| 144 |
+
)) + " |")
|
| 145 |
return "\n".join(table)
|
| 146 |
|
| 147 |
|
| 148 |
+
def svg(domain: str, curves: dict[str, tuple[list[tuple[int, int]], int, int]], output: Path) -> None:
|
|
|
|
| 149 |
width, height = 1120, 580
|
| 150 |
left, right, top, bottom = 90, 40, 126, 82
|
| 151 |
plot_w, plot_h = width - left - right, height - top - bottom
|
| 152 |
+
# The chart concentrates on the lower false-positive-rate region.
|
| 153 |
+
x_max = 15 if domain == "lint" else 30
|
| 154 |
+
y_max = 1.0 if domain == "lint" else 0.5
|
| 155 |
|
| 156 |
def x(fp: int, negatives: int) -> float:
|
| 157 |
+
return left + (fp / negatives * 100) / x_max * plot_w
|
| 158 |
|
| 159 |
def y(tp: int, positives: int) -> float:
|
| 160 |
+
return top + (1 - (tp / positives) / y_max) * plot_h
|
| 161 |
|
| 162 |
title = {"bug": "Bug detection", "security": "Security detection", "lint": "Perch Lint Bench"}[domain]
|
| 163 |
out = [f'<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}" viewBox="0 0 {width} {height}" role="img" aria-labelledby="title desc">',
|
| 164 |
f'<title id="title">{title}: recall versus false alerts</title>',
|
| 165 |
+
'<desc id="desc">Seven model score curves on the public benchmark. Higher and farther left is better.</desc>',
|
| 166 |
f'<rect width="{width}" height="{height}" rx="16" fill="#101318"/>',
|
| 167 |
f'<text x="{left}" y="43" fill="#f2f5fa" font-family="Arial,sans-serif" font-weight="700" font-size="28">{html.escape(title)}</text>',
|
| 168 |
+
f'<text x="{left}" y="70" fill="#aeb9c7" font-family="Arial,sans-serif" font-size="16">Public methods · recall versus false alerts</text>']
|
| 169 |
for i, model in enumerate(ORDER):
|
| 170 |
col = i % 4
|
| 171 |
row = i // 4
|
|
|
|
| 173 |
ly = 91 + row * 22
|
| 174 |
out += [f'<line x1="{lx}" y1="{ly}" x2="{lx + 24}" y2="{ly}" stroke="{COLORS[model]}" stroke-width="4"/>',
|
| 175 |
f'<text x="{lx + 32}" y="{ly + 5}" fill="#e1e7ef" font-family="Arial,sans-serif" font-size="15">{html.escape(NAMES[model][0])}</text>']
|
| 176 |
+
x_step = 5
|
| 177 |
+
for value in range(0, x_max + 1, x_step):
|
| 178 |
px = left + value / x_max * plot_w
|
| 179 |
out += [f'<line x1="{px:.1f}" y1="{top}" x2="{px:.1f}" y2="{top + plot_h}" stroke="#29303a"/>',
|
| 180 |
+
f'<text x="{px:.1f}" y="{top + plot_h + 25}" text-anchor="middle" fill="#aeb9c7" font-family="Arial,sans-serif" font-size="14">{value}%</text>']
|
| 181 |
+
step = 20 if domain == "lint" else 10
|
| 182 |
+
for value in range(0, round(y_max * 100) + 1, step):
|
| 183 |
+
py = top + (1 - (value / 100) / y_max) * plot_h
|
| 184 |
out += [f'<line x1="{left}" y1="{py:.1f}" x2="{left + plot_w}" y2="{py:.1f}" stroke="#29303a"/>',
|
| 185 |
f'<text x="{left - 12}" y="{py + 5:.1f}" text-anchor="end" fill="#aeb9c7" font-family="Arial,sans-serif" font-size="14">{value}%</text>']
|
|
|
|
|
|
|
|
|
|
| 186 |
for model in ORDER:
|
| 187 |
points, positives, negatives = curves[model]
|
| 188 |
+
visible = [(fp, tp) for fp, tp in points if fp / negatives * 100 <= x_max]
|
| 189 |
if len(visible) > 1:
|
| 190 |
positions = " ".join(f"{x(fp, negatives):.2f},{y(tp, positives):.2f}" for fp, tp in visible)
|
| 191 |
out.append(f'<polyline points="{positions}" fill="none" stroke="{COLORS[model]}" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round"/>')
|
| 192 |
+
out += [f'<text x="{left + plot_w / 2:.1f}" y="{height - 23}" text-anchor="middle" fill="#e1e7ef" font-family="Arial,sans-serif" font-size="17">Clean methods wrongly flagged →</text>',
|
|
|
|
|
|
|
|
|
|
| 193 |
f'<text transform="translate(23 {top + plot_h / 2:.1f}) rotate(-90)" text-anchor="middle" fill="#e1e7ef" font-family="Arial,sans-serif" font-size="17">Actual issues found (recall) →</text>',
|
| 194 |
'</svg>']
|
| 195 |
output.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 198 |
|
| 199 |
def render_sections(results: list[dict], curves_by_domain: dict[str, dict], output_dir: Path) -> str:
|
| 200 |
sections = ["## Reading the results", "",
|
| 201 |
+
"Each line shows how many issues a model finds and what percentage of clean methods it wrongly flags as its score cutoff changes. Higher and farther left is better.", "",
|
| 202 |
+
"The tables use each run's recorded alert settings. A value of 20% under ‘Clean methods wrongly flagged’ means one in five clean methods received an alert. Models are ranked by recall minus that percentage. Bold marks the best displayed value in each column; cost compares priced runs captured here.", ""]
|
|
|
|
| 203 |
for domain in ("bug", "security", "lint"):
|
| 204 |
title = {"bug": "Bugs", "security": "Security", "lint": "Perch Lint Bench"}[domain]
|
| 205 |
link = {"bug": "bug-pairs-public", "security": "security-pairs-public", "lint": "perch-lint-bench-public"}[domain]
|
|
|
|
| 207 |
private = [r for r in results if r["domain"] == domain and r["track"] == "private"]
|
| 208 |
if set(r["model_id"] for r in public) != set(ORDER) or set(r["model_id"] for r in private) != set(ORDER):
|
| 209 |
raise ValueError(f"Unexpected models in {domain} results")
|
|
|
|
| 210 |
image = output_dir / f"{domain}-tradeoff.svg"
|
| 211 |
+
svg(domain, curves_by_domain[domain], image)
|
| 212 |
sections += [f"## {title}", "", f"[Public pairs](https://huggingface.co/datasets/perchscan/{link})", "",
|
| 213 |
f"", "",
|
| 214 |
f"### Public — {public[0]['benchmark_pairs']:,} pairs", "",
|
| 215 |
+
results_table(public), "",
|
| 216 |
f"### Private — {private[0]['benchmark_pairs']:,} pairs", "",
|
| 217 |
+
results_table(private), ""]
|
| 218 |
return "\n".join(sections)
|
| 219 |
|
| 220 |
|