google/langextract
A Python library for extracting structured information from unstructured text using LLMs with precise source grounding and interactive visualization.
What it solves
LangExtract 是一个 Python 库,旨在从非结构化文本文件中提取结构化信息。它解决了将混乱、自由形式的文本(如临床笔记或报告)转化为有组织数据的难题,同时确保每条提取的信息都有来源文本作为依据,便于验证。
How it works
该库使用大语言模型(LLM)和 few‑shot 提示策略。用户通过提供提示词和少量高质量示例,定义文本如何映射为结构化实体。为处理长文档,它采用文本分块、并行处理和多轮提取的方式来提升召回率。
Who it’s for
它面向需要将非结构化文本转换为结构化数据集的开发者和研究者,且无需微调模型。特别适用于处理领域特定文档,如医学报告或文学分析,因为这些场景要求可追溯性和精确性。
Highlights
- Precise Source Grounding: Maps extractions to exact character intervals in the source text for visual traceability.
- Reliable Structured Outputs: Uses controlled generation (in supported models) and few-shot examples to enforce consistent schemas.
- Long Document Optimization: Uses parallel processing and multiple passes to overcome the "needle-in-a-haystack" problem.
- Interactive Visualization: Generates self-contained HTML files to visualize extracted entities within their original context.
- Flexible LLM Support: Compatible with cloud models (Gemini, OpenAI) and local models via Ollama.
- Extensible Provider System: Allows users to add custom LLM providers via a plugin system.