Show model separation in benchmark graphs
Browse filesFiles changed (6)
28 unmodified lines293031323334353 unmodified lines3940414243444530 unmodified lines7677787980818230 unmodified lines11311411511611711811928 unmodified lines## Reading the resultsEach 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.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 full-set value in each column; cost compares priced runs captured here.3 unmodified lines[Public pairs](https://huggingface.co/datasets/perchscan/bug-pairs-public)### Public — 2,220 pairs30 unmodified lines[Public pairs](https://huggingface.co/datasets/perchscan/security-pairs-public)### Public — 1,311 pairs30 unmodified lines[Public pairs](https://huggingface.co/datasets/perchscan/perch-lint-bench-public)### Public — 214 pairs28 unmodified lines293031323334353 unmodified lines3940414243444530 unmodified lines7677787980818230 unmodified lines11311411511611711811928 unmodified lines## Reading the resultsEach line shows recall minus the false-positive rate as the score cutoff changes. Higher is better; farther left means fewer clean methods flagged. The dashed zero line means issues and clean methods are flagged at equal rates.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 full-set value in each column; cost compares priced runs captured here.3 unmodified lines[Public pairs](https://huggingface.co/datasets/perchscan/bug-pairs-public)### Public — 2,220 pairs30 unmodified lines[Public pairs](https://huggingface.co/datasets/perchscan/security-pairs-public)### Public — 1,311 pairs30 unmodified lines[Public pairs](https://huggingface.co/datasets/perchscan/perch-lint-bench-public)### Public — 214 pairs
123456789101112131415161718192021222324252627282930313233343536373839404142from pathlib import Pathimport tempfileimport unittestimport xml.etree.ElementTree as ET
import tradeoff
class GraphTests(unittest.TestCase): def test_equal_alert_rates_have_zero_margin_at_both_ends(self): # Unequal class sizes prevent subtracting raw counts by mistake. curves = {model: ([(0, 0), (2, 7), (20, 10)], 10, 20) for model in tradeoff.ORDER} with tempfile.TemporaryDirectory() as temp: output = Path(temp) / 'graph.svg' tradeoff.svg('bug', curves, output) root = ET.fromstring(output.read_text()) paths = root.findall('{http://www.w3.org/2000/svg}polyline') self.assertEqual(len(paths), len(tradeoff.ORDER)) points = [tuple(map(float, point.split(','))) for point in paths[0].attrib['points'].split()] self.assertEqual(points[0][1], points[2][1]) self.assertLess(points[1][1], points[0][1]) self.assertGreater(points[2][0], points[1][0]) labels = [e.text for e in root.findall('{http://www.w3.org/2000/svg}text')] self.assertIn('100%', labels) self.assertIn('Zero means issues and clean methods are flagged at equal rates.', root.find('{http://www.w3.org/2000/svg}desc').text) self.assertIn('Recall − false-positive rate (percentage points)', labels)
def test_negative_margins_remain_visible(self): curves = {model: ([(0, 0), (10, 2), (20, 10)], 10, 20) for model in tradeoff.ORDER} with tempfile.TemporaryDirectory() as temp: output = Path(temp) / 'graph.svg' tradeoff.svg('security', curves, output) root = ET.fromstring(output.read_text()) path = root.find('{http://www.w3.org/2000/svg}polyline') points = [tuple(map(float, point.split(','))) for point in path.attrib['points'].split()] self.assertGreater(points[1][1], points[0][1]) self.assertLessEqual(points[1][1], 498)
if __name__ == '__main__': unittest.main()10 unmodified lines11121314151617151 unmodified lines1691701711721731741751761771781791801811821831841851861871881891901911926 unmodified lines1992002012022032042052062072082092102112122132142152162172 unmodified lines22022122222322422522616 unmodified lines24324424524624724824910 unmodified linesfrom collections import defaultdictimport htmlimport jsonfrom math import isfinitefrom pathlib import Pathfrom tempfile import TemporaryDirectoryfrom urllib.request import urlopen151 unmodified lineswidth, height = 1120, 580left, right, top, bottom = 90, 40, 148, 82plot_w, plot_h = width - left - right, height - top - bottom# All benchmarks use one complete plot with the same percentage axes.x_max = 100y_max = 1.0def x(fp: int, negatives: int) -> float:return left + (fp / negatives * 100) / x_max * plot_wdef y(tp: int, positives: int) -> float:return top + (1 - (tp / positives) / y_max) * plot_htitle = {"bug": "Bug detection", "security": "Security detection", "lint": "Perch Lint Bench"}[domain]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">',f'<title id="title">{title}: recall versus false alerts</title>','<desc id="desc">Model score curves on the public benchmark. Higher and farther left is better.</desc>',f'<rect width="{width}" height="{height}" rx="16" fill="#101318"/>',f'<defs><clipPath id="plot"><rect x="{left}" y="{top}" width="{plot_w}" height="{plot_h}"/></clipPath></defs>',f'<text x="{left}" y="43" fill="#f2f5fa" font-family="Arial,sans-serif" font-weight="700" font-size="28">{html.escape(title)}</text>',f'<text x="{left}" y="70" fill="#aeb9c7" font-family="Arial,sans-serif" font-size="16">Public methods · recall versus false alerts</text>']for i, model in enumerate(ORDER):col = i % 4row = i // 46 unmodified linespx = left + value / x_max * plot_wout += [f'<line x1="{px:.1f}" y1="{top}" x2="{px:.1f}" y2="{top + plot_h}" stroke="#29303a"/>',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>']step = 20for value in range(0, round(y_max * 100) + 1, step):py = top + (1 - (value / 100) / y_max) * plot_hout += [f'<line x1="{left}" y1="{py:.1f}" x2="{left + plot_w}" y2="{py:.1f}" stroke="#29303a"/>',f'<text x="{left - 12}" y="{py + 5:.1f}" text-anchor="end" fill="#aeb9c7" font-family="Arial,sans-serif" font-size="14">{value}%</text>']for model in ORDER:points, positives, negatives = curves[model]visible = [(fp, tp) for fp, tp in points if fp / negatives * 100 <= x_max]if len(visible) > 1:positions = " ".join(f"{x(fp, negatives):.2f},{y(tp, positives):.2f}" for fp, tp in visible)out.append(f'<polyline points="{positions}" fill="none" stroke="{COLORS[model]}" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round" clip-path="url(#plot)"/>')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>',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>','</svg>']output.parent.mkdir(parents=True, exist_ok=True)output.write_text("\n".join(out) + "\n")2 unmodified linesdef render_sections(results: list[dict], curves_by_domain: dict[str, dict], output_dir: Path,codeql_results: dict) -> str:sections = ["## Reading the results", "","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.", "","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 full-set value in each column; cost compares priced runs captured here.", ""]if any(r.get("failed_methods") for r in results):sections += ["Failed requests count as incorrect decisions: a failed issue is a miss; a failed clean method is a false positive. Failed cases receive no model score and remain incorrect across the plotted cutoffs.", ""]16 unmodified linesimage = output_dir / f"{domain}-tradeoff.svg"svg(domain, curves_by_domain[domain], image)sections += [f"## {title}", "", f"[Public pairs](https://huggingface.co/datasets/perchscan/{link})", "",f"", "",f"### Public — {public[0]['benchmark_pairs']:,} pairs", "",results_table(public), ""]if domain in ("bug", "security"):10 unmodified lines11121314151617151 unmodified lines1691701711721731741751761771781791801811821831841851861871881891901911921931941951961976 unmodified lines2042052062072082092102112122132142152162172182192202212222232 unmodified lines22622722822923023123216 unmodified lines24925025125225325425510 unmodified linesfrom collections import defaultdictimport htmlimport jsonfrom math import ceil, floor, isfinitefrom pathlib import Pathfrom tempfile import TemporaryDirectoryfrom urllib.request import urlopen151 unmodified lineswidth, height = 1120, 580left, right, top, bottom = 90, 40, 148, 82plot_w, plot_h = width - left - right, height - top - bottom# Subtract the diagonal so small ranking differences remain visible.# Keep every cutoff and adapt only the vertical display range.x_max = 100step = 10 if domain == "lint" else 5margins = [100 * (tp / positives - fp / negatives)for points, positives, negatives in curves.values() for fp, tp in points]y_min = min(-step, floor(min(margins) / step) * step)y_max = max(step, ceil(max(margins) / step) * step)def x(fp: int, negatives: int) -> float:return left + (fp / negatives * 100) / x_max * plot_wdef y(margin: float) -> float:return top + (y_max - margin) / (y_max - y_min) * plot_htitle = {"bug": "Bug detection", "security": "Security detection", "lint": "Perch Lint Bench"}[domain]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">',f'<title id="title">{title}: recall minus false-positive rate</title>','<desc id="desc">Public model curves across score cutoffs. The vertical axis subtracts the false-positive rate from recall. Zero means issues and clean methods are flagged at equal rates. Higher is better.</desc>',f'<rect width="{width}" height="{height}" rx="16" fill="#101318"/>',f'<defs><clipPath id="plot"><rect x="{left}" y="{top}" width="{plot_w}" height="{plot_h}"/></clipPath></defs>',f'<text x="{left}" y="43" fill="#f2f5fa" font-family="Arial,sans-serif" font-weight="700" font-size="28">{html.escape(title)}</text>',f'<text x="{left}" y="70" fill="#aeb9c7" font-family="Arial,sans-serif" font-size="16">Public methods · recall minus false-positive rate · higher is better</text>']for i, model in enumerate(ORDER):col = i % 4row = i // 46 unmodified linespx = left + value / x_max * plot_wout += [f'<line x1="{px:.1f}" y1="{top}" x2="{px:.1f}" y2="{top + plot_h}" stroke="#29303a"/>',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>']for value in range(y_min, y_max + 1, step):py = y(value)out += [f'<line x1="{left}" y1="{py:.1f}" x2="{left + plot_w}" y2="{py:.1f}" stroke="#29303a"/>',f'<text x="{left - 12}" y="{py + 5:.1f}" text-anchor="end" fill="#aeb9c7" font-family="Arial,sans-serif" font-size="14">{value}</text>']zero_y = y(0)out.append(f'<line x1="{left}" y1="{zero_y:.1f}" x2="{left + plot_w}" y2="{zero_y:.1f}" stroke="#aeb9c7" stroke-width="1.5" stroke-dasharray="5 5"/>')for model in ORDER:points, positives, negatives = curves[model]visible = [(fp, tp) for fp, tp in points if fp / negatives * 100 <= x_max]if len(visible) > 1:positions = " ".join(f"{x(fp, negatives):.2f},{y(100 * (tp / positives - fp / negatives)):.2f}" for fp, tp in visible)out.append(f'<polyline points="{positions}" fill="none" stroke="{COLORS[model]}" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round" clip-path="url(#plot)"/>')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>',f'<text transform="translate(23 {top + plot_h / 2:.1f}) rotate(-90)" text-anchor="middle" fill="#e1e7ef" font-family="Arial,sans-serif" font-size="14">Recall − false-positive rate (percentage points)</text>','</svg>']output.parent.mkdir(parents=True, exist_ok=True)output.write_text("\n".join(out) + "\n")2 unmodified linesdef render_sections(results: list[dict], curves_by_domain: dict[str, dict], output_dir: Path,codeql_results: dict) -> str:sections = ["## Reading the results", "","Each line shows recall minus the false-positive rate as the score cutoff changes. Higher is better; farther left means fewer clean methods flagged. The dashed zero line means issues and clean methods are flagged at equal rates.", "","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 full-set value in each column; cost compares priced runs captured here.", ""]if any(r.get("failed_methods") for r in results):sections += ["Failed requests count as incorrect decisions: a failed issue is a miss; a failed clean method is a false positive. Failed cases receive no model score and remain incorrect across the plotted cutoffs.", ""]16 unmodified linesimage = output_dir / f"{domain}-tradeoff.svg"svg(domain, curves_by_domain[domain], image)sections += [f"## {title}", "", f"[Public pairs](https://huggingface.co/datasets/perchscan/{link})", "",f"", "",f"### Public — {public[0]['benchmark_pairs']:,} pairs", "",results_table(public), ""]if domain in ("bug", "security"):
README.md+4-4
assets/bug-tradeoff.svg
assets/lint-tradeoff.svg
assets/security-tradeoff.svg
test_tradeoff.pyAdded+42
tradeoff.py+22-16