This is a fantastic and ambitious idea! You're essentially describing a personalized knowledge graph-based learning system with continuous mastery tracking. Let me break down how to implement this systematically.
Core Architecture Components
1. Semantic Heatmap Representation
Instead of thinking of it as a literal heatmap, think of it as a knowledge graph with continuous mastery scores:
class KnowledgeNode:
def __init__(self, content_id, text, embedding, mastery=0.0):
self.content_id = content_id # e.g., "chapter_3_section_2_paragraph_5"
self.text = text
self.embedding = embedding # from sentence transformer
self.mastery = mastery # 0.0 to 1.0
self.prerequisites = [] # list of content_id references
self.dependencies = [] # concepts that depend on this
self.similar_concepts = [] # cosine similarity neighbors
Building the graph:
2. Continuous Mastery Propagation
Implement mastery diffusion through the graph:
def propagate_mastery(graph, updated_node_id, delta_mastery):
"""Propagate mastery changes through prerequisites and similar concepts"""
node = graph[updated_node_id]
# Prerequisite effect: if you master something, prerequisites become more valuable
for prereq_id in node.prerequisites:
prereq = graph[prereq_id]
prereq.mastery = min(1.0, prereq.mastery + delta_mastery * 0.3)
# Similarity effect: similar concepts get slight boosts
for similar_id, similarity_score in node.similar_concepts:
similar = graph[similar_id]
similar.mastery = min(1.0, similar.mastery + delta_mastery * similarity_score * 0.2)
# Dependency effect: mastering prerequisites makes dependent concepts more accessible
for dep_id in node.dependencies:
dep = graph[dep_id]
prereq_mastery_avg = np.mean([graph[pid].mastery for pid in dep.prerequisites])
dep.mastery = min(dep.mastery, prereq_mastery_avg * 0.8) # Cap at prerequisite level
3. Gap Identification & Question Generation
Finding knowledge gaps:
def find_optimal_gaps(graph, user_mastery_threshold=0.3, max_prereq_threshold=0.7):
"""Find concepts that are just beyond current mastery but have sufficient prerequisites"""
candidates = []
for node_id, node in graph.items():
if node.mastery < user_mastery_threshold: # This is a gap
# Check if prerequisites are sufficiently mastered
if node.prerequisites:
prereq_mastery = np.mean([graph[pid].mastery for pid in node.prerequisites])
if prereq_mastery > max_prereq_threshold:
candidates.append((node_id, node.mastery, prereq_mastery))
else:
# No prerequisites - always fair game
candidates.append((node_id, node.mastery, 1.0))
# Sort by optimal learning zone (not too easy, not too hard)
candidates.sort(key=lambda x: abs(x[1] - 0.4)) # Target ~40% mastery
return candidates[:5] # Top 5 candidates
Passing context to LLM:
def generate_question_prompt(target_node, graph, context_window=3):
"""Create rich context for LLM question generation"""
# Get the target content
main_content = target_node.text
# Get prerequisite context
prereq_context = []
for prereq_id in target_node.prerequisites[:2]: # Top 2 prerequisites
prereq_context.append(f"Prerequisite: {graph[prereq_id].text[:200]}...")
# Get similar concept context
similar_context = []
for similar_id, _ in target_node.similar_concepts[:2]:
similar_context.append(f"Related: {graph[similar_id].text[:200]}...")
prompt = f"""
You are a master tutor helping a student learn from a book.
TARGET CONCEPT TO TEST:
"{main_content}"
RELEVANT BACKGROUND KNOWLEDGE (student has mastered these):
{chr(10).join(prereq_context)}
RELATED CONCEPTS (for context):
{chr(10).join(similar_context)}
Generate 2-3 Socratic questions that:
1. Test understanding of the target concept
2. Connect it to the background knowledge
3. Are at the right difficulty level (not too easy, not impossible)
4. Encourage deep thinking rather than rote recall
Format as a JSON array of questions.
"""
return prompt
4. Embedding Integration Strategy
Use embeddings for multiple purposes:
- Similarity edges: Pre-compute cosine similarities between all chunks
- Dynamic gap finding: When looking for gaps, you can also search embedding space for "nearby" low-mastery concepts
- LLM context retrieval: When generating questions, use embeddings to find the most relevant context beyond just graph edges
# Example: Find semantically similar gaps
def find_semantic_gaps(graph, target_embedding, mastery_threshold=0.3):
gaps = []
for node_id, node in graph.items():
if node.mastery < mastery_threshold:
similarity = cosine_similarity(target_embedding, node.embedding)
gaps.append((node_id, similarity))
return sorted(gaps, key=lambda x: x[1], reverse=True)[:3]
5. System Workflow
class SemanticLearningCompanion:
def __init__(self, book_text):
self.graph = self.build_knowledge_graph(book_text)
self.session_history = []
def build_knowledge_graph(self, book_text):
# 1. Chunk text
chunks = self.chunk_book(book_text)
# 2. Generate embeddings
embeddings = self.embed_chunks(chunks)
# 3. Build initial graph structure
graph = self.create_nodes(chunks, embeddings)
# 4. Extract relationships using LLM
self.extract_prerequisites(graph)
self.build_similarity_edges(graph)
return graph
def next_study_session(self):
# Find optimal gaps
gaps = self.find_optimal_gaps()
if not gaps:
return "No suitable gaps found - consider reviewing or expanding content"
target_node = self.graph[gaps[0][0]]
# Generate question prompt
prompt = self.generate_question_prompt(target_node, self.graph)
# Get LLM response
questions = self.llm.generate(prompt)
return questions, target_node.content_id
def update_mastery(self, content_id, performance_score):
"""performance_score: 0.0 (failed) to 1.0 (mastered)"""
old_mastery = self.graph[content_id].mastery
self.graph[content_id].mastery = performance_score
# Propagate changes
delta = performance_score - old_mastery
self.propagate_mastery(content_id, delta)
Advanced Considerations
Temporal Dynamics
- Add forgetting curves: mastery decays over time unless reinforced
- Track confidence vs. actual performance to detect overconfidence
Multi-modal Content
- For technical books, extract formulas, diagrams, code examples as separate nodes
- Use specialized embeddings (e.g., CodeBERT for code snippets)
Adaptive Granularity
- Start with coarse chunks (sections), then drill down to paragraphs when mastery is high
- Merge very similar low-mastery concepts to avoid overwhelming the student
Evaluation Metrics
- Track learning efficiency: mastery gain per study session
- Monitor coverage: percentage of book with mastery > threshold
- Measure retention: delayed retesting of previously mastered concepts
This architecture gives you a truly semantic, continuous, and personalized learning system. The key insight is that your "heatmap" is really a dynamic knowledge graph with continuous edge weights and node states, where embeddings provide the semantic backbone and LLMs provide the intelligent tutoring interface.
Would you like me to elaborate on any specific component, like the prerequisite extraction algorithm or the mastery propagation math?