RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Eruo Fredoline
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /Courses
  5. /Advanced NLP with Local Models
  6. /Ch. 2
Advanced NLP with Local Models

02. Named Entity Recognition

Chapter 2 of 18 · 15 min
KEY INSIGHT

Local LLMs provide flexible entity schemas without model retraining, but prompt stability degrades when entity definitions contain ambiguity. Explicit type boundaries and boundary markers improve extraction consistency.

Named Entity Recognition identifies and classifies specific elements within text—organization names, dates, monetary values, and geographic locations. Local LLMs approach NER as a text generation task where structured output follows input-context specifications.

Prompting strategies for NER typically take the form of instruction-completion pairs. A well-structured prompt specifies entity types, output format preferences, and handling rules for ambiguous cases. Entity types might include PERSON, ORG, DATE, GPE, and FACILITY, though specific schemas vary by application domain.

import ollama

def extract_entities(text, model="llama3"):
    prompt = f"""Extract all named entities from the text below.
    Return entities as a structured list with type and value.
    
    Entity types: PERSON, ORG, GPE, DATE, MONEY, FACILITY
    
    Text: {text}
    
    Entities:"""
    
    response = ollama.generate(
        model=model,
        prompt=prompt,
        options={'temperature': 0.1}
    )
    return response['response']

text = "Apple Inc. announced on January 15, 2024 that its Seattle office will expand to 500 employees."
entities = extract_entities(text)
print(entities)

Handling complex cases requires explicit instructions. Nested entities—where one entity contains another—appear frequently in news articles: "The White House announced policy changes." Here, "The White House" is an ORG while "House" might be classified as a building (FACILITY) in other contexts. Resolution strategies must be specified in prompt templates.

Overlapping entity types present additional challenges. The phrase "French technology companies" contains both a nationality (GPE-derived) and an organization category. Prompt engineering must specify priority rules for type assignment.

Local verification checkpoint

Run the smallest example from this chapter in a local workspace and record the package version, runtime, data path, and observed output. If the result depends on model size, vector count, CPU/GPU backend, or available memory, note that constraint beside the exercise so the lesson remains reproducible.

EXERCISE

Design a custom entity schema for legal contract analysis. Implement extraction with handling for nested and overlapping entities. Evaluate precision and recall on a annotated test set.

← Chapter 1
NLP with LLMs vs Traditional Approaches
Chapter 3 →
NER Prompting vs Fine-Tuning