Entities and relations from text, by hand
Fixed phrase patterns stand in for a model extractor. Note the skipped sentence: a missed pattern is a missing link, and nothing fails loudly.
Some questions need facts that sit in different passages and are connected by who or what they mention. Extract entities and relations into a graph, then follow the links hop by hop to collect the passages a chain of facts needs.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write neighbours(node, triples) that returns a list of (relation, other) pairs for every triple whose left side is node, in the order they appear. Print the neighbours of Harbour shop and of Northside.
Write hops_between(start, goal, triples, max_hops) that follows outgoing links breadth first and returns the number of hops needed to reach goal, or None if it takes more than max_hops. Print the result for Maria to "charging station" with limits 2 and 3.
Explain it without notes
What is a multi-hop question, and why does ordinary chunk search handle it badly?
Describe how a graph is built from text and how a question uses it.
What goes wrong with extraction, and how would you notice?
When would you decide a graph is not worth building?
Expected output
(Maria) -manages-> (Harbour shop)
(Harbour shop) -is_in-> (Northside)
(Northside) -has-> (charging station)
(Dev) -manages-> (Hilltop shop)
(Hilltop shop) -is_in-> (Eastgate)
skipped: Priya looks after the Docks shop.
5 triples from 6 sentences