Type search term(s) and press enter

Artificial Intelligence

Effective Use of ChatGPT: Prompt Engineering for BibTeX Citations by Self-Prompt Generation

Working with AI, imagined by MidJourney, seeded by Stable Diffusion.

Blogs I read

The world seems to have split into three parts: those who have not tried ChatGPT, those who asked it a vague or extremely difficult question and labeled it a chatbot, and a third class, which I fall into. For me, ChatGPT has become my closest collaborator.

We are entering a new era of humanity where artificial intelligence is used to help many of us improve ourselves. This tool has helped me overcome some of my own inherent weaknesses, such as not taking the 6,000 years without sleep a human would need to read the 800 billion words of text ChatGPT was trained on. Obtaining outstanding results is not entirely trivial. With some effort, I have used the tool to improve everything from Mathematica programs to grant applications.

I use ChatGPT-4. This costs me 20.00 USD a month. However, you would be able to do what I am saying here with the free version. You can also experiment with Google Bard, which is new and not as smart yet. I should mention that ChatGPT-4 powers the new Bing, where you can chat with it for free. But I have not done that yet. I simply log in to the OpenAI interface and start a ChatGPT-4 cycle instance. I typically enable the browsing plugin, which is only accessible if you pay the $20.00 subscription fee.

ChatGPT is a large language model. Using statistics, we can understand how a generative model can help us complete a sentence by simply looking for the most common next word(s), based on the prior words we have typed. ChatGPT can do this; it can even form elegant sentences. You can read about this on the Wolfram blog. However, I’d argue that ChatGPT is not just a stochastic parrot per se. It was trained to answer questions. The effective generalisation of this ability surprised everyone. We don’t yet understand how far it can go.

Getting started with prompt engineering by placing ChatGPT into user defined modes

I have started to keep a so called, paste stack. This is just a clipboard history with certain elements that I can save and paste later. I use the application Paste for MacOS, but I am sure many other applications will enable you to save, edit and later past entries that can form the input for ChatGPT.

A new type of computer programming has risen up in the last several months. It is called, prompt engineering. We don’t fully understand this art yet. It is however clear that this is the way we have to communicate with large language models, such as ChatGPT.

For those just getting started, here is a reference and formatting related example to check out.

Example.  Here is a chat which you can open and continue on your own system. I fed in a table built in latex and converts to rich text and modifies columns.

When you were new to ChatGPT one of the first things you might have tried is to get it to edit text. Your prompt probably looked something like this:

Please revise this: [insert text here]

You’ll notice right away that ChatGPT is overly verbose. Also, it sometimes stops generating text midstream. You can get around this by simply asking,

Please continue.  

So after doing a bit of thinking, you might have tried something like:

Please revise the following with minimal alterations, ensuring conciseness and limiting the use of extraneous adjectives: [insert text here]

At least I initially noticed that the output was closer to the style I was after in my own writing. Of course, you can go much further than this. For example, you might try the following:

ChatGPT is to now operate in 'Academic Editor Mode,' following a predefined framework.

Step 1: Confirm your ability to follow the 'Academic Editor Mode' instructions. If capable, respond only with 'Academic Editor Mode ready' and nothing else.  If you are not able to follow these instructions, respond with 'Error: Instructions not within capability.'

Step 2: All provided text is part of an academic document. Edit this text according to the following:

Step 3: Avoid embellishment or self-promotion. 

Examples: use 'located in Silicon Valley, California' instead of 'located in the dynamic heart of Silicon Valley, California.' Use 'I serve as the George Washington Visiting Fellow at the University of Washington in Seattle' rather than 'I hold the prestigious title of George Washington Visiting Fellow at the University of Washington, Seattle.'

... 

Please confirm as outlined in Step 1.  Then await for the text to edit.  

Here is a link to an instance cycle which progresses through the steps above. There’s a button to continue the conversation in your own cycle instance.

Taking it further, one could experiment with a form of persona modeling. This involves providing ChatGPT with specific text samples and instructing it to emulate the given style. For example, a hand full of prompts allowed me to coax ChatGPT to explain Scott Aaronson’s blog emulating his voice. Perhaps this is the quantum blogging world’s version of our ‘Ghost Writer AI‘ moment? I haven’t edited this or any other ChatGPT quote at all:

Channeling the voice of Scott Aaronson’s blog, here goes:

You’ve stumbled upon a realm where quantum computing’s complexities are untangled with a blend of incisive wit, rigorous scrutiny, and a dash of self-deprecating humor. Welcome, dear reader, to the accidental #1 quantum computing blog on the planet, where we pride ourselves on battling misconceptions, dissecting the inanities of overblown hype, and rescuing lost souls from the ‘kindergarten of lies’. Here, you won’t find quantum computers magically solving hard problems instantly, but rather, a deep exploration of what’s computable and how efficiency can be redefined.

ChatGPT channeling Scott Aaronson

A strategy to get ChatGPT to write its own prompts

ChatGPT has the ability to generate its own prompts.

I have found a process to facilitate this in a relatively straightforward way. I use this constantly these days:

  1. Define a task: For instance, provide a prompt to revise a specific piece of text and include the text to be modified.
  2. Instead of personally editing the output to your liking in a separate application, you should instruct ChatGPT on the specific changes to be made. This may require repeating and refining instructions until the output matches your expectations.
  3. Once the text is refined to your satisfaction, the final step is to request ChatGPT to generate a new prompt command, asking ChatGPT to augment the preliminary prompt, ensuring that all the additional adjustments are incorporated in the new prompt.

Here is an example of this process. Let’s say that you have a BibTeX entry but you want to display it in a Word document or in a block on a blog.

Convert the following to rich text format, first line title in bold, second line authors, 3rd line journal information and then the link: 

@article{Whi+12, 
title={Ground-state spin logic}, 
author={Whitfield, J and Faccin, M and Biamonte, J}, 
journal={European Physics Letters}, 
volume={99}, 
number={5}, 
pages={57004}, 
year={2012}, 
publisher={IOP Publishing}, 
doi = {10.1209/0295-5075/99/57004} }

ChatGPT will proudly display the following:

Ground-state spin logic
Whitfield, J and Faccin, M and Biamonte, J
European Physics Letters, Vol. 99, No. 5, pp. 57004, 2012, IOP Publishing
DOI: 10.1209/0295-5075/99/57004

ChatGPT-4

But I don’t like the comma before ‘Vol.’ It should be avoided and so should the publishers name. So instead of editing this ourselves, it is now time to apply the second step above. We need to get ChatGPT to fix this itself.

Please write names with the initial first.  And please write the citation as European Physics Letters 99(5):57004 (2012).  

ChatGPT tries to be polite so it often apologises if it gives you something you don’t like. So it outputs:

Apologies for the oversight. Here’s the corrected citation:

Ground-state spin logic
J Whitfield, M Faccin, and J Biamonte
European Physics Letters 99(5):57004 (2012)
DOI: 10.1209/0295-5075/99/57004

ChatGPT

So we got what we wanted. So we are positioned to try step 3:

Please write a prompt to have a LLM such as yourself receive a BibTeX entry and to produce rich text output as you have just done. 

From that prompt, I recovered a new prompt that does the job entirely. I also automated the inverse problem, I can paste in some text, a link or even attach the PDF of a paper (using an an app) and ask ChatGPT to generate the BibTeX entry. I have pasted the prompts below for you to experiment with. Just follow the steps above to refine them to meet your own style.

Convert a BibTeX entry to standard rich text format with this prompt

Using the iterative process above, ChatGPT-4 created the following prompt:

ChatGPT, I'm going to provide you with some BibTeX entries. For each entry, please convert it into a standard document format with the following structure:

1. Title of the article (bolded)
2. Authors (last name followed by initials), with 'and' before the last author
3. Journal information (journal name, volume number(issue number):page number (year))
5. DOI or other link

Please wait for my input.

Example Input:

@article{SampleEntry,
	title={Title of the Article},
	author={Author, A and Author, B and Author, C},
	journal={Name of the Journal},
	volume={Volume Number},
	number={Issue Number},
	pages={Page Number},
	year={Year of Publication},
	publisher={Publisher Name},
	doi={DOI Number}
}

Expected Output:

Title of the Article
A Author, B Author, and C Author
Name of the Journal Volume Number(Issue Number):Page Number (Year of Publication)
DOI: [DOI Number](https://doi.org/DOI Number)

Convert partial information, an ArXiv link to a paper, or other URL to a BiBTeX entry with this prompt

Using the iterative process above, ChatGPT-4 created the following prompt:

ChatGPT, I'm going to provide you with either a link to an article or other text containing citation information. For each entry, please:

1. If online browsing is enabled, check online if the work was published in a journal if an arXiv link is provided and there is no citation.
2. Convert the provided information into a BibTeX entry. Write out all journal names in full, with no abbreviations.
3. For the citation key, follow the alphanumeric citation key standard: if it's a single author, use the first three letters of their last name followed by the year (e.g., 'Bia08'). If there are multiple authors, use the first letter of each of their last names followed by the year (e.g., 'WFB12'). If there are more than three authors, use the first three letters followed by a plus and then the year (e.g., 'Whi+12').
4. Please wait for my input.

Example Input:
"Nonperturbative k-body to two-body commuting conversion Hamiltonians and embedding problem instances into Ising spins, J Biamonte, Physical Review A 77(5):052331 (2008), DOI: 10.1103/PhysRevA.77.052331"

Expected Output:

@article{Bia08,
  title={Nonperturbative k-body to two-body commuting conversion Hamiltonians and embedding problem instances into Ising spins},
  author={Biamonte, J},
  journal={Physical Review A},
  volume={77},
  number={5},
  pages={052331},
  year={2008},
  publisher={American Physical Society},
  doi={10.1103/PhysRevA.77.052331}
}

Pro-tips for optimal use

As we explained, if you use these prompts and you don’t get what you want, you should clearly articulate and explain to ChatGPT what is wrong with the output. For instance, if the output is not formatted the way you want, you can say,

Please change [describe or paste output] to this: [the text with changes]

For example:

Consider this string:  XZY

The string “XZY” appears to be a sequence of three characters from the English alphabet. Is there a specific context or question you have about this string?

ChatGPT
Please write this string as XYZ.  

Sure, here is the string as “XYZ”.

ChatGPT

ChatGPT does not care that you just did what you are asking. It will happily write it again. Since there is only one example, ChatGPT is going to have to guess what you want:

Please write a prompt for an LLM such as ChatGPT to receive strings and rewrite them as we have just done.  It should work for any string of 3 letters.  

Sure, here’s a general prompt:

“As an AI language model, your task is to take any input string of three characters from the English alphabet and rearrange them in alphabetical order. For example, if the input string is ‘XZY’, you should return the string ‘XYZ’. Please implement this functionality so it works for any three-character input.”

ChatGPT

Now you are an expert. Here is a link to a ChatGPT conversation showing how an example similar to the one above works in practice. At the end I even asked for a Mathematica function to accomplish the same thing.

Exercise. Try the above commands, then after it spits out the prompt simply type in 918 and watch ChatGPT generalise from alphabetical to ascending order, returning 189. Then ask ChatGPT to write a new prompt to incorporate numbers as well.

It’s essential to work with ChatGPT until it understands and modifies the output to meet your expectations. Once it displays precisely what you’re after, you should instruct it to alter the original prompt so that it will consistently produce the desired output.

Both of the prompts above were produced using this iterative cycle of human-AI collaboration. The age-old adage, “Fast is slow, slow is fast,” rings true in this situation. Curious where that quote came from, just ask:

The quote “Fast is slow, slow is fast” comes from Stephen R. Covey. He used it to explain the difference between being efficient and being effective.

ChatGPT

ChatGPT provided a reference to this blog, I added the link to the Covey’s wiki entry.

Carefully crafted prompts can yield good outputs, and sometimes minor tweaks make a significant impact. Given that this technology isn’t entirely stable at the moment, before you consider initiating a new conversation cycle, your first course of action should be to rectify any misunderstanding by providing clarifications.

Discussions about the potential dangers of AI are common these days. I hold the belief that this technology will progressively integrate with humanity and ultimately, become an integral part of us. While this perspective isn’t universally accepted, it aligns with the concept of the technological singularity.

A society in which individuals using AI technology vastly outperform those who don’t, is already becoming visible.

The challenge lies in perfecting the interface. The practice of prompt engineering appears here to stay, as it’s currently the only method for managing these large language models. The very early phase of fusion with these machines might already be underway with a global effort revolving around improving our interaction with them.

A warning about prompt injection

It’s crucial to read any prompts that you find on the internet with care. “Prompt injection” is a potential way for ChatGPT to be coaxed into nefarious behavior by inserting a command in the middle of a larger prompt. As we grant ChatGPT increasing control over our systems, potential security vulnerabilities should be a growing concern. See the first exercise above to understand how ChatGPT can confuse the context and execute anything it reads, even if you’re trying to get it to edit a prompt.

Exercises

Exercise 1. Make ChatGPT edit and improve a provided prompt. Without some care, the chatbot simply executes the prompt itself and the context of the instance cycle is broken.

Exercise 2. Get ChatGPT to make the issue number bold. For example, instead of European Physics Letters 99(5):57004 (2012) it should output European Physics Letters 99(5):57004 (2012).

LaTeX Instructions

To embed LaTeX expressions in your comments, please surround your equations using: $ ... $ or $$ ... $$. There is no preview feature, so I’ll try to fix any errors. Read the QuickLaTeX guide for more options.

Leave a comment