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.