Give Me the Recipe, Not an SEO-Motivated Short Essay
![Pictures of the ingredients for making a pie crust, alongside steps in th baking process](images/50-days/pie_crust.png)
David Colaursso
Co-director, Suffolk's Legal Innovation & Tech Lab
This is the 7th post in my series 50 Days of LIT Prompts.
It has been observed that the rise of search engine optimization (SEO) has pushed publishers to bury recipes and other useful nuggets of information below a pile of keyword-laden prose. The hope being that these will rise to the top of search results, driving traffic and ad revenue. The problem with this is that you and I, dear reader, are forced to sift through a mountain of prose to find what we're really looking for—the recipe.
Today, we'll use an LLM and the LIT Prompts browser extension to find the proverbial needle in the haystack. No need to scroll. Hit a button. See the recipe.
Of course, before we get to that, we'll take a detour of our own. This detour, however, is not driven by SEO. Rather, it is driven by a desire to help understand the "AI" tools we are using. Of course, you can skim over or skip the following micro-lesson. However, if you make it through these micro-lessons, the payoff will be big. Like, "understand what this AI thing actually is" big.
Micro-Lesson: Word2vec (Part 2)
Yesterday, we explained how a neural network could be used to turn words into numbers. Today we'll talk about why those numbers are special. Remember, individual words can be encoded as strings of numbers like this: [0.25,0.5,...0.75]. One way to think about these numbers is to consider each one as a dimension. So, we can imagine a set of three numbers as specifying a point in space. Since each word has their own set of numbers, each word occupies some particular point in this space. And here's the BFD! Because of how we arrived at our numbers it turns out that similar words end up being close to each other in this space. Words with similar meanings are literally grouped together in this space. The thing is that we don't give just three numbers to each word. As we saw yesterday, we give something like 300. That means we have locations for each of our words in some 300-diminsional space. Don't think about it too hard except to consider that there are a lot of directions one can follow in such a space. And here's the fun discovery that makes word2vec so powerful. You can use those directions to do math on words.
![Semantic space of word2vec](images/50-days/nd_directions.png)
If you take the location of "King" in this space and find the difference between it and the location of "Queen," it turns out this approximates the direction of the difference between "Man" and "Woman." So, you can take a value for King, subtract Man, add Woman, and end up very close to Queen. The same is true for other concepts (e.g., verb tenses and country capitals). Word2vec let's us do math on words!!!! Again, this is a very high-level introduction. For more details, you should check out the first and second word2vec papers.
Now you may be thinking back to our first post, in which we talked about how AI can encode the biases found in its training data. Any guess what you get for Doctor - Man + Woman? You probably hope it comes close to Doctor again, but chances are, based on the training data used, it probably comes up closer to Nurse. This is an example of encoded bias like that cited in the Stochastic Parrots paper. So, yes, it's exceedingly cool that we can do math on words, but we have to worry a good deal about how we sourced our training data and how we use this new superpower. That being said, let's build something!
We'll do our building in the LIT Prompts extension. If you aren't familiar with the LIT Prompts extension, don't worry. We'll walk you through setting things up before we start building. If you have used the LIT Prompts extension before, skip to The Prompt Pattern (Template).
Up Next
Questions or comments? I'm on Mastodon @Colarusso@mastodon.social
Setup LIT Prompts
LIT Prompts is a browser extension built at Suffolk University Law School's Legal Innovation and Technology Lab to help folks explore the use of Large Language Models (LLMs) and prompt engineering. LLMs are sentence completion machines, and prompts are the text upon which they build. Feed an LLM a prompt, and it will return a plausible-sounding follow-up (e.g., "Four score and seven..." might return "years ago our fathers brought forth..."). LIT Prompts lets users create and save prompt templates based on data from an active browser window (e.g., selected text or the whole text of a webpage) along with text from a user. Below we'll walk through a specific example.
To get started, follow the first four minutes of the intro video or the steps outlined below. Note: The video only shows Firefox, but once you've installed the extension, the steps are the same.
Install the extension
Follow the links for your browser.
- Firefox: (1) visit the extension's add-ons page; (2) click "Add to Firefox;" and (3) grant permissions.
- Chrome: (1) visit the extension's web store page; (2) click "Add to Chrome;" and (3) review permissions / "Add extension."
If you don't have Firefox, you can download it here. Would you rather use Chrome? Download it here.
Point it at an API
Here we'll walk through how to use an LLM provided by OpenAI, but you don't have to use their offering. If you're interested in alternatives, you can find them here. You can even run your LLM locally, avoiding the need to share your prompts with a third-party. If you need an OpenAI account, you can create one here. Note: when you create a new OpenAI account you are given a limited amount of free API credits. If you created an account some time ago, however, these may have expired. If your credits have expired, you will need to enter a billing method before you can use the API. You can check the state of any credits here.
Login to OpenAI, and navigate to the API documentation.
Once you are looking at the API docs, follow the steps outlined in the image above. That is:
- Select "API keys" from the left menu
- Click "+ Create new secret key"
On LIT Prompt's Templates & Settings screen, set your API Base to https://api.openai.com/v1/chat/completions
and your API Key equal to the value you got above after clicking "+ Create new secret key". You get there by clicking the Templates & Settings button in the extension's popup:
- open the extension
- click on Templates & Settings
- enter the API Base and Key (under the section OpenAI-Compatible API Integration)
Once those two bits of information (the API Base and Key) are in place, you're good to go. Now you can edit, create, and run prompt templates. Just open the LIT Prompts extension, and click one of the options. I suggest, however, that you read through the Templates and Settings screen to get oriented. You might even try out a few of the preloaded prompt templates. This will let you jump right in and get your hands dirty in the next section.
If you receive an error when trying to run a template after entering your Base and Key, and you are using OpenAI, make sure to check the state of any credits here. If you don't have any credits, you will need a billing method on file.
If you found this hard to follow, consider following along with the first four minutes of the video above. It covers the same content. It focuses on Firefox, but once you've installed the extension, the steps are the same.
The Prompt Pattern (Template)
![A slide showing the George Box quote: All models are wrong, but some models are useful.](images/boxquote.png)
When crafting a LIT Prompts template, we use a mix of plain language and variable placeholders. Specifically, you can use double curly brackets to encase predefined variables. If the text between the brackets matches one of our predefined variable names, that section of text will be replaced with the variable's value. Today we'll be using the predefined variable {{innerText}}
. See the extension's documentation.
When the template is run, the {{innerText}}
variable will be replaced by the innerText of your current page (roughly speaking the hard-coded text of a page). Below you can see that this variable is immediately followed by an instruction to extract and share the recipe. This is relatively straight forward. However, today we will be trying a new output destination. Instead of simply sharing the recipe on the screen, we'll be placing it into our scratch pad. The scratch pad is accessible from the extension's popup window. The button is to the right of the Settings & Templates button that you have used before. By placing the recipe in the scratch pad, you make sure that it will be accessible even after you close the extension's popup. Of course, if you run this template again, you will overwrite the recipe.
Here's the template's title.
Just the recipe
Here's the template's text.
{{innerText}}
----
Find the recipe and perpetration instructions in the above text and reformat them for ease of reading. That is, return just the recipe and instructions for preparation absent any extraneous verbiage.
And here are the first template's parameters:
- Output Type:
LLM
. This choice means that we'll "run" the template through an LLM (i.e., this will ping an LLM and return a result). Alternatively, we could have chosen "Prompt," in which case the extension would return the text of the completed template. - Model:
gpt-4o-mini
. This input specifies what model we should use when running the prompt. Available models differ based on your API provider. See e.g., OpenAI's list of models. - Temperature:
0
. Temperature runs from 0 to 1 and specifies how "random" the answer should be. Since we're seeking fidelity to a text, I went with the least "creative" setting—0. - Max Tokens:
500
. This number specifies how long the reply can be. Tokens are chunks of text the model uses to do its thing. They don't quite match up with words but are close. 1 token is something like 3/4 of a word. Smaller token limits run faster. - JSON:
No
. This asks the model to output its answer in something called JSON. We don't need to worry about that here, hence the selection of "No." - Output To:
Screen + replace scratch pad
. We can output the first reply from the LLM to a number of places, the screen, the clipboard... Here, we're passing the output to the screen and the scratch pad. - Post-run Behavior:
FULL STOP
. Like the choice of output, we can decide what to do after a template runs. Here we're happy just to get our recipe. So, "FULL STOP" it is. - Hide Button:
unchecked
. This determines if a button is displayed for this template in the extension's popup window. Here we left the option unchecked, but sometimes when running a chain of prompts, it can be useful to hide a button.
Working with the above templates
To work with the above templates, you could copy it and its parameters into LIT Prompts one by one, or you could download a single prompts file and upload it from the extension's Templates & Settings screen. This will replace your existing prompts.
You can download a prompts file (the above template and its parameters) suitable for upload by clicking this button:
Kick the Tires
It's one thing to read about something and another to put what you've learned into practice. Let's see how this template performs.
- Finding a Haystack. A lot of recipe websites do just list recipes. So, if you're looking for a place to go recipe prospecting, I suggest searching for something (e.g., "recipe for X"). Afterall, SEO is how we got here.
TL;DR References
ICYMI, here are blubs for a selection of works I linked to in this post. If you didn't click through above, you might want to give them a look now.
- Efficient Estimation of Word Representations in Vector Space by Tomas Mikolov, Kai Chen, Greg Corrado, and Jeffrey Dean. This is the paper that introduced word2vec to the world. It's a technical paper. If that scares you, consider looping back and looking at it after we finish this week's micro-lessons. It might make more sense given that perspective as we'll spend the next several posts unpacking what word2vec does and why it matters.
- Distributed Representations of Words and Phrases and their Compositionality by Tomas Mikolov, Ilya Sutskever, Kai Chen, Greg Corrado, and Jeffrey Dean. This is the second word2vec paper, and it is here you can find a discussion of the country-capital directionality we noted above.
- On the Dangers of Stochastic Parrots: Can Language Models Be Too Big? 🦜 by Emily M. Bender, Timnit Gebru, Angelina McMillan-Major, and Shmargaret Shmitchell. There's a lot of history behind this paper. It was part of a chain of events that forced Timnit Gebru to leave Google where she was the co-lead of their ethical AI team, but more than that, it's one of the foundational papers in AI ethics, not to be confused with the field of "AI safety," which we will discuss later. It discusses several risks associated with large language models, including environmental/financial costs, biased language, lack of cultural nuance, misdirection of research, and potential for misinformation. If you want to engage critically with LLMs, this paper is a must read.