{
  "path": "/posts/2025/llm-conversation-branching/index",
  "site": "at://did:plc:mracrip6qu3vw46nbewg44sm/site.standard.publication/self",
  "$type": "site.standard.document",
  "title": "LLM Conversation Branching",
  "updatedAt": "2025-01-17T02:08:37.000Z",
  "description": "Visualizing and navigating branched conversations with LLMs and embeddings",
  "publishedAt": "2025-01-17T02:08:37.000Z",
  "textContent": "export const messages = [\n  {\n    id: '1',\n    prompt: 'What is machine learning?',\n    response:\n      'Machine learning is a branch of AI that enables systems to learn from data',\n    summary: 'Basic definition and core concept of machine learning',\n  },\n  {\n    id: '2',\n    parent_id: '1',\n    prompt: 'Can you explain neural networks?',\n    response:\n      'Neural networks are computing systems inspired by biological brains',\n    summary:\n      'Introduction to neural networks as brain-inspired computing systems',\n  },\n  {\n    id: '3',\n    parent_id: '1',\n    prompt: 'What about reinforcement learning?',\n    response:\n      'Reinforcement learning is learning through interaction with an environment',\n    summary: 'Overview of reinforcement learning as environment-based learning',\n  },\n  {\n    id: '4',\n    parent_id: '2',\n    prompt: 'What are some applications?',\n    response:\n      'Common applications include image recognition and natural language processing',\n    summary:\n      'Real-world applications of neural networks in computer vision and NLP',\n  },\n  {\n    id: '5',\n    parent_id: '3',\n    prompt: 'What are some examples?',\n    response:\n      'Examples include game playing AIs like AlphaGo and robotics control',\n    summary:\n      'Concrete examples of reinforcement learning in games and robotics',\n  },\n];\n\nexport const moreMessages = [\n  {\n    id: '1',\n    prompt: 'What is machine learning?',\n    response:\n      'Machine learning is a branch of AI that enables systems to learn from data',\n    summary: 'Basic definition and core concept of machine learning',\n    embedding_2d: [-0.8704802293794979, 1.6597547868477167],\n  },\n  {\n    id: '2',\n    parent_id: '1',\n    prompt: 'What are the ethical concerns?',\n    response:\n      'Key ethical concerns include bias in training data, privacy issues, and potential job displacement',\n    summary: 'Overview of ML ethics and societal impact',\n    embedding_2d: [-2.357171023654697, -3.6926941840950964],\n  },\n  {\n    id: '3',\n    parent_id: '1',\n    prompt: 'How is it used in healthcare?',\n    response:\n      'ML is used for disease diagnosis, drug discovery, and personalized treatment plans',\n    summary: 'Applications of ML in medical field',\n    embedding_2d: [-6.512378918799455, -3.4844864717193667],\n  },\n  {\n    id: '4',\n    parent_id: '1',\n    prompt: 'What programming languages are used?',\n    response:\n      'Popular languages include Python, R, and Julia with frameworks like TensorFlow and PyTorch',\n    summary: 'Programming tools for ML development',\n    embedding_2d: [-2.979766807873413, 6.468533476095193],\n  },\n  {\n    id: '5',\n    parent_id: '2',\n    prompt: 'How can we address algorithmic bias?',\n    response:\n      'Through diverse training data, regular audits, and transparent model development processes',\n    summary: 'Solutions for addressing ML bias',\n    embedding_2d: [-4.210181372227558, 4.8947246978693535],\n  },\n  {\n    id: '6',\n    parent_id: '3',\n    prompt: 'Tell me about radiology applications',\n    response:\n      'ML assists in analyzing medical images to detect tumors, fractures, and other abnormalities',\n    summary: 'ML in medical imaging',\n    embedding_2d: [-6.745846105849347, -5.684692915936991],\n  },\n  {\n    id: '7',\n    parent_id: '4',\n    prompt: 'What is PyTorch?',\n    response:\n      'PyTorch is a deep learning framework developed by Facebook, known for its dynamic computational graphs',\n    summary: 'Overview of PyTorch framework',\n    embedding_2d: [15.01975299992652, -2.9826768789456524],\n  },\n  {\n    id: '8',\n    parent_id: '4',\n    prompt: 'How does Julia compare to Python?',\n    response:\n      'Julia offers better performance and mathematical syntax, but has a smaller ecosystem than Python',\n    summary: 'Julia vs Python for ML',\n    embedding_2d: [0.31194656885226835, 10.155799442766826],\n  },\n  {\n    id: '9',\n    parent_id: '6',\n    prompt: 'What about FDA approval?',\n    response:\n      'ML medical tools require rigorous validation and regulatory approval processes',\n    summary: 'Regulatory aspects of ML in healthcare',\n    embedding_2d: [-6.16826307182544, -5.785657819336929],\n  },\n  {\n    id: '10',\n    parent_id: '7',\n    prompt: 'Compare PyTorch and TensorFlow',\n    response:\n      'PyTorch is more pythonic and flexible, while TensorFlow has better production tools',\n    summary: 'PyTorch vs TensorFlow comparison',\n    embedding_2d: [14.512387960830605, -1.5486041335450467],\n  },\n];\n\nimport Aside from '@components/prose/Aside.astro';\n\n<Aside type=\"tip\" mobileOnly>\n  The interactive visuals in the post don't play so nice on small devices. You\n  can still enjoy on your phone but be sure to check them out later on a bigger\n  screen.\n</Aside>\n\nI wrote about Conversation Branching on my main blog and I've been prototyping an LLM chat app called Delta that has first-class conversation branching.\nLLM conversations typically follow a linear path, making it unintuitive to explore alternative directions or recover from miscommunications.\nThis post is an interactive introduction to conversation branching but also an exploration into additional UX patterns that using a canvas can enable.\n\nHere are the basic primitives of conversation branching.\nClick any node on the left.\nThe conversation on the right updates to show the prompts and responses (since we're modeling an LLM conversation).\n\nimport ChatAndTree from './components/ChatAndTree';\n\n<ChatAndTree messages={messages} client:load />\n\nThe motivation behind conversation branching is multifold\n\nKeep the context clean\n\nLanguage models can be sensitive to typos or ambiguous phrases that send the conversation in the wrong direction.\nOften, if you notice the model is misunderstanding you, it's more effective to delete the previous conversation turn or update your message.\nChatGPT actually provides subtle support for branching with the message \"edit\" feature.\n\n!GIF showing ChatGPT multiple turns of a conversation with edits\n\nExplore parallel threads, maintaining conversation history\n\nWhile editing message and implicit branching helps keep the context clean, making branches visible and navigable adds additional depth.\nWe now can explore multiple lines of thinking from a shared starting premise, while maintaining the integrity of the context, keeping the LLM focused on the thing you care about, in each of the branches.\n\nimport ZoomableTree from './components/ZoomableTree';\n\n<ZoomableTree messages={moreMessages} client:load />\n\nWe're now exploring multiple lines of thought branching off of the original question \"What is machine learning?\".\nAs above, we could navigate any of these branches individually and linearly by clicking on a node, and branch off any node with a new message.\nHowever, the canvas has a ton of content, making it difficult to navigate or get an at-a-glance sense of what each node contains.\n\nLLMs can help us here.\nWe can summarize each node based on the prompt and response, then show summaries when zoomed out to make the content more digestible at a high level.\n\n<ZoomableTree messages={moreMessages} summaryZoomLevel={0.9} client:load />\n\nTry zooming in and out on either of the last two visualizations to see how the content adapts based on zoom level.\n\nSemantic clustering and exploration\n\nWith concise summaries, we can now add a new perspective to these conversations.\nIf we generate embeddings of the summaries, which gives us a list of floats for each summary, we can then apply Principal Component Analysis to reduce the many dimensions down to just two.\nFinally, we use those two floats as coordinates to position each of the conversation nodes, clustering them by their semantic similarity.\n\nHere are the results:\n\nimport ClusteredTree from './components/ClusteredTree';\n\n<ClusteredTree messages={moreMessages} client:load />\n\nBy my assessment, there are three main categories\n\n- ML and programming languages/development (bottom left)\n- ML and medicine/society (top left)\n- PyTorch (top right)\n\nEquidistant from the three clusters is the more generic, start message.\n\nI always find it interesting to explore latent space like this.\nDoing so with a conversation is a bit like blazing a trail and identifying new terrain, seeing where similar pieces fit together and finding unexplored areas in the negative spaces.",
  "canonicalUrl": "https://www.danielcorin.com/posts/2025/llm-conversation-branching/index"
}