Large Language Models (LLMs) are emerging as an extremely capable technology for powering information extraction applications.
Classical solutions to information extraction rely on a combination of people, (many) hand-crafted rules (e.g., regular expressions), and custom fine-tuned ML models.
Such systems tend to get complex over time and become progressively more expensive to maintain and more difficult to enhance.
LLMs can be adapted quickly for specific extraction tasks just by providing appropriate instructions to them and appropriate reference examples.
This guide will show you how to use LLMs for extraction applications!
ApproachesThere are 3 broad approaches for information extraction using LLMs:
Tool/Function Calling Mode: Some LLMs support a tool or function calling mode. These LLMs can structure output according to a given schema. Generally, this approach is the easiest to work with and is expected to yield good results.
JSON Mode: Some LLMs are can be forced to output valid JSON. This is similar to tool/function Calling approach, except that the schema is provided as part of the prompt. Generally, our intuition is that this performs worse than a tool/function calling approach, but don't trust us and verify for your own use case!
Prompting Based: LLMs that can follow instructions well can be instructed to generate text in a desired format. The generated text can be parsed downstream using existing Output Parsers or using custom parsers into a structured format like JSON. This approach can be used with LLMs that do not support JSON mode or tool/function calling modes. This approach is more broadly applicable, though may yield worse results than models that have been fine-tuned for extraction or function calling.
Head to the quickstart to see how to extract information using LLMs using a basic end-to-end example.
The quickstart focuses on information extraction using the tool/function calling approach.
How-To GuidesHead to the Guidelines page to see a list of opinionated guidelines on how to get the best performance for extraction use cases.
Reference Applicationlangchain-extract is a starter repo that implements a simple web server for information extraction from text and files using LLMs. It is built using FastAPI, LangChain and Postgresql. Feel free to adapt it to your own use cases.
Other ResourcesRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4