microsoft / lida
- понедельник, 28 августа 2023 г. в 00:00:09
Automatic Generation of Visualizations and Infographics using Large Language Models
LIDA is a library for generating data visualizations and data-faithful infographics. LIDA is grammar agnostic (will work with any programming language and visualization libraries e.g. matplotlib, seaborn, altair, d3 etc) and works with multiple large language model providers (OpenAI, PaLM, Cohere, Huggingface). Details on the components of LIDA are described in the paper here and in this tutorial notebook. See the project page here for updates!.
Note on Code Execution: To create visualizations, LIDA generates and executes code. Ensure that you run LIDA in a secure environment.
LIDA treats visualizations as code and provides a clean api for generating, executing, editing, explaining, evaluating and repairing visualization code.
from lida import Manager, llm
lida = Manager(text_gen = llm("openai")) # palm, cohere ..
summary = lida.summarize("data/cars.csv")
goals = lida.goals(summary, n=2) # exploratory data analysis
charts = lida.visualize(summary=summary, goal=goals[0]) # exploratory data analysis
Setup and verify that your python environment is python 3.10
or higher (preferably, use Conda). Install the library via pip.
pip install lida
Once requirements are met, setup your api key. Learn more about setting up keys for other LLM providers here.
export OPENAI_API_KEY=<your key>
Alternatively you can install the library in dev model by cloning this repo and running pip install -e .
in the repository root.
LIDA comes with an optional bundled ui and web api that you can explore by running the following command:
lida ui --port=8080 --docs
Then navigate to http://localhost:8080/ in your browser. To view the web api specification, add the --docs
option to the cli command, and navigate to http://localhost:8080/api/docs
in your browser.
The fastest and recommended way to get started after installation will be to try out the web ui above or run the tutorial notebook.
Given a dataset, generate a compact summary of the data.
from lida import Manager
lida = Manager()
summary = lida.summarize("data/cars.json") # generate data summary
Generate a set of visualization goals given a data summary.
goals = lida.goals(summary, n=5) # generate goals
Generate, refine, execute and filter visualization code given a data summary and visualization goal. Note that LIDA represents visualizations as code.
# generate charts (generate and execute visualization code)
charts = lida.visualize(summary=summary, goal=goals[0], library="matplotlib") # seaborn, ggplot ..
Given a visualization, edit the visualization using natural language.
# modify chart using natural language
instructions = ["convert this to a bar chart", "change the color to red", "change y axes label to Fuel Efficiency", "translate the title to french"]
edited_charts = lida.edit(code=code, summary=summary, instructions=instructions, library=library, textgen_config=textgen_config)
Given a visualization, generate a natural language explanation of the visualization code (accessibility, data transformations applied, visualization code)
# generate explanation for chart
explanation = lida.explain(code=charts[0].code, summary=summary)
Given a visualization, evaluate to find repair instructions (which may be human authored, or generated), repair the visualization.
evaluations = lida.evaluate(code=code, goal=goals[i], library=library)
Given a dataset, generate a set of recommended visualizations.
recommendations = lida.recommend(code=code, summary=summary, n=2, textgen_config=textgen_config)
Given a visualization, generate a data-faithful infographic. This methods should be considered experimental, and uses stable diffusion models from the peacasso library. You will need to run pip install lida[infographics]
to install the required dependencies.
infographics = lida.infographics(visualization = charts[0].raster, n=3, style_prompt="line art")
Naturally, some of these limitations could be addressed by a much welcomed PR.
A short paper describing LIDA (Accepted at ACL 2023 Conference) is available here.
@inproceedings{dibia2023lida,
title = "{LIDA}: A Tool for Automatic Generation of Grammar-Agnostic Visualizations and Infographics using Large Language Models",
author = "Dibia, Victor",
booktitle = "Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 3: System Demonstrations)",
month = jul,
year = "2023",
address = "Toronto, Canada",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2023.acl-demo.11",
doi = "10.18653/v1/2023.acl-demo.11",
pages = "113--126",
}
LIDA builds on insights in automatic generation of visualizaiton from an earlier paper - Data2Vis: Automatic Generation of Data Visualizations Using Sequence to Sequence Recurrent Neural Networks.