How davidberenstein1957/concise-concepts works
Concise Concepts is a Python library (published to PyPI) that provides few-shot Named Entity Recognition (NER) by:
• taking a small concept dictionary (labels → example terms),
• expanding terms via embedding similarity (Gensim / Sense2Vec / keyed vectors),
• generating rule-based matching patterns,
• injecting them into a spaCy EntityRuler (and optionally fuzzy matching),
• optionally computing entity scores (similarity of matched entity to concept group).
So your “system” is not a web service—it's a library embedded inside a user’s Python process, typically inside a spaCy pipeline.
From the tree:
• concise_concepts/
• __init__.py
• public API surface (exports Conceptualizer, registers spaCy component entrypoint)
• conceptualizer/Conceptualizer.py
• the core engine (pattern generation, similarity expansion, scoring, integration into spaCy)
• examples/
• usage patterns: spaCy pipeline mode, standalone mode, custom embedding models/paths
• tests/test_model_import.py
• import + integration sanity check (packaging correctness)
• pyproject.toml, setup.cfg
• packaging/build metadata
• .github/workflows/*
• CI for tests and publish
The README describes two primary usage modes:
spaCy Pipeline Component mode (most important)
User does:
• nlp = spacy.load(...)
• nlp.add_pipe("concise_concepts", config={...})
• doc = nlp(text) → doc.ents enriched
Key runtime fact: Concise Concepts is a spaCy pipeline component that configures and populates an EntityRuler with patterns derived from embeddings + seed terms.
Standalone mode
User does:
• conceptualizer = Conceptualizer(nlp, data, model)
• conceptualizer.nlp(text).ents
Key runtime fact: the library can be used without repeatedly reloading large models; user passes an embedding model object directly.
What to put
• “User Application / Notebook / Script”
• “spaCy”
• “Concise Concepts (this library)”
• “Embedding Model Provider”
• examples: gensim.downloader, local keyed vectors, sense2vec
• Optional: “Filesystem” (for json_path patterns export)
• User → spaCy: constructs pipeline, calls nlp(text)
• User → Concise Concepts: provides data config, options, optionally model_path/model
• Concise Concepts → Embedding Models: similarity queries / nearest neighbors
• Concise Concepts → Filesystem: write generated patterns JSON
Notes to annotate
• Runs in-process (no network boundary unless embedding download is used)
• Output is doc.ents + optional ent._.ent_score
User Code
• supplies: data, config, text
spaCy Pipeline
• base pipeline (tokenizer, tagger, parser, etc. depending on loaded model)
Concise Concepts spaCy Component
• installed via nlp.add_pipe("concise_concepts", config=...)
Conceptualizer Core
• pattern builder + scoring logic
EntityRuler
• pattern matching + entity injection into Doc
Embedding Model
• Gensim KeyedVectors/FastText/Word2Vec, Sense2Vec, etc.
Optional Fuzzy Matcher
• README mentions fuzzy matching via spaczz (treat as conditional subcomponent)
Patterns JSON Output
• json_path export for interpretability/debugging
• data (label -> seed terms) → Conceptualizer Core
• Conceptualizer Core → Embedding Model: “get similar terms / similarity scores”
• Conceptualizer Core → Pattern Generator: “build token/phrase patterns”
• Pattern Generator → EntityRuler: “load patterns”
• spaCy pipeline executes:
• Text → Tokenization → (other components) → Concise Concepts Component → EntityRuler match → Doc.ents
• If ent_score=True:
• Matched entity spans → Embedding Model similarity → attach ent._.ent_score
Key config knobs to label on the edges
• exclude_pos, exclude_dep, include_compound_words, case_sensitive affect pattern construction/matching
• topn affects expansion breadth per concept group
• fuzzy=True routes matching through fuzzy mechanism
• model_path or model determines embedding backend
concise_concepts/conceptualizer/Conceptualizer.py and how it connects outward.
• Conceptualizer (central class)
• “Similarity/Expansion Engine”
• “Scoring Engine” (conditional if ent_score=True)
• “spaCy Component Adapter” (registration + nlp.add_pipe integration)
• “EntityRuler Adapter” (create/populate patterns)
• “I/O: JSON Pattern Exporter”
• Conceptualizer uses spaCy Language/Doc APIs
• Conceptualizer uses embedding model API
• Conceptualizer produces patterns → EntityRuler
• Conceptualizer optionally writes JSON
Why this level matters here: this library’s “architecture” is mainly the transformation pipeline:
seed terms → expanded vocabulary → matcher patterns → entity spans (+ scores)
Important architectural patterns/design principles to call out
• Adapter pattern: the library adapts external embedding model interfaces into a consistent “similarity lookup” role.
• Pipeline component architecture (spaCy): works as a composable pipeline stage, not as a model trainer.
• Rule generation + interpretability: explicit pattern export (json_path) is part of the design.
• Configuration-driven behavior: most behavior is driven by config passed to nlp.add_pipe(...).
• Python library (packaged via pyproject.toml / setup.cfg)
• spaCy (EntityRuler, pipeline component)
• Gensim / Sense2Vec (embedding backends)
• spaczz (conditional fuzzy matching)