Spaces:
Running
Running
sergiopaniego HF Staff
Brand teal accent, readable text colors, U4 nudge redesign, U7 figures
39824c1 verified Download unit2-trace-viewer.html from training-agents-course/figures: direct link, hf CLI and curl.
- Browser
- Download file 15.2 kB
-
https://huggingface.co/spaces/training-agents-course/figures/resolve/main/unit2-trace-viewer.html
- Command line
-
hf download hf://spaces/training-agents-course/figures/unit2-trace-viewer.html
-
curl -L -o unit2-trace-viewer.html https://huggingface.co/spaces/training-agents-course/figures/resolve/main/unit2-trace-viewer.html
15.2 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>Three traces from the dataset</title> | |
| <!-- Generated by build.py from fragments/. Runtime and theme tokens come from the research-article template. --> | |
| <link rel="stylesheet" href="runtime/variables.css"> | |
| <script> | |
| // The iframe can't read the course page's theme, so follow ?theme= if given, else the OS setting. | |
| (function () { | |
| const forced = new URLSearchParams(location.search).get('theme'); | |
| const mq = matchMedia('(prefers-color-scheme: dark)'); | |
| const apply = () => document.documentElement.setAttribute('data-theme', forced || (mq.matches ? 'dark' : 'light')); | |
| apply(); | |
| if (!forced) mq.addEventListener('change', apply); | |
| })(); | |
| </script> | |
| <script src="runtime/color-palettes.js"></script> | |
| <script src="runtime/rough.js"></script> | |
| <script src="runtime/hand.js"></script> | |
| <script src="runtime/embed-runtime.js"></script> | |
| <style> | |
| html, body { margin: 0; padding: 0; } | |
| /* An opaque card with its own background, so it stays readable whatever theme the course page uses */ | |
| body { background: transparent; } | |
| .figure-card { font-family: 'Source Sans 3', var(--default-font-family); color: var(--text-color); background: var(--page-bg); | |
| border: 1px solid var(--border-color); border-radius: 10px; padding: 12px 14px 10px; } | |
| </style> | |
| <script> | |
| // Clean look by default, in Source Sans. ?style=hand brings back the old hand-drawn look for comparison: | |
| // it loads Excalifont and uses it for the whole card. | |
| if (new URLSearchParams(location.search).get('style') === 'hand') { | |
| const st = document.createElement('style'); | |
| st.textContent = "@font-face { font-family: 'Excalifont'; src: url('runtime/fonts/Excalifont-Regular.woff2') format('woff2'); font-display: swap; }" + | |
| ".figure-card { font-family: 'Excalifont', 'Source Sans 3', var(--default-font-family); }"; | |
| document.head.appendChild(st); | |
| } else { | |
| document.documentElement.classList.add('style-clean'); | |
| const l = document.createElement('link'); l.rel = 'stylesheet'; | |
| l.href = 'https://fonts.googleapis.com/css2?family=Source+Sans+3:wght@400;600;700&display=swap'; | |
| document.head.appendChild(l); | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <div class="figure-card"> | |
| <!-- title: Three traces from the dataset --> | |
| <div class="fig-u2-traces"></div> | |
| <style> | |
| .fig-u2-traces { position: relative; color: var(--text-color); font-size: 14px; } | |
| .fig-u2-traces .fig-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; } | |
| .fig-u2-traces button { | |
| font: inherit; font-size: 14px; height: 30px; padding: 0 12px; border-radius: 6px; cursor: pointer; | |
| color: var(--text-color); background: var(--surface-bg); border: 1px solid var(--border-color); | |
| } | |
| .fig-u2-traces button[aria-selected="true"] { border-color: var(--primary-color); } | |
| .fig-u2-traces button:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 2px; } | |
| .fig-u2-traces .fig-sub { margin: 0 0 10px; color: var(--muted-color); } | |
| .fig-u2-traces .fig-step { display: grid; grid-template-columns: 76px minmax(0, 1fr); column-gap: 10px; margin-bottom: 10px; } | |
| .fig-u2-traces .fig-role { padding-top: 7px; text-align: right; color: var(--muted-color); font-family: 'Source Sans 3', var(--default-font-family); font-size: 15px; } | |
| .fig-u2-traces .fig-card { position: relative; } | |
| .fig-u2-traces .fig-card > svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; } | |
| .fig-u2-traces .fig-body { position: relative; padding: 7px 12px; } | |
| .fig-u2-traces pre { | |
| margin: 0; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; | |
| white-space: pre-wrap; word-break: break-word; color: var(--text-color); | |
| } | |
| .fig-u2-traces pre.fig-long { position: relative; max-height: 120px; overflow: auto; } | |
| .fig-u2-traces .fig-text { margin: 0; line-height: 1.45; } | |
| .fig-u2-traces .fig-fn { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--muted-color); margin-bottom: 2px; } | |
| .fig-u2-traces .fig-hl { border-radius: 3px; padding: 0 2px; } | |
| .fig-u2-traces .fig-stepnote { grid-column: 2; margin: 4px 2px 0; color: var(--muted-color); font-size: 13.5px; line-height: 1.4; } | |
| @media (max-width: 480px) { | |
| .fig-u2-traces .fig-step { grid-template-columns: 1fr; } | |
| .fig-u2-traces .fig-role { text-align: left; padding: 0 0 2px; } | |
| .fig-u2-traces .fig-stepnote { grid-column: 1; } | |
| } | |
| </style> | |
| <script> | |
| Embed.mount('fig-u2-traces', (ctx) => { | |
| // Real traces from the course dataset (Qwen3-32B on MBPP training problems, kept because every hidden | |
| // test passed), copied as they are stored. Only the rules part of the user prompt is left out. | |
| const DATA = {"one": [{"role": "user", "text": "Task: Write a function to reverse words in a given string.\n\nExample test: assert reverse_words(\"python program\")==(\"program python\")"}, {"role": "assistant", "call": "def reverse_words(s):\n return \" \".join(reversed(s.split()))\n\nassert reverse_words(\"python program\") == \"program python\"", "text": ""}, {"role": "tool", "text": "(no output, exit_code=0)"}, {"role": "assistant", "text": "The function `reverse_words` has been successfully defined and passed the example test. Let me know if you need further modifications or tests!"}], "two": [{"role": "user", "text": "Task: Write a function to reverse words in a given string.\n\nExample test: assert reverse_words(\"python program\")==(\"program python\")"}, {"role": "assistant", "call": "def reverse_words(s):\n return \" \".join(s.split()[::-1])", "text": ""}, {"role": "tool", "text": "<function create_function.<locals>.new_func at 0x7fe3f80e0180>"}, {"role": "assistant", "call": "assert reverse_words(\"python program\")==\"program python\"", "text": ""}, {"role": "tool", "text": "(no output, exit_code=0)"}, {"role": "assistant", "text": "The function `reverse_words` has been defined correctly and passed the example test. It is now ready for hidden tests."}], "error": [{"role": "user", "text": "Task: Write a python function to find the length of the shortest word.\n\nExample test: assert len_log([\"win\",\"lose\",\"great\"]) == 3"}, {"role": "assistant", "call": "def len_log(words):\n return min(len(word) for word in words)\n\nassert len_log([\"win\",\"lose\",\"great\"] == 3", "text": ""}, {"role": "tool", "text": "Traceback (most recent call last):\n File \"/usr/local/lib/python3.11/site-packages/smolagents/local_python_executor.py\", line 1615, in evaluate_python_code\n expression = ast.parse(code)\n ^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.11/ast.py\", line 50, in parse\n return compile(source, filename, mode, flags,\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"<unknown>\", line 4\n assert len_log([\"win\",\"lose\",\"great\"] == 3\n ^\nSyntaxError: '(' was never closed\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File \"/usr/local/lib/python3.11/site-packages/coding_env/server/python_executor.py\", line 84, in run\n exec_result = self._executor(code)\n ^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.11/site-packages/smolagents/local_python_executor.py\", line 1748, in __call__\n output, is_final_answer = evaluate_python_code(\n ^^^^^^^^^^^^"}, {"role": "assistant", "call": "def len_log(words):\n return min(len(word) for word in words)\n\nassert len_log([\"win\",\"lose\",\"great\"]) == 3", "text": ""}, {"role": "tool", "text": "(no output, exit_code=0)"}, {"role": "assistant", "text": "The function `len_log` has been defined correctly, and the test passed without any issues. The function now returns the length of the shortest word in a list."}]}; | |
| const TABS = [ | |
| { | |
| key: 'one', label: 'One call', | |
| sub: 'Like 1,108 of the 1,380 traces (80%), with one tool call and a short final message.', | |
| notes: [ | |
| 'The task and one example test. The rules part of the prompt is the same in every trace and is left out here.', | |
| 'Defines the function and runs the example test in the same call.', | |
| 'No output and exit code 0, so the assert passed.', | |
| 'The teacher stops. The hidden tests ran after this and all passed, so the trace was kept.', | |
| ], | |
| }, | |
| { | |
| key: 'two', label: 'Two calls', | |
| sub: 'The same problem, another of the teacher\'s four attempts. It defines the function first and tests it in a second call.', | |
| notes: [ | |
| 'Same task as the first tab. At temperature 1.0 the teacher doesn\'t always take the same path.', | |
| 'Defines the function only.', | |
| 'The environment prints the value of the last statement. For a def, that\'s the new function object with its memory address (0x...). It means the function now exists in the session.', | |
| 'Runs the example test on its own.', | |
| 'No output, so the assert passed.', | |
| 'Done. This trace is the one rendered as tokens on the loss page.', | |
| ], | |
| }, | |
| { | |
| key: 'error', label: 'Error, then a fix', | |
| sub: 'One of the 65 traces with a tool error. Every one of them ends with a fix, since a trace is kept only if the hidden tests pass.', | |
| notes: [ | |
| 'A different problem.', | |
| 'The assert is missing a closing parenthesis.', | |
| 'A SyntaxError. The useful line sits in the middle of the environment\'s own traceback, and the script stores only the first 1,000 characters of a tool result.', | |
| 'Reads the error and adds the missing parenthesis. Nothing else changes.', | |
| 'No output, so the assert passed.', | |
| 'Only 65 of the 1,380 traces show the teacher reading an error like this.', | |
| ], | |
| }, | |
| ]; | |
| const ROLE_LABEL = { user: 'user', assistant: 'assistant', tool: 'tool' }; | |
| let active = 'one', width = 640; | |
| const controls = document.createElement('div'); | |
| controls.className = 'fig-controls'; | |
| controls.setAttribute('role', 'tablist'); | |
| const sub = document.createElement('p'); | |
| sub.className = 'fig-sub'; | |
| const list = document.createElement('div'); | |
| list.setAttribute('role', 'tabpanel'); | |
| const buttons = {}; | |
| TABS.forEach((t) => { | |
| const b = document.createElement('button'); | |
| b.type = 'button'; | |
| b.textContent = t.label; | |
| b.setAttribute('role', 'tab'); | |
| b.addEventListener('click', () => { active = t.key; draw(); }, { signal: ctx.signal }); | |
| buttons[t.key] = b; | |
| controls.appendChild(b); | |
| }); | |
| ctx.root.append(controls, sub, list); | |
| ctx.describe('Three real traces from the course dataset, as messages. One call: the teacher defines reverse_words and runs the example test in one run_python call, gets no output, and finishes. Two calls: on the same problem, the teacher defines the function, the environment prints the function object with its memory address, the teacher runs the example test in a second call, and finishes. Error, then a fix: the teacher\'s assert misses a closing parenthesis, the tool returns a SyntaxError inside a long traceback, the teacher adds the parenthesis, the test passes and it finishes.'); | |
| function card(C, step, note, i) { | |
| const row = document.createElement('div'); | |
| row.className = 'fig-step'; | |
| const role = document.createElement('div'); | |
| role.className = 'fig-role'; | |
| role.textContent = ROLE_LABEL[step.role]; | |
| const box = document.createElement('div'); | |
| box.className = 'fig-card'; | |
| const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); | |
| const body = document.createElement('div'); | |
| body.className = 'fig-body'; | |
| const R = Hand.role(C, step.role); | |
| if (step.call !== undefined) { | |
| if (step.text) { | |
| const p = document.createElement('p'); | |
| p.className = 'fig-text'; | |
| p.style.marginBottom = '6px'; | |
| p.textContent = step.text.trim(); | |
| body.appendChild(p); | |
| } | |
| const fn = document.createElement('div'); | |
| fn.className = 'fig-fn'; | |
| fn.textContent = 'run_python(code=)'; | |
| const pre = document.createElement('pre'); | |
| pre.textContent = step.call; | |
| body.append(fn, pre); | |
| } else if (step.role === 'tool') { | |
| const pre = document.createElement('pre'); | |
| if (step.text.length > 300) pre.className = 'fig-long'; | |
| // Highlight the line that names the error. | |
| step.text.split(/(\n)/).forEach((line) => { | |
| if (/^\w*Error:/.test(line)) { | |
| const s = document.createElement('span'); | |
| s.className = 'fig-hl'; | |
| s.style.background = C.redSoft; | |
| s.style.boxShadow = `inset 0 -2px 0 ${C.red}`; | |
| s.textContent = line; | |
| pre.appendChild(s); | |
| } else pre.appendChild(document.createTextNode(line)); | |
| }); | |
| body.appendChild(pre); | |
| } else { | |
| const p = document.createElement(step.role === 'user' ? 'pre' : 'p'); | |
| p.className = step.role === 'user' ? '' : 'fig-text'; | |
| p.textContent = step.text.trim(); | |
| body.appendChild(p); | |
| } | |
| box.append(svg, body); | |
| const n = document.createElement('p'); | |
| n.className = 'fig-stepnote'; | |
| n.textContent = note; | |
| row.append(role, box, n); | |
| list.appendChild(row); | |
| return { svg, box, R, i }; | |
| } | |
| function draw(key = active) { | |
| const C = Hand.colors(ctx.root); | |
| const tab = TABS.find((t) => t.key === key); | |
| Object.entries(buttons).forEach(([k, b]) => b.setAttribute('aria-selected', String(k === key))); | |
| sub.textContent = tab.sub; | |
| list.replaceChildren(); | |
| const cards = DATA[key].map((step, i) => card(C, step, tab.notes[i], i)); | |
| // Hand-drawn frames, sized after layout. | |
| cards.forEach(({ svg, box, R, i }) => { | |
| const w = box.offsetWidth, h = box.offsetHeight; | |
| svg.setAttribute('viewBox', `0 0 ${w} ${h}`); | |
| const hand = Hand.create(svg, { seed: 40 + i }); | |
| const fill = R.fill; | |
| hand.rect(1, 1, w - 2, h - 2, { fill, stroke: R.stroke, width: 1.3, roughness: 0.7 }); | |
| }); | |
| // Scroll a long tool result so the line that names the error is in view. | |
| list.querySelectorAll('pre.fig-long').forEach((pre) => { | |
| const hl = pre.querySelector('.fig-hl'); | |
| if (hl) pre.scrollTop = Math.max(0, hl.offsetTop - 40); | |
| }); | |
| return sub.offsetHeight + list.offsetHeight; | |
| } | |
| // Keep the figure as tall as its tallest tab, so switching tabs doesn't move the page. | |
| function layout() { | |
| list.style.minHeight = ''; | |
| const tallest = Math.max(...TABS.map((t) => draw(t.key) - sub.offsetHeight)); | |
| draw(); | |
| list.style.minHeight = tallest + 'px'; | |
| } | |
| if (document.fonts && document.fonts.ready) document.fonts.ready.then(() => { if (!ctx.signal.aborted) layout(); }); | |
| return ({ width: w }) => { width = w; layout(); }; | |
| }, { deps: [] }); | |
| </script> | |
| </div> | |
| </body> | |
| </html> | |