File size: 28,516 Bytes
294abb8 84b4733 294abb8 84b4733 294abb8 84b4733 294abb8 84b4733 294abb8 84b4733 294abb8 84b4733 294abb8 84b4733 294abb8 84b4733 294abb8 84b4733 294abb8 84b4733 294abb8 84b4733 294abb8 84b4733 294abb8 4ee3619 | 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 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Rootformer-Code v25 vs Qwen4-35B-A3B — Live Interactive Demo Studio</title>
<style>
:root {
--bg: #070b14;
--panel: #0e1628;
--panel2: #121d34;
--border: rgba(148, 163, 184, 0.18);
--text: #e2e8f0;
--muted: #94a3b8;
--accent: #38bdf8;
--accent2: #818cf8;
--green: #34d399;
--amber: #fbbf24;
--rose: #fb7185;
}
* { box-sizing: border-box; }
body {
margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
background: radial-gradient(circle at 15% 0%, #102042 0%, var(--bg) 45%);
color: var(--text); min-height: 100vh;
}
.wrap { max-width: 1520px; margin: 0 auto; padding: 20px 20px 44px; }
header {
display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between;
padding: 18px 22px; background: rgba(14, 22, 40, 0.85); border: 1px solid var(--border);
border-radius: 16px; backdrop-filter: blur(12px); margin-bottom: 18px;
}
h1 { margin: 0 0 6px; font-size: 1.38rem; letter-spacing: -0.02em; }
.sub { color: var(--muted); font-size: 0.9rem; margin: 0; }
.links { display: flex; flex-wrap: wrap; gap: 10px; }
.btn {
display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px; border-radius: 10px;
font-size: 0.85rem; font-weight: 600; text-decoration: none; cursor: pointer; border: 1px solid var(--border);
background: var(--panel2); color: var(--text); transition: 0.15s ease;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn-primary { background: linear-gradient(135deg, #2563eb, #4f46e5); border-color: transparent; color: #fff; }
.kpis {
display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 18px;
}
.kpi {
background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px;
}
.kpi .lbl { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.kpi .val { font-size: 1.45rem; font-weight: 700; margin: 4px 0 2px; color: #fff; }
.kpi .note { font-size: 0.8rem; color: var(--green); }
.tabs {
display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; align-items: center; justify-content: space-between;
}
.tab-group { display: flex; flex-wrap: wrap; gap: 8px; }
.tab {
padding: 10px 15px; border-radius: 10px; background: var(--panel); border: 1px solid var(--border);
color: var(--muted); font-weight: 600; font-size: 0.88rem; cursor: pointer; transition: 0.15s ease;
}
.tab:hover { color: #fff; border-color: rgba(56,189,248,0.45); }
.tab.active {
background: linear-gradient(135deg, rgba(56,189,248,0.2), rgba(129,140,248,0.22));
border-color: var(--accent); color: #fff;
}
.pane { display: none; }
.pane.active { display: block; }
.desc-bar {
display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
padding: 12px 16px; margin-bottom: 14px; font-size: 0.88rem; color: var(--muted);
}
.desc-bar strong { color: #fff; }
.split {
display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px;
}
@media (max-width: 1024px) { .split { grid-template-columns: 1fr; } }
.card {
background: var(--panel); border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
display: flex; flex-direction: column;
}
.card-head {
display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between;
padding: 11px 14px; background: var(--panel2); border-bottom: 1px solid var(--border);
}
.card-title { font-weight: 700; font-size: 0.92rem; display: flex; align-items: center; gap: 8px; }
.pill {
font-size: 0.74rem; padding: 3px 8px; border-radius: 999px; font-weight: 700;
}
.pill-ours { background: rgba(52,211,153,0.16); color: var(--green); border: 1px solid rgba(52,211,153,0.35); }
.pill-q4 { background: rgba(129,140,248,0.16); color: #a5b4fc; border: 1px solid rgba(129,140,248,0.35); }
.pill-win { background: rgba(251,191,36,0.16); color: var(--amber); border: 1px solid rgba(251,191,36,0.35); }
.card-actions { display: flex; gap: 8px; align-items: center; }
.mini-link {
font-size: 0.78rem; color: var(--accent); text-decoration: none; font-weight: 600;
padding: 4px 8px; border-radius: 7px; background: rgba(56,189,248,0.1);
}
.mini-link:hover { background: rgba(56,189,248,0.22); }
iframe {
width: 100%; height: 640px; border: 0; background: #050811; display: block;
}
.table-wrap {
background: var(--panel); border: 1px solid var(--border); border-radius: 14px; overflow-x: auto; margin-bottom: 18px;
}
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 11px 14px; border-bottom: 1px solid var(--border); text-align: left; }
th { background: var(--panel2); color: #cbd5e1; font-weight: 700; }
.b-pass { background: rgba(52,211,153,0.16); color: var(--green); padding: 3px 8px; border-radius: 6px; font-weight: 700; font-size: 0.78rem; }
.b-fail { background: rgba(251,113,133,0.14); color: var(--rose); padding: 3px 8px; border-radius: 6px; font-weight: 700; font-size: 0.78rem; }
pre {
margin: 0; padding: 14px; overflow: auto; max-height: 460px; font-size: 0.8rem; line-height: 1.48;
background: #060a13; color: #e2e8f0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
</style>
</head>
<body>
<div class="wrap">
<header>
<div>
<h1>⚡ Rootformer-Code v25 (Stage 25.2 + KhalilSWE v3.6) vs. Qwen4-35B-A3B</h1>
<p class="sub">100% Live Browser HTML5 / Canvas / SVG Outputs & Unseen SWE-bench Shootout — Same Hardware (A100-80GB), Same Prompts</p>
</div>
<div class="links">
<a class="btn btn-primary" href="https://huggingface.co/enver/rootformer-code-v25-khalilswe-27b" target="_blank" rel="noopener">🤗 Model Weights (27B BF16)</a>
<a class="btn" href="https://huggingface.co/datasets/enver/KhalilAlgoWorks" target="_blank" rel="noopener">📚 KhalilAlgoWorks Dataset</a>
</div>
</header>
<section class="kpis">
<div class="kpi">
<div class="lbl">SWE-bench Verified 100</div>
<div class="val">62.0% <span style="font-size:0.9rem;color:#94a3b8">(62/100)</span></div>
<div class="note">63.2% Unseen · 6.2× vs Vanilla Qwen3.8-27B (10%)</div>
</div>
<div class="kpi">
<div class="lbl">Unseen SWE-HO6 vs Qwen4</div>
<div class="val">4/6 vs 3/6</div>
<div class="note">Ours 66.7% beats Qwen4-35B-A3B ReAct (50.0%)</div>
</div>
<div class="kpi">
<div class="lbl">Qwen4 + Our KhalilSWE v3.6</div>
<div class="val">5/6 <span style="font-size:0.9rem;color:#94a3b8">(83.3%)</span></div>
<div class="note">+33.3 pts lift & 100% patch rate on Qwen4 itself!</div>
</div>
<div class="kpi">
<div class="lbl">Dev-615 + Turāth-40 Arabic</div>
<div class="val">81.63% / 75.0%</div>
<div class="note">502/615 OOF (ECE 0.0413) · +7.5 pts Arabic Fast</div>
</div>
</section>
<div class="tabs">
<div class="tab-group">
<button class="tab active" data-tab="hex">1. Spinning Neon Hexagon Physics (LIVE)</button>
<button class="tab" data-tab="glass">2. Glassmorphism Telemetry UI (LIVE · Full)</button>
<button class="tab" data-tab="pelican">3. Moving Pelican on a Bicycle (LIVE Animation)</button>
<button class="tab" data-tab="bench">4. SWE-HO6 & Audited Code Outputs</button>
</div>
<button class="btn" id="reloadBtn" type="button">↻ Reload Active Live Demos</button>
</div>
<!-- TAB 1: SPINNING HEXAGON -->
<div class="pane active" id="pane-hex">
<div class="desc-bar">
<div><strong>Prompt:</strong> Single-file HTML5 Canvas simulation of 18 glowing physics balls with gravity, elasticity, trails, and HUD inside a rotating neon hexagon.</div>
<div><strong>Result:</strong> Ours achieved <strong>33.0 FPS</strong> with a crisp zero-overlap HUD vs Qwen4's <strong>21.5 FPS</strong>, overlapping energy text, and smeared outline.</div>
</div>
<div class="split">
<div class="card">
<div class="card-head">
<div class="card-title"><span class="pill pill-ours">OURS</span> Rootformer Stage 25.2 (Qaṭʿ · 39.5s) <span class="pill pill-win">33.0 FPS · WIN</span></div>
<div class="card-actions">
<a class="mini-link" href="./spinning_hexagon_html_ours.html" target="_blank" rel="noopener">Fullscreen ↗</a>
</div>
</div>
<iframe data-src="./spinning_hexagon_html_ours.html" src="./spinning_hexagon_html_ours.html" title="Ours Spinning Hexagon"></iframe>
</div>
<div class="card">
<div class="card-head">
<div class="card-title"><span class="pill pill-q4">QWEN4</span> Qwen4-35B-A3B (35.6s · 21.5 FPS)</div>
<div class="card-actions">
<a class="mini-link" href="./spinning_hexagon_html_qwen4.html" target="_blank" rel="noopener">Fullscreen ↗</a>
</div>
</div>
<iframe data-src="./spinning_hexagon_html_qwen4.html" src="./spinning_hexagon_html_qwen4.html" title="Qwen4 Spinning Hexagon"></iframe>
</div>
</div>
</div>
<!-- TAB 2: GLASSMORPHISM UI -->
<div class="pane" id="pane-glass">
<div class="desc-bar">
<div><strong>Prompt:</strong> Single-file dark glassmorphism Autonomous Software Engineering Agent Telemetry Card (equal <strong>10,240-token</strong> output cap for both models).</div>
<div><strong>Result:</strong> Both finished 100% cleanly (<code>finish=stop</code>, 0 JS errors) — Ours (<strong>Forge-7</strong>, <strong>7,088 tok</strong>) rendered all 4 sparkline KPI cards, dual-series bar+trendline chart, and PR pills in fewer tokens than Qwen4 (<strong>Aurora-7</strong>, <strong>7,800 eval tok</strong>).</div>
</div>
<div class="split">
<div class="card">
<div class="card-head">
<div class="card-title"><span class="pill pill-ours">OURS</span> Rootformer Stage 25.2 (7,088 tok · Clean Finish) <span class="pill pill-win">100% COMPLETE</span></div>
<div class="card-actions">
<a class="mini-link" href="./glassmorphism_ui_html_ours.html" target="_blank" rel="noopener">Fullscreen ↗</a>
</div>
</div>
<iframe data-src="./glassmorphism_ui_html_ours.html" src="./glassmorphism_ui_html_ours.html" title="Ours Glassmorphism UI"></iframe>
</div>
<div class="card">
<div class="card-head">
<div class="card-title"><span class="pill pill-q4">QWEN4</span> Qwen4-35B-A3B (7,800 eval tok · Clean Finish)</div>
<div class="card-actions">
<a class="mini-link" href="./glassmorphism_ui_html_qwen4.html" target="_blank" rel="noopener">Fullscreen ↗</a>
</div>
</div>
<iframe data-src="./glassmorphism_ui_html_qwen4.html" src="./glassmorphism_ui_html_qwen4.html" title="Qwen4 Glassmorphism UI"></iframe>
</div>
</div>
</div>
<!-- TAB 3: MOVING PELICAN ANIMATION -->
<div class="pane" id="pane-pelican">
<div class="desc-bar">
<div><strong>Prompt:</strong> Single-file HTML5 animated scene of a pelican actively pedaling a bicycle along a parallax coastal boardwalk at sunset with Speed slider, Pause toggle, and live FPS readout (equal <strong>10,240-token</strong> answer cap).</div>
<div><strong>Result:</strong> Both animate smoothly with 0 JS errors — Ours runs at <strong>40 FPS</strong> using <strong>2.1× fewer tokens</strong> (<strong>6,567</strong> vs <strong>13,805</strong> eval tok); Qwen4 runs at <strong>46 FPS</strong> with a larger pelican throat pouch.</div>
</div>
<div class="split">
<div class="card">
<div class="card-head">
<div class="card-title"><span class="pill pill-ours">OURS</span> Rootformer Stage 25.2 (40 FPS · 6,567 tok) <span class="pill pill-win">2.1× LEANER</span></div>
<div class="card-actions">
<a class="mini-link" href="./moving_pelican_html_ours.html" target="_blank" rel="noopener">Fullscreen ↗</a>
</div>
</div>
<iframe data-src="./moving_pelican_html_ours.html" src="./moving_pelican_html_ours.html" title="Ours Moving Pelican Animation"></iframe>
</div>
<div class="card">
<div class="card-head">
<div class="card-title"><span class="pill pill-q4">QWEN4</span> Qwen4-35B-A3B (46 FPS · 13,805 eval tok)</div>
<div class="card-actions">
<a class="mini-link" href="./moving_pelican_html_qwen4.html" target="_blank" rel="noopener">Fullscreen ↗</a>
</div>
</div>
<iframe data-src="./moving_pelican_html_qwen4.html" src="./moving_pelican_html_qwen4.html" title="Qwen4 Moving Pelican Animation"></iframe>
</div>
</div>
</div>
<!-- TAB 4: SWE-HO6 & CODE -->
<div class="pane" id="pane-bench">
<div class="desc-bar">
<div><strong>Unseen SWE-HO6 (3 Django + 3 SymPy from <code>heldout10</code>):</strong> Graded zero-Docker against official hidden <code>FAIL_TO_PASS + PASS_TO_PASS</code> suites under an identical 16-turn cap.</div>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Unseen GitHub Issue</th>
<th>Qwen3.8-27B + ReAct</th>
<th>Qwen4-35B-A3B + ReAct</th>
<th>Ours (27B + KhalilSWE v3.6)</th>
<th>Bonus: Qwen4-35B-A3B + Our KhalilSWE v3.6</th>
</tr>
</thead>
<tbody>
<tr><td><code>django__django-14725</code></td><td><span class="b-fail">FAIL</span></td><td><span class="b-fail">FAIL</span></td><td><span class="b-fail">FAIL</span></td><td><span class="b-fail">FAIL</span></td></tr>
<tr><td><code>django__django-14771</code></td><td><span class="b-fail">FAIL</span></td><td><span class="b-pass">PASS</span></td><td><span class="b-pass">PASS</span></td><td><span class="b-pass">PASS</span></td></tr>
<tr><td><code>django__django-14787</code></td><td><span class="b-fail">FAIL</span></td><td><span class="b-pass">PASS</span></td><td><span class="b-pass">PASS</span></td><td><span class="b-pass">PASS</span></td></tr>
<tr><td><code>sympy__sympy-22456</code></td><td><span class="b-fail">FAIL</span></td><td><span class="b-fail">FAIL</span></td><td><span class="b-pass">PASS</span></td><td><span class="b-pass">PASS</span></td></tr>
<tr><td><code>sympy__sympy-22914</code></td><td><span class="b-fail">FAIL</span></td><td><span class="b-pass">PASS</span></td><td><span class="b-pass">PASS</span></td><td><span class="b-pass">PASS</span></td></tr>
<tr><td><code>sympy__sympy-23262</code></td><td><span class="b-fail">FAIL</span></td><td><span class="b-fail">FAIL</span></td><td><span class="b-fail">FAIL</span></td><td><span class="b-pass">PASS</span></td></tr>
<tr style="background:rgba(56,189,248,0.08);font-weight:700;">
<td>Total Resolved</td>
<td>0 / 6 (0.0%)</td>
<td>3 / 6 (50.0%)</td>
<td style="color:var(--green)">4 / 6 (66.7%)</td>
<td style="color:var(--amber)">5 / 6 (83.3%)</td>
</tr>
</tbody>
</table>
</div>
<div class="desc-bar">
<div><strong>1. Unseen Multi-Library <code>BigCodeBench-Hard</code> (RandomForest / pandas / matplotlib):</strong> Both passed <strong>5/5 official unittests</strong>; Ours is <strong>3× leaner</strong> (1,040 chars vs 3,113 chars).</div>
</div>
<div class="split" style="margin-bottom:18px;">
<div class="card">
<div class="card-head"><div class="card-title"><span class="pill pill-ours">OURS · 5/5 PASS</span> Stage 25.2 (1,040 chars)</div></div>
<pre>import pandas as pd
from sklearn.ensemble import RandomForestClassifier
import seaborn as sns
import matplotlib.pyplot as plt
def task_func(df, target_column):
# Separate features and target
X = df.drop(columns=[target_column])
y = df[target_column]
# Train Random Forest Classifier
clf = RandomForestClassifier()
clf.fit(X, y)
# Get feature importances
feature_importances = clf.feature_importances_
# Create a dataframe for sorting
importance_df = pd.DataFrame({
'Feature': X.columns,
'Importance': feature_importances
})
# Sort in descending order
importance_df = importance_df.sort_values(by='Importance', ascending=False).reset_index(drop=True)
# Plot horizontal bar plot
fig, ax = plt.subplots()
sns.barplot(x='Importance', y='Feature', data=importance_df, ax=ax)
ax.set_xlabel('Feature Importance Score')
ax.set_ylabel('Features')
ax.set_title('Visualizing Important Features')
return clf, ax</pre>
</div>
<div class="card">
<div class="card-head"><div class="card-title"><span class="pill pill-q4">QWEN4 · 5/5 PASS</span> Qwen4-35B-A3B (3,113 chars)</div></div>
<pre>import pandas as pd
import numpy as np
from sklearn.ensemble import RandomForestClassifier
import seaborn as sns
import matplotlib.pyplot as plt
def task_func(df, target_column):
"""
Train a Random Forest classifier on a dataframe (using `target_column` as the
label) and plot the feature importances as a horizontal bar plot.
Parameters
----------
df : pandas.DataFrame
The dataframe containing the features and the column of interest.
target_column : str
The name of the column used as the classification target.
Returns
-------
(sklearn.ensemble.RandomForestClassifier, matplotlib.axes.Axes)
The trained random forest classifier and the Axes object of the
plotted bar chart.
"""
# ------------------------------------------------------------------
# 1. Split the data into features (X) and target (y)
# ------------------------------------------------------------------
X = df.drop(columns=[target_column])
y = df[target_column]
# ------------------------------------------------------------------
# 2. Encode any non numeric (categorical / boolean) feature columns so
# that the random forest can consume them.
# ------------------------------------------------------------------
non_numeric = X.select_dtypes(include=["object", "category", "bool", "string"]).columns
if len(non_numeric) > 0:
X = pd.get_dummies(X, columns=list(non_numeric))
# ------------------------------------------------------------------
# 3. Train the random forest classifier
# ------------------------------------------------------------------
clf = RandomForestClassifier()
clf.fit(X, y)
# ------------------------------------------------------------------
# 4. Collect and sort the feature importances in descending order
# ------------------------------------------------------------------
importances = clf.feature_importances_
feature_names = np.asarray(X.columns)
sorted_idx = np.argsort(importances)[::-1] # descending order
sorted_importances = np.asarray(importances)[sorted_idx]
sorted_features = feature_names[sorted_idx]
# ------------------------------------------------------------------
# 5. Plot: importances on the x-axis, feature names on the y-axis
# ------------------------------------------------------------------
fig, ax = plt.subplots(figsize=(10, 6))
ax.barh(sorted_features, sorted_importances, color="skyblue", edgecolor="black")
ax.set_xlabel("Feature Importance Score")
ax.set_ylabel("Features")
ax.set_title("Visualizing Important Features")
fig.tight_layout()
return clf, ax
if __name__ == "__main__":
# Simple demo
data = pd.DataFrame({
"feature1": np.random.rand(100),
"feature2": np.random.rand(100),
"feature3": np.random.rand(100),
"category": np.random.choice(["a", "b", "c"], 100),
"target": np.random.choice([0, 1], 100),
})
model, axis = task_func(data, "target")
plt.show()</pre>
</div>
</div>
<div class="desc-bar">
<div><strong>2. Classical Arabic <code>Turāth</code> DAG & Lexicographical Kahn Validator:</strong> Both passed <strong>10/10 hidden asserts</strong>; Ours is <strong>40% leaner</strong> with zero stray debug prints (2,096 chars vs 3,456 chars).</div>
</div>
<div class="split">
<div class="card">
<div class="card-head"><div class="card-title"><span class="pill pill-ours">OURS · 10/10 PASS</span> Stage 25.2 (2,096 chars)</div></div>
<pre>def analyze_isnad_dag(chains: list[list[str]], unreliable: set[str]) -> dict:
from heapq import heappush, heappop
nodes = set()
edges = set()
for chain in chains:
for n in chain:
nodes.add(n)
for i in range(len(chain) - 1):
edges.add((chain[i], chain[i + 1]))
# Check for self-loops (direct cycle)
for u, v in edges:
if u == v:
return {"valid_dag": False, "topological_order": [], "authentic_chains": 0, "longest_clean_path": 0}
# Build adjacency and in-degree
adj = {n: [] for n in nodes}
in_degree = {n: 0 for n in nodes}
for u, v in edges:
adj[u].append(v)
in_degree[v] += 1
# Kahn's algorithm with lexicographic tie-breaking
heap = [n for n in nodes if in_degree[n] == 0]
heap.sort()
topo = []
while heap:
u = heappop(heap)
topo.append(u)
for v in adj[u]:
in_degree[v] -= 1
if in_degree[v] == 0:
heappush(heap, v)
if len(topo) != len(nodes):
return {"valid_dag": False, "topological_order": [], "authentic_chains": 0, "longest_clean_path": 0}
# Authentic chains: non-empty and no narrator in unreliable
authentic_chains = 0
for chain in chains:
if len(chain) > 0 and not any(n in unreliable for n in chain):
authentic_chains += 1
# Longest clean path (number of nodes) in subgraph of reliable nodes
clean_nodes = {n for n in nodes if n not in unreliable}
if not clean_nodes:
longest_clean_path = 0
else:
dp = {n: 1 for n in clean_nodes}
for u in topo:
if u not in clean_nodes:
continue
for v in adj[u]:
if v in clean_nodes:
if dp[u] + 1 > dp[v]:
dp[v] = dp[u] + 1
longest_clean_path = max(dp.values())
return {
"valid_dag": True,
"topological_order": topo,
"authentic_chains": authentic_chains,
"longest_clean_path": longest_clean_path
}</pre>
</div>
<div class="card">
<div class="card-head"><div class="card-title"><span class="pill pill-q4">QWEN4 · 10/10 PASS</span> Qwen4-35B-A3B (3,456 chars)</div></div>
<pre>import heapq
def analyze_isnad_dag(chains: list[list[str]], unreliable: set[str]) -> dict:
"""
تحليل رسم الإسناد الموجّه المُجمَّع من كل سلاسل الإسناد.
يعيد:
{
"valid_dag": bool,
"topological_order": list[str], # كسني أبجدي عند التساوي
"authentic_chains": int,
"longest_clean_path": int
}
"""
invalid = {
"valid_dag": False,
"topological_order": [],
"authentic_chains": 0,
"longest_clean_path": 0,
}
if unreliable is None:
unreliable = set()
nodes: set[str] = set()
adj: dict[str, set] = {}
indeg: dict[str, int] = {}
edge_set: set[tuple[str, str]] = set()
# ---- بناء الرسم البياني المُجمَّع (عقد + حواف فريدة) ----
for chain in chains:
if chain is None:
continue
chain = list(chain)
if not chain:
continue
for name in chain:
nodes.add(name)
if name not in adj:
adj[name] = set()
indeg[name] = 0
for a, b in zip(chain, chain[1:]):
if a == b:
# حلقة ذاتية => دورة موجهة حتماً
adj.setdefault(a, set())
indeg.setdefault(a, 0)
if (a, b) not in edge_set:
edge_set.add((a, b))
adj[a].add(b)
indeg[b] += 1
continue
if (a, b) not in edge_set:
edge_set.add((a, b))
adj[a].add(b)
indeg[b] += 1
if not nodes:
return {
"valid_dag": True,
"topological_order": [],
"authentic_chains": 0,
"longest_clean_path": 0,
}
# ---- خوارزمية كان مع أولوية صغرى (كسني أبجدي) ----
heap = [n for n in nodes if indeg[n] == 0]
heapq.heapify(heap)
order: list[str] = []
while heap:
u = heapq.heappop(heap)
order.append(u)
for v in sorted(adj[u]):
indeg[v] -= 1
if indeg[v] == 0:
heapq.heappush(heap, v)
if len(order) != len(nodes):
# توجد دورة موجهة (أو حلقة ذاتية)
return invalid
# ---- عدد السلاسل الصحيحة (خالية من الرواة غير الموثوقين) ----
authentic_chains = 0
for chain in chains:
if chain is None:
continue
if not chain:
continue
ok = True
for name in chain:
if name in unreliable:
ok = False
break
if ok:
authentic_chains += 1
# ---- أطول مسار موجّه يمر فقط برواة موثوقين (DP على الترتيب الطوبولوجي) ----
dp: dict[str, int] = {}
for u in order:
if u in unreliable:
continue
if u not in dp:
dp[u] = 1
base = dp[u]
for v in adj[u]:
if v in unreliable:
continue
if dp.get(v, 0) < base + 1:
dp[v] = base + 1
longest_clean_path = max(dp.values()) if dp else 0
return {
"valid_dag": True,
"topological_order": order,
"authentic_chains": authentic_chains,
"longest_clean_path": longest_clean_path,
}
if __name__ == "__main__":
print(analyze_isnad_dag([["مالك", "نافع", "ابن عمر"]], {"ابن عمر"}))
print(analyze_isnad_dag([["أ", "ب"], ["ب", "أ"]], set()))
print(analyze_isnad_dag([], set()))</pre>
</div>
</div>
</div>
</div>
<script>
(function() {
const tabs = document.querySelectorAll('.tab');
const panes = document.querySelectorAll('.pane');
tabs.forEach(t => {
t.addEventListener('click', () => {
tabs.forEach(x => x.classList.remove('active'));
panes.forEach(p => p.classList.remove('active'));
t.classList.add('active');
document.getElementById('pane-' + t.dataset.tab).classList.add('active');
});
});
document.getElementById('reloadBtn').addEventListener('click', () => {
const active = document.querySelector('.pane.active');
if (!active) return;
active.querySelectorAll('iframe').forEach(f => {
const base = f.getAttribute('data-src') || f.src;
f.src = base.split('?')[0] + '?t=' + Date.now();
});
});
})();
</script>
</body>
</html>
|