Skip to main content

A query language for language models.

Project description

Logo

LMQL

A query language for programming (large) language models.
Read The Paper »

Explore Examples · Playground IDE · Report Bug

Full Code Release Coming Soon

LMQL is a query language for large language models (LLMs). It facilitates LLM interaction by combining the benefits of natural language prompting with the expressiveness of Python. With only a few lines of LMQL code, users can express advanced, multi-part and tool-augmented LM queries, which then are optimized by the LMQL runtime to run efficiently as part of the LM decoding loop. To illustrate, consider the following LMQL program:

lmql-overview

Explore More Examples »

About LMQL

Large language models have demonstrated outstanding performance on a wide range of tasks such as question answering and code generation. On a high level, given an input, a language model can be used to automatically complete the sequence in a statistically-likely way. Based on this, users prompt these models with language instructions or examples, to implement a variety of downstream tasks. Advanced prompting methods can even imply interaction between the language model, a user, and external tools such as calculators. However, to obtain state-of-the-art performance or adapt language models for specific tasks, complex task- and model-specific programs have to be implemented, which may still require ad-hoc interaction.

Based on this, we present the novel idea of Language Model Programming (LMP). LMP generalizes language model prompting from pure text prompts to an intuitive combination of text prompting and scripting. Additionally, LMP allows constraints to be specified over the language model output. This enables easy adaption to many tasks, while abstracting language model internals and providing high-level semantics.

To enable LMP, we implement LMQL (short for Language Model Query Language), which leverages the constraints and control flow from an LMP prompt to generate an efficient inference procedure that minimizes the number of expensive calls to the underlying language model.

We show that LMQL can capture a wide range of state-of-the-art prompting methods in an intuitive way, especially facilitating interactive flows that are challenging to implement with existing high-level APIs. Our evaluation shows that we retain or increase the accuracy on several downstream tasks, while also significantly reducing the required amount of computation or cost in the case of pay-to-use APIs.

Code Release and Stability

We plan to release the LMQL source code soon, together with a packaged release on PyPi. Until then, feel free to experiment with LMQL in the web-based Playground IDE, which includes the fully-featured LMQL runtime and compiler.

The current version of LMQL should be considered as an alpha release. Please report bugs and feature requests as GitHub Issues.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lmql-0.0.2.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lmql-0.0.2.1-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file lmql-0.0.2.1.tar.gz.

File metadata

  • Download URL: lmql-0.0.2.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for lmql-0.0.2.1.tar.gz
Algorithm Hash digest
SHA256 b8402672bf8369b4b23bae257f925930763c11423cc22db5f65fcf44cc8b4cd3
MD5 a4a07168621ce6a6ce904254a38de600
BLAKE2b-256 6b39afc7db7bcabbfa8632a5b449a48437f350a2efadf367e76f73317076ba14

See more details on using hashes here.

File details

Details for the file lmql-0.0.2.1-py3-none-any.whl.

File metadata

  • Download URL: lmql-0.0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for lmql-0.0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a45956bec9cb00732168d0690c2c0f86cf41cfdee2c403c76482f312f9a91eb
MD5 1c77acdec862f15f54df838e48e5f6da
BLAKE2b-256 57525b472281f846a3c155648bfae3777cf328682f3679f091b617d2a37dd279

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page