Upload source code (part 2)
Browse files- web/src/app/results/page.tsx +44 -4
- web/src/components/FilingSearch.tsx +20 -4
- web/src/components/Shell.tsx +6 -6
- web/src/lib/types.ts +15 -5
web/src/app/results/page.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import Link from "next/link";
|
|
| 3 |
import { BarBreakdown, TrainingCurve } from "@/components/charts";
|
| 4 |
import { Banner, Button, Card, Pill, Stat } from "@/components/ui";
|
| 5 |
import { loadDashboard, loadReceipts } from "@/lib/data";
|
| 6 |
-
import { ANSWER_MODES } from "@/lib/types";
|
| 7 |
|
| 8 |
const RECEIPT_ROWS = [
|
| 9 |
{ key: "zeroshot", label: "Zero-shot" },
|
|
@@ -171,6 +171,7 @@ export default function Overview() {
|
|
| 171 |
<tbody className="tabular">
|
| 172 |
{ANSWER_MODES.map(({ key, label, note }) => {
|
| 173 |
const r = ans.modes[key];
|
|
|
|
| 174 |
const pct = (v: number) => `${(v * 100).toFixed(1)}%`;
|
| 175 |
const main = key === "top5" || key === "adaptive";
|
| 176 |
return (
|
|
@@ -190,16 +191,55 @@ export default function Overview() {
|
|
| 190 |
</table>
|
| 191 |
</div>
|
| 192 |
<p className="mt-3 text-[13px] leading-relaxed text-muted">
|
| 193 |
-
RAG raises correct answers from {(ans.modes.closed.correct * 100).toFixed(0)}% to {(ans.modes.top5.correct * 100).toFixed(0)}%. Keeping
|
| 194 |
pages until they hold 90% of the reranker's confidence uses{" "}
|
| 195 |
-
{((1 - ans.modes.adaptive.prompt_tokens_mean / ans.modes.top5.prompt_tokens_mean) * 100).toFixed(0)}% fewer tokens with no
|
| 196 |
significant accuracy change (McNemar p = 0.48). Even with the analysts' own pages a 4B model reaches{" "}
|
| 197 |
-
{(ans.modes.oracle.correct * 100).toFixed(0)}%, so the next gain is in reasoning, not retrieval. For scale, the FinanceBench paper
|
| 198 |
reports GPT-4-Turbo with retrieval failing 81% of these 150 questions.
|
| 199 |
</p>
|
| 200 |
</Card>
|
| 201 |
)}
|
| 202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
<h2 className="mt-7 mb-3 text-[16px] font-bold text-ink">Explore the results</h2>
|
| 204 |
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
| 205 |
{SCREENS.map(({ href, icon: Icon, title, text }) => (
|
|
|
|
| 3 |
import { BarBreakdown, TrainingCurve } from "@/components/charts";
|
| 4 |
import { Banner, Button, Card, Pill, Stat } from "@/components/ui";
|
| 5 |
import { loadDashboard, loadReceipts } from "@/lib/data";
|
| 6 |
+
import { ANSWER_MODES, THINK_MODES } from "@/lib/types";
|
| 7 |
|
| 8 |
const RECEIPT_ROWS = [
|
| 9 |
{ key: "zeroshot", label: "Zero-shot" },
|
|
|
|
| 171 |
<tbody className="tabular">
|
| 172 |
{ANSWER_MODES.map(({ key, label, note }) => {
|
| 173 |
const r = ans.modes[key];
|
| 174 |
+
if (!r) return null;
|
| 175 |
const pct = (v: number) => `${(v * 100).toFixed(1)}%`;
|
| 176 |
const main = key === "top5" || key === "adaptive";
|
| 177 |
return (
|
|
|
|
| 191 |
</table>
|
| 192 |
</div>
|
| 193 |
<p className="mt-3 text-[13px] leading-relaxed text-muted">
|
| 194 |
+
RAG raises correct answers from {(ans.modes.closed!.correct * 100).toFixed(0)}% to {(ans.modes.top5!.correct * 100).toFixed(0)}%. Keeping
|
| 195 |
pages until they hold 90% of the reranker's confidence uses{" "}
|
| 196 |
+
{((1 - ans.modes.adaptive!.prompt_tokens_mean / ans.modes.top5!.prompt_tokens_mean) * 100).toFixed(0)}% fewer tokens with no
|
| 197 |
significant accuracy change (McNemar p = 0.48). Even with the analysts' own pages a 4B model reaches{" "}
|
| 198 |
+
{(ans.modes.oracle!.correct * 100).toFixed(0)}%, so the next gain is in reasoning, not retrieval. For scale, the FinanceBench paper
|
| 199 |
reports GPT-4-Turbo with retrieval failing 81% of these 150 questions.
|
| 200 |
</p>
|
| 201 |
</Card>
|
| 202 |
)}
|
| 203 |
|
| 204 |
+
{ans?.modes.think_4096 && (
|
| 205 |
+
<Card className="mt-5" title="Thinking budget (budget forcing)" icon={<Sparkles size={18} />} action={<Pill tone="good">38% to 68%, McNemar p = 0.0001</Pill>}>
|
| 206 |
+
<div className="relative overflow-x-auto rounded-xl border border-line bg-surface-solid">
|
| 207 |
+
<table className="w-full min-w-[560px] text-[13.5px]">
|
| 208 |
+
<thead>
|
| 209 |
+
<tr className="border-b border-line text-left text-[11.5px] tracking-wide text-muted uppercase">
|
| 210 |
+
<th className="px-3 py-2.5 font-semibold">Reasoning before answering</th>
|
| 211 |
+
<th className="px-3 py-2.5 text-right font-semibold">Correct</th>
|
| 212 |
+
<th className="px-3 py-2.5 text-right font-semibold">Wrong</th>
|
| 213 |
+
<th className="px-3 py-2.5 text-right font-semibold">Refused</th>
|
| 214 |
+
<th className="px-3 py-2.5 text-right font-semibold">Seconds / question</th>
|
| 215 |
+
</tr>
|
| 216 |
+
</thead>
|
| 217 |
+
<tbody className="tabular">
|
| 218 |
+
{THINK_MODES.map(({ key, label }) => {
|
| 219 |
+
const r = ans.modes[key];
|
| 220 |
+
if (!r) return null;
|
| 221 |
+
const pct = (v: number) => `${(v * 100).toFixed(0)}%`;
|
| 222 |
+
return (
|
| 223 |
+
<tr key={key} className={`border-b border-line last:border-0 ${key === "think_4096" ? "font-semibold" : ""}`}>
|
| 224 |
+
<td className="px-3 py-2.5">{label}</td>
|
| 225 |
+
<td className="px-3 py-2.5 text-right">{pct(r.correct)}</td>
|
| 226 |
+
<td className="px-3 py-2.5 text-right">{pct(r.wrong)}</td>
|
| 227 |
+
<td className="px-3 py-2.5 text-right">{pct(r.refused)}</td>
|
| 228 |
+
<td className="px-3 py-2.5 text-right">{r.seconds_mean.toFixed(0)}</td>
|
| 229 |
+
</tr>
|
| 230 |
+
);
|
| 231 |
+
})}
|
| 232 |
+
</tbody>
|
| 233 |
+
</table>
|
| 234 |
+
</div>
|
| 235 |
+
<p className="mt-3 text-[13px] leading-relaxed text-muted">
|
| 236 |
+
The 50 calculation questions, the same top-5 pages, Qwen3.5-4B in Ollama. The model may reason up to the budget, then must answer
|
| 237 |
+
(s1 budget forcing). Reasoning cuts wrong answers from 60% to 14%: it more often notices a missing figure and says so instead of
|
| 238 |
+
guessing. Filing search shows these reasoned answers for the calculation questions.
|
| 239 |
+
</p>
|
| 240 |
+
</Card>
|
| 241 |
+
)}
|
| 242 |
+
|
| 243 |
<h2 className="mt-7 mb-3 text-[16px] font-bold text-ink">Explore the results</h2>
|
| 244 |
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4">
|
| 245 |
{SCREENS.map(({ href, icon: Icon, title, text }) => (
|
web/src/components/FilingSearch.tsx
CHANGED
|
@@ -55,7 +55,9 @@ export function FilingSearch({ questions }: { questions: QuestionSummary[] }) {
|
|
| 55 |
};
|
| 56 |
|
| 57 |
const hits = useMemo(() => detail?.methods.reranked.slice(0, 5) ?? [], [detail]);
|
| 58 |
-
|
|
|
|
|
|
|
| 59 |
// Open the page the answer cites; otherwise the top-ranked page.
|
| 60 |
useEffect(() => {
|
| 61 |
if (detail && selected === null && hits.length) setSelected(gen?.cited.find((r) => detail.pages[String(r)]) ?? hits[0].row);
|
|
@@ -88,7 +90,19 @@ export function FilingSearch({ questions }: { questions: QuestionSummary[] }) {
|
|
| 88 |
|
| 89 |
{detail && (
|
| 90 |
<>
|
| 91 |
-
<Card
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
{gen ? (
|
| 93 |
<>
|
| 94 |
<p className="text-[15px] leading-relaxed whitespace-pre-line text-ink">
|
|
@@ -142,8 +156,10 @@ export function FilingSearch({ questions }: { questions: QuestionSummary[] }) {
|
|
| 142 |
)}
|
| 143 |
</div>
|
| 144 |
<p className="mt-3 text-[12px] text-muted">
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
| 147 |
</p>
|
| 148 |
</Card>
|
| 149 |
|
|
|
|
| 55 |
};
|
| 56 |
|
| 57 |
const hits = useMemo(() => detail?.methods.reranked.slice(0, 5) ?? [], [detail]);
|
| 58 |
+
// The most accurate measured setting: reasoning before answering (calculation questions), else top-5 RAG.
|
| 59 |
+
const reasoned = detail?.generated.think_4096;
|
| 60 |
+
const gen = reasoned ?? detail?.generated.top5;
|
| 61 |
// Open the page the answer cites; otherwise the top-ranked page.
|
| 62 |
useEffect(() => {
|
| 63 |
if (detail && selected === null && hits.length) setSelected(gen?.cited.find((r) => detail.pages[String(r)]) ?? hits[0].row);
|
|
|
|
| 90 |
|
| 91 |
{detail && (
|
| 92 |
<>
|
| 93 |
+
<Card
|
| 94 |
+
className="mb-5"
|
| 95 |
+
title="SumProof's answer"
|
| 96 |
+
icon={<Sparkles size={18} />}
|
| 97 |
+
action={
|
| 98 |
+
gen ? (
|
| 99 |
+
<>
|
| 100 |
+
{reasoned && <Pill tone="dark">Reasoned answer</Pill>}
|
| 101 |
+
<OutcomePill g={gen} />
|
| 102 |
+
</>
|
| 103 |
+
) : null
|
| 104 |
+
}
|
| 105 |
+
>
|
| 106 |
{gen ? (
|
| 107 |
<>
|
| 108 |
<p className="text-[15px] leading-relaxed whitespace-pre-line text-ink">
|
|
|
|
| 156 |
)}
|
| 157 |
</div>
|
| 158 |
<p className="mt-3 text-[12px] text-muted">
|
| 159 |
+
{reasoned
|
| 160 |
+
? `Written by Qwen3.5-4B from the 5 best pages below, after reasoning for ${reasoned.thinking_tokens?.toLocaleString("en-US")} tokens: on calculation questions this lifts accuracy from 38% to 68%.`
|
| 161 |
+
: "Written by Qwen3.5-4B from the 5 best pages below."}{" "}
|
| 162 |
+
AI can misread tables and calculations, so check the source page before relying on a number.
|
| 163 |
</p>
|
| 164 |
</Card>
|
| 165 |
|
web/src/components/Shell.tsx
CHANGED
|
@@ -30,7 +30,7 @@ const MAIN = [
|
|
| 30 |
const WORKSPACE = [
|
| 31 |
{ href: "/results/", label: "Model results", icon: BarChart3 },
|
| 32 |
{ href: "/receipts/", label: "Before vs after", icon: ReceiptText },
|
| 33 |
-
{ href: "/compare/", label: "
|
| 34 |
{ href: "/architecture/", label: "Architecture", icon: Network },
|
| 35 |
{ href: "/about/", label: "Data & licences", icon: BookOpen },
|
| 36 |
];
|
|
@@ -64,7 +64,7 @@ function NavList({ items, path, onNavigate }: { items: typeof MAIN; path: string
|
|
| 64 |
href={href}
|
| 65 |
onClick={onNavigate}
|
| 66 |
aria-current={active ? "page" : undefined}
|
| 67 |
-
className={`flex items-center gap-3 rounded-lg px-3 py-2
|
| 68 |
active ? "bg-white/10 font-semibold text-white ring-1 ring-white/15" : "text-nav-ink hover:bg-white/5 hover:text-white"
|
| 69 |
}`}
|
| 70 |
>
|
|
@@ -80,7 +80,7 @@ function NavList({ items, path, onNavigate }: { items: typeof MAIN; path: string
|
|
| 80 |
|
| 81 |
function Sidebar({ path, onNavigate }: { path: string; onNavigate?: () => void }) {
|
| 82 |
return (
|
| 83 |
-
<div className="flex h-full flex-col gap-
|
| 84 |
<Logo />
|
| 85 |
<nav aria-label="App" className="flex flex-col gap-2 border-t border-white/10 pt-5">
|
| 86 |
<p className="px-3 text-[11.5px] font-medium tracking-[0.1em] text-nav-muted uppercase">App</p>
|
|
@@ -93,7 +93,7 @@ function Sidebar({ path, onNavigate }: { path: string; onNavigate?: () => void }
|
|
| 93 |
href={GITHUB_URL}
|
| 94 |
target="_blank"
|
| 95 |
rel="noreferrer"
|
| 96 |
-
className="flex items-center gap-3 rounded-lg px-3 py-2
|
| 97 |
>
|
| 98 |
<Github size={18} strokeWidth={1.8} className="text-nav-muted" />
|
| 99 |
Source code
|
|
@@ -118,7 +118,7 @@ export function Shell({ children }: { children: React.ReactNode }) {
|
|
| 118 |
return (
|
| 119 |
<div className="flex min-h-screen">
|
| 120 |
<aside className="hidden w-[248px] shrink-0 bg-nav lg:block">
|
| 121 |
-
<div className="sticky top-0 h-screen">
|
| 122 |
<Sidebar path={path} />
|
| 123 |
</div>
|
| 124 |
</aside>
|
|
@@ -126,7 +126,7 @@ export function Shell({ children }: { children: React.ReactNode }) {
|
|
| 126 |
{open && (
|
| 127 |
<div className="fixed inset-0 z-40 lg:hidden" role="dialog" aria-modal="true" aria-label="Navigation">
|
| 128 |
<button className="absolute inset-0 bg-black/40" aria-label="Close navigation" onClick={() => setOpen(false)} />
|
| 129 |
-
<div className="relative h-full w-[272px] bg-nav">
|
| 130 |
<button
|
| 131 |
onClick={() => setOpen(false)}
|
| 132 |
aria-label="Close navigation"
|
|
|
|
| 30 |
const WORKSPACE = [
|
| 31 |
{ href: "/results/", label: "Model results", icon: BarChart3 },
|
| 32 |
{ href: "/receipts/", label: "Before vs after", icon: ReceiptText },
|
| 33 |
+
{ href: "/compare/", label: "Search methods", icon: Columns3 },
|
| 34 |
{ href: "/architecture/", label: "Architecture", icon: Network },
|
| 35 |
{ href: "/about/", label: "Data & licences", icon: BookOpen },
|
| 36 |
];
|
|
|
|
| 64 |
href={href}
|
| 65 |
onClick={onNavigate}
|
| 66 |
aria-current={active ? "page" : undefined}
|
| 67 |
+
className={`flex items-center gap-3 rounded-lg px-3 py-2 text-[14.5px] transition-colors ${
|
| 68 |
active ? "bg-white/10 font-semibold text-white ring-1 ring-white/15" : "text-nav-ink hover:bg-white/5 hover:text-white"
|
| 69 |
}`}
|
| 70 |
>
|
|
|
|
| 80 |
|
| 81 |
function Sidebar({ path, onNavigate }: { path: string; onNavigate?: () => void }) {
|
| 82 |
return (
|
| 83 |
+
<div className="flex min-h-full flex-col gap-5 px-4 py-5">
|
| 84 |
<Logo />
|
| 85 |
<nav aria-label="App" className="flex flex-col gap-2 border-t border-white/10 pt-5">
|
| 86 |
<p className="px-3 text-[11.5px] font-medium tracking-[0.1em] text-nav-muted uppercase">App</p>
|
|
|
|
| 93 |
href={GITHUB_URL}
|
| 94 |
target="_blank"
|
| 95 |
rel="noreferrer"
|
| 96 |
+
className="flex items-center gap-3 rounded-lg px-3 py-2 text-[14.5px] text-nav-ink hover:bg-white/5 hover:text-white"
|
| 97 |
>
|
| 98 |
<Github size={18} strokeWidth={1.8} className="text-nav-muted" />
|
| 99 |
Source code
|
|
|
|
| 118 |
return (
|
| 119 |
<div className="flex min-h-screen">
|
| 120 |
<aside className="hidden w-[248px] shrink-0 bg-nav lg:block">
|
| 121 |
+
<div className="sticky top-0 h-screen overflow-y-auto">
|
| 122 |
<Sidebar path={path} />
|
| 123 |
</div>
|
| 124 |
</aside>
|
|
|
|
| 126 |
{open && (
|
| 127 |
<div className="fixed inset-0 z-40 lg:hidden" role="dialog" aria-modal="true" aria-label="Navigation">
|
| 128 |
<button className="absolute inset-0 bg-black/40" aria-label="Close navigation" onClick={() => setOpen(false)} />
|
| 129 |
+
<div className="relative h-full w-[272px] overflow-y-auto bg-nav">
|
| 130 |
<button
|
| 131 |
onClick={() => setOpen(false)}
|
| 132 |
aria-label="Close navigation"
|
web/src/lib/types.ts
CHANGED
|
@@ -35,9 +35,17 @@ export type QuestionSummary = {
|
|
| 35 |
|
| 36 |
/** How the generated answer compares with the analysts' reference answer. */
|
| 37 |
export type Outcome = "correct" | "wrong" | "refused" | "ungraded";
|
| 38 |
-
export type AnswerMode = "closed" | "top5" | "adaptive" | "oracle";
|
| 39 |
|
| 40 |
-
export type GeneratedAnswer = { text: string; rows: number[]; cited: number[]; outcome: Outcome; prompt_tokens: number };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
export const ANSWER_MODES: { key: AnswerMode; label: string; note: string }[] = [
|
| 43 |
{ key: "closed", label: "No pages (closed book)", note: "what the model knows" },
|
|
@@ -81,9 +89,11 @@ export type Dashboard = {
|
|
| 81 |
train_log: { step: number; epoch: number; loss: number; lr: number }[];
|
| 82 |
answers?: {
|
| 83 |
judge: string;
|
| 84 |
-
modes:
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
| 87 |
>;
|
| 88 |
judge_vs_numeric_rule: { answers: number; agreement: number };
|
| 89 |
};
|
|
|
|
| 35 |
|
| 36 |
/** How the generated answer compares with the analysts' reference answer. */
|
| 37 |
export type Outcome = "correct" | "wrong" | "refused" | "ungraded";
|
| 38 |
+
export type AnswerMode = "closed" | "top5" | "adaptive" | "oracle" | "think_0" | "think_1024" | "think_2048" | "think_4096";
|
| 39 |
|
| 40 |
+
export type GeneratedAnswer = { text: string; rows: number[]; cited: number[]; outcome: Outcome; prompt_tokens: number; thinking_tokens?: number };
|
| 41 |
+
|
| 42 |
+
/** Thinking budgets measured on the 50 metric questions (same top-5 pages, Ollama). */
|
| 43 |
+
export const THINK_MODES: { key: AnswerMode; label: string }[] = [
|
| 44 |
+
{ key: "think_0", label: "No thinking" },
|
| 45 |
+
{ key: "think_1024", label: "1,024 tokens" },
|
| 46 |
+
{ key: "think_2048", label: "2,048 tokens" },
|
| 47 |
+
{ key: "think_4096", label: "4,096 tokens" },
|
| 48 |
+
];
|
| 49 |
|
| 50 |
export const ANSWER_MODES: { key: AnswerMode; label: string; note: string }[] = [
|
| 51 |
{ key: "closed", label: "No pages (closed book)", note: "what the model knows" },
|
|
|
|
| 89 |
train_log: { step: number; epoch: number; loss: number; lr: number }[];
|
| 90 |
answers?: {
|
| 91 |
judge: string;
|
| 92 |
+
modes: Partial<
|
| 93 |
+
Record<
|
| 94 |
+
AnswerMode,
|
| 95 |
+
{ correct: number; wrong: number; refused: number; pages_mean: number; prompt_tokens_mean: number; seconds_mean: number; context_has_evidence_page: number | null }
|
| 96 |
+
>
|
| 97 |
>;
|
| 98 |
judge_vs_numeric_rule: { answers: number; agreement: number };
|
| 99 |
};
|