Message Boards Message Boards

Using GPT-4 to generate Wolfram Language code

Posted 1 year ago

POSTED BY: Yaroslav Bulatov
10 Replies
Posted 1 year ago

Hi Anton,

Can open AI mode be used with Wolfram Desktop?

POSTED BY: Cogni Curious

Yes.

  1. Install the paclets "OpenAILink" and "OpenAIMode".
  2. Follow the setup instructions in "OpanAILink".
  3. Run Needs["AntonAntonovOpenAIMode"].
  4. Run OpenAIMode[] in a desired notebook

More details are given in this discussion.

POSTED BY: Anton Antonov

The main challenge I have found is getting ChatGPT 4 to produce correct vectorized code. Even given quite short procedural code snippets, it fails in repeated attempts to vectorize them correctly.

This isn't a failing specific to the Wolfram language, however: the same thing occurs with Python and Matlab.

What I am hoping is that Wolfram will eventually provide api connectivity between ChatGPT 4 and the Wolfram documentation library, which is organized very systematically and is replete with examples of function usage. Given this, and an ability to test its own code, ChatGPT should be able to improve its performance with WL programming, over time.

POSTED BY: Jonathan Kinlay

I've had about 50% rate of success at correct vectorization. One of the issues is that transformer models use the same amount of compute per prompt. Hence, harder questions need several prompts to get right.

POSTED BY: Yaroslav Bulatov

Did anyone try ChatGPT Wolfram plugin that was announced recently?

https://writings.stephenwolfram.com/2023/03/chatgpt-gets-its-wolfram-superpowers

QUOTE: ...given some candidate code, the Wolfram plugin can run it, and if the results are obviously wrong (like they generate lots of errors), ChatGPT can attempt to fix it, and try running it again. (More elaborately, ChatGPT can try to generate tests to run, and change the code if they fail.)

POSTED BY: Sam Carrettie

I asked GPT-4 to "write a short tutorial with examples of CombinedEntityClass in the Wolfram Language. The result looked believable, but it was mostly made-up: EntityClass expression were incomplete, some Entity types non-existent etc. A few code examples are shown below.

usStates = EntityClass["AdministrativeDivision", "UnitedStatesStates"];
canadaProvinces = 
  EntityClass["AdministrativeDivision", "CanadaProvinces"];
combinedClass = CombinedEntityClass[{usStates, canadaProvinces}];

instruments = EntityClass["MusicalInstrument"];
manufacturers = 
  EntityClass["Organization", "MusicalInstrumentManufacturers"];
combinedClass = CombinedEntityClass[{instruments, manufacturers}];

    physicsLaureates = EntityClass["Person", "NobelPrizePhysicsLaureates"];
chemistryLaureates = 
  EntityClass["Person", "NobelPrizeChemistryLaureates"];
combinedClass = 
  CombinedEntityClass[{physicsLaureates, chemistryLaureates}];

I think GPT-4 needs a Wolfram-U online course first :)

POSTED BY: Dave Middleton

Another task I've had success with is "make this code faster". It's sometimes able to rewrite the inefficient For loops in terms of vectorized matrix expressions

POSTED BY: Yaroslav Bulatov
Posted 1 year ago

I attempted to use GPT-3 and the Codex family of models to generate Mathematica code, but I was not satisfied with most of the results. GPT-4 seems to be better. Using "You are a Mathematica programmer" as the system instruction and your prompt, I got a piece of code that was almost correct, only needing a change of := to =. However, when I used the prompt "Write a function that will compute the motion of a frictionless puck inside a square", the returned code was syntactically correct (it ran) but it computed the wrong thing. The code had hints of the Katok-Zemlyakov construction, but messed it up.

POSTED BY: Ronnie M

Indeed, it seems most useful when it's easy to check for correctness. IE, using it to generate visualization code that you can run.

I've asked to implement fast algorithm to compute Tr(A+B)^n for matrices A,B, and it made an algorithm which assumed matrix multiplication is commutative.

POSTED BY: Yaroslav Bulatov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract