Module 2 of 3 · 45 min
DeepSeek R1 Reasoning Tokens & Chain-of-Thought
Work with DeepSeek R1 deliberate reasoning streams, parse thinking tokens, and integrate structured output verification.
Core concept
By the end
You will be able to
- Parse and handle DeepSeek R1 reasoning output tokens and final answers.
- Understand reinforcement learning cold-start mechanisms without supervised fine-tuning.
- Implement structured output parsing while handling variable-length reasoning traces.
01
Handling the Reasoning Stream
DeepSeek R1 emits an explicit internal reasoning chain (often encapsulated in `<think>...</think>` tags) prior to emitting the final response.
Application developers can stream thinking traces to user interfaces for transparency or filter them on backend pipelines while validating final structured JSON.
Extract Reasoning Trace and Final Output
python
import re
def parse_r1_response(raw_text: str) -> dict:
think_match = re.search(r"<think>(.*?)</think>", raw_text, re.DOTALL)
reasoning = think_match.group(1).strip() if think_match else ""
final_answer = re.sub(r"<think>.*?</think>", "", raw_text, flags=re.DOTALL).strip()
return {"reasoning": reasoning, "answer": final_answer}Practice activity
Benchmark DeepSeek R1 on Complex Mathematical Logic Problems
- Submit 10 complex logic puzzles to DeepSeek R1 and DeepSeek V3.
- Record reasoning trace length, token count, and final answer correctness.
What to produce
- Benchmarking results table showing accuracy vs thinking token overhead.
Reflect before continuing
When is deliberate multi-step reasoning worth the latency and token cost over immediate greedy decoding?
Evidence
Sources and verification
- DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement LearningArXiv · verified 2026-08-22
Knowledge check
Make it stick.
Choose the strongest answer for each question. Your attempts become part of your account transcript.