Extract named entities from text

Identify and extract people, organizations, locations, dates, and other entities from text using LLMs.

Text · Notebook · Updated

Colab runs it in your browser. If it calls a model provider, it asks for that provider's API key in a cell.

How it works

You use structured output to get entities in a consistent JSON format. The entities are stored as JSON columns that you can query and filter.

What it covers

  • Extract entities as structured JSON
  • Use OpenAI's structured output for reliable parsing
  • Access extracted entities as queryable columns

What it uses

Install
terminal
pip install pixeltable openai
Environment variables it names
OPENAI_API_KEY
Pixeltable calls
openai.chat_completions()pxt.create_table()add_computed_column()insert()

A look at the code

text-extract-entities.ipynb
# Add entity extraction column
extraction_prompt = (
'Extract all named entities from the following text:\n\n'
+ articles.content
)
articles.add_computed_column(
extraction_response=chat_completions(
messages=[{'role': 'user', 'content': extraction_prompt}],
model='gpt-4o-mini',
model_kwargs={'response_format': entity_schema},
)
)

One cell of the notebook, copied as it is. Open it in Colab for the rest.

Browse all 103