Giter Club home page Giter Club logo

lean-gptf's Introduction

lean-gptf

This repository lets you use GPT-f to suggest tactics based on the goal state. The current model is trained on 80% of the tactic proofs in mathlib (commit 33483a3de6d91066e0fb9efd6aa4c0275d7ac44c).

Setup

# download pre-built binaries and build the project
leanpkg configure && leanpkg build

After Lean is finished compiling, try commenting out the proofs in src/example.lean and calling gptf inside the begin ... end blocks. Make sure your API key is set up (see below). For example,

example {α} (a : α) : a = a :=
begin
  gptf,
end

should succeed with a message like this:

Successes:
----------
Try this:  refl

All predictions:
----------------
Try this:  refl

Importing lean-gptf as a dependency for your own project

leanpkg add jesse-michael-han/lean-gptf

leanpkg configure

leanproject get-mathlib-cache

leanpkg build

then remember to import tactic.gptf at the top.

Accessing the OpenAI API

GPT-f is a generative language model trained by OpenAI. It is available over the OpenAI API using an API key. It receives a formatted tactic state as a prompt and will emit a list of tactics to try. The gptf tactic will try these tactics and return the ones that succeed as Try this: ... suggestions.

To get an API key, apply to join the beta here: https://bit.ly/3nNWMyB

Once you have recieved an API key, either add it as an OS environment variable called OPENAI_API_KEY

# ~/.zshenv, /etc/environment, etc.
export OPENAI_API_KEY=<key goes here> # you may have to log out and back in to get this to work

or you can paste the key directly in to the Lean document:

-- located in ./src/tactic/gptf/gptf.lean

/- set to `some $KEY` if you don't want to mess with environment variables
   WARNING: do _not_ leave your key in committed source code -/
   private meta def OPENAI_API_KEY : option string := none

Usage

import tactic.gptf

lemma my_lemma {α} (a : α) : a = a :=
begin
  gptf {n := 32, temp := 1.0} -- this will query the server and return a set of 'try this' commands.
end

Options

  • temperature: Controls the randomness of the predictions; defaults to 1.0. Decrease to make the model's predictions more deterministic.
  • n: Number of predictions to try at once.

Considerations

The gptf tactic will query a model via the OpenAI API using curl. This query will be re-executed every time Lean compiles the tactic, and will count towards your API key rate limit. Thus, to avoid hitting the rate-limit and being throttled, please:

  • try not to have more than one uncommented gptf in a live Lean file at a time
  • replace calls to gptf by successful predictions whenever possible

Also remember that even if the system doesn't progress the goal, you may be able to see clues of how to progress by looking at the suggestions which fail given in the 'Predictions' list. Currently, the model tends to predict long chains of rewrites; often, the first few rewrites in the chain will succeed.

lean-gptf's People

Contributors

alexjbest avatar edayers avatar jesse-michael-han avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.