Xzero UI
Pro library

Mixture of expertsPro

An illustration of mixture of experts routing: each token is scored by a router, travels to its top experts, and their outputs merge into the token's result.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui-pro/mixture-of-experts
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui-pro/mixture-of-experts

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { MixtureOfExperts } from "@/components/xzero/mixture-of-experts/mixture-of-experts";

export function RoutingExplainer() {
  return <MixtureOfExperts />;
}

// Your own sequence and experts. Scores are gate weights in expert order.
const experts = [
  { name: "Code", handles: "Identifiers and keywords" },
  { name: "Math", handles: "Numbers and operators" },
  { name: "Prose", handles: "Everyday words" },
  { name: "Names", handles: "People and places" },
];

export function CustomRouting() {
  return (
    <MixtureOfExperts
      experts={experts}
      tokens={[
        { text: "const", scores: [0.7, 0.05, 0.15, 0.1] },
        { text: " total", scores: [0.4, 0.3, 0.25, 0.05] },
        { text: " =", scores: [0.35, 0.55, 0.05, 0.05] },
      ]}
      defaultTopK={1}
      capacityFactor={Infinity}
      parameters={{ total: 141, shared: 5, perExpert: 22 }}
      onRoute={route => console.log(route.token, route.experts)}
    />
  );
}

API reference

MixtureOfExperts

An illustration of sparse mixture of experts routing in one card. Tokens slide in one at a time, a router scores every expert with a small bar each, and the token travels to its top k experts. The chosen experts light up in a first and second choice color, their load counters roll, and their outputs merge into the token's output chip. A capacity limit can make a full expert skip a token, which the card shows as a warning. Hover or focus a token to freeze on its gate scores and choices, hover an expert to see what it tends to handle and which tokens it took, switch between top 1 and top 2 to roll the active parameter readout, and read the load balance bar underneath. The expert specialties, scores and parameter counts are illustrative, not measurements of a real model.

PropTypeDefaultDescription
tokensMixtureOfExpertsToken[]DEFAULT_TOKENSThe sequence to route, as { text, scores? }. Scores are gate weights, one per expert in expert order; any non-negative numbers work and are normalized to sum to 1. Tokens without scores get stable sample scores derived from their text. Defaults to a 15 token sample sentence with hand tuned scores.
expertsMixtureOfExpertsExpert[]DEFAULT_EXPERTSThe routed experts, from 2 to 12, as { name, handles?, icon? }. handles is the short description shown on hover; icon is a 14px glyph that narrow cards show instead of the name (it falls back to the first letter). The defaults are eight illustrative specialties: code, numbers, punctuation, names, grammar, verbs, dates and symbols.
topK1 | 2–Experts per token, controlled. Pair with onTopKChange.
defaultTopK1 | 22Experts per token on first render when uncontrolled.
onTopKChange(topK: 1 | 2) => void–Called when the top 1 or top 2 control changes.
parameters{ total: number; shared: number; perExpert: number }{ total: 671, shared: 5, perExpert: 16 }Sizes in billions for the readout. Active parameters are shared plus top k times perExpert, so the defaults read 21B at top 1 and 37B at top 2, of 671B. These numbers are illustrative: they echo the scale of large open weights models, not the exact layout of the eight expert diagram.
capacityFactornumber1Room per expert as a multiple of an even share of the routes: capacity is ceil(factor × tokens × k / experts). A token whose chosen expert is already full skips that expert, and passes through unchanged when every choice is full. Pass Infinity to never drop. With the defaults, two tokens overflow at top 2 and one at top 1.
speednumber1Multiplies the pace. At 1 a token takes about 2.2 seconds; 0 holds still.
pausedboolean–Holds the animation, controlled. Pair with onPausedChange.
defaultPausedbooleanfalseStarts paused when uncontrolled.
onPausedChange(paused: boolean) => void–Called by the play and pause button.
loopbooleantrueStarts over after a short summary once the last token is through. With reduced motion the card never loops; the button turns into a replay.
onRoute(route: MixtureOfExpertsRoute) => void–Called as each token is sent to its experts with { index, token, scores, experts, weights, dropped }. Experts are best first and weights are renormalized over the top k.
labelstring"Mixture of experts routing"Accessible name of the card.
classNamestring–Class on the root element. Set --moe-first and --moe-second on it to recolor the first and second choice.
styleCSSProperties–Inline style on the root element.

Keyboard interactions

KeysAction
TabMoves through the top k control, the play and pause button, the expert tiles (one stop) and the token sequence (one stop).
Arrow keys, Home, EndMove between options in the top k control, between expert tiles, or between tokens. Focusing a tile or a token with the keyboard freezes the card and shows its details.
Enter, SpaceOn a token or an expert, pins it so the card stays frozen on it; press again to unpin. On the play button, pauses, resumes or replays.
EscapeUnpins the pinned token or expert and lets routing resume.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in illustrations

Guidance for AI tools

Mixture of experts: An illustration of mixture of experts routing: each token is scored by a router, travels to its top experts, and their outputs merge into the token's result. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components