liveBook · Manning

Chapter 8: NED with open LLMs and domain ontologies

What you will learn in chapter 8 of Knowledge Graphs and LLMs in Action

The introduction recalls scispaCy’s biomedical role in Chapter 7 and previews Chapter 8’s approach to named entity disambiguation.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction recalls scispaCy’s biomedical role in Chapter 7 and previews Chapter 8’s approach to named entity disambiguation.

Key terms: scispaCy, spaCy, pretrained models, biomedical domain

8.1 Understanding limitations of traditional NED systems

The section explains why scispaCy’s biomedical entity disambiguation is limited, using a Zika example to show its dependence on surrounding words.

Key terms: scispaCy, UMLS, canonical entities, reference knowledge base, contextual words, relationships and paths, disambiguation, Zika Virus Infection

8.2 Ingesting the domain ontology

The section describes how SNOMED is ingested into Neo4j and how its hierarchy supplies semantic types for disambiguation.

Key terms: SNOMED, Neo4j, names and aliases, relationships, SNOMED_IS_A, semantic types, first-level nodes, hierarchical structure

8.3 Setting up the model with Ollama and Llama 3.1 8B

This section explains why the NED system uses a locally deployed Llama 3.1 8B model and how Ollama makes that model accessible from Python.

Key terms: Ollama, Llama 3.1 8B, NED system, OpenAI Chat Completions API, Python

8.4 End-to-end NED process

This section traces an ontology-guided NED workflow from unstructured biomedical text to disambiguated entity matches.

Key terms: named entity recognition (NER), candidate selection (CS), full-text search, domain ontology, candidate disambiguation (CD), shortest path, ontology structure, disambiguated entity

8.4.1 Named entity recognition

This section shows how to use SNOMED categories in an LLM prompt to recognize medical entities, then add mention positions in post-processing.

Key terms: NER, SNOMED, predefined categories, prompt engineering, sentence, entities, ID, mention, label, JSON

8.4.2 Candidate selection

This section explains how candidate selection maps NER-detected mentions to possible concepts in a domain ontology using type-filtered full-text search.

Key terms: CS, NER, mentions, domain ontology, candidates, SNOMED, Neo4j, full-text search, LLM, $labels

8.4.3 Candidate disambiguation

This section explains how candidate disambiguation uses ontology connections and an LLM to select the best SNOMED concept for each entity mention.

Key terms: CD, co-occurring, domain ontology, candidate entities, shortest paths, Neo4j Graph Data Science (GDS), degree, hub nodes, translating paths to text, graph paths

8.5 Conclusions

The section concludes that combining domain ontologies, graph search, and open LLMs supports named entity disambiguation in complex domain texts.

Key terms: NED, domain ontologies, SNOMED, open and general-purpose LLMs, Llama 3.1 8B, scispaCy, Neo4j’s GDS library, shortest-path detection, full-text search, disambiguation

8.6 Summary

Concepts explained in this chapter

← Chapter 7: Named entity disambiguation Chapter 9: Machine learning on knowledge graphs: A primer approach →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.