Sadly Not, Havoc Dinosaur

You Can't Be Neutral on a Moving Train

Define a selected word, phrase, idiom, or initialism given the context of the webpage on which it is found

Headshot of the author, Colarusso. David Colaursso

This is the 4th post in my series 50 Days of LIT Prompts.

If I had a motto, it might be "context matters." Except, I'm resistant to picking a singular guiding principle because, well... context matters. ๐Ÿ˜‰ Earlier in the week, we wrote a template to provide definitions for words we highlighted in the browser, but we found when kicking the tires that sometimes this feel down when dealing with terms of art or initialisms claimed by competing collections of words. What was lacking in these instances was context. So, today we'll add context from the active page to the prompt template. Before we get there, let's talk context more broadly.

This week my social media feeds have focused on two things: AI and unions. The precipitating events for this are: (1) the launch of this series on Monday; and (2) the fact that my wife is on strike. We're all likely to see these two topics near each other more and more for one simple reason. Despite what you may have heard, the real answer to people's AI fears isn't copyright. It's antitrust and labor law. We saw a preview of this with last year's writers' strike. I believe training AI shouldn't be a matter for copyright, and the liability for infringing outputs should probably fall mostly on the prompter. Whether or not five justices agree with me is another matter. Either way, AI art doesn't copy human artists the way you think it does & that queasy feeling it gives you isn't about copyright. It's antitrust and labor.

Image-generating models like Dall-E and Stable Diffusion do NOT contain copies of the art they were trained on. To see why consider: (1) models like Stable Diffusion and Dall-E were trained on billions of image-description pairs; (2) the trained models, the software capable of producing AI art have sizes on the order of half a dozen gigabytes. This means there is only something like 17 bits available per image. For reference, this sentence alone contains 192 bits if encoded in the popular ASCII character set. If one could store a high-resolution image in 17 bits, a cell phone with 32GB of storage could store 15 billion photos. That's 5 photos every second for 100 years. Whatever is stored in that model, it is not a database of images. There is simply not enough space. Consequently, the images produced by the model are not collages stitched together from existing images. They are something much much weirder.

To many it seems self-evident that all AI art is composed of copies. Additionally, something strikes them as unfair and so they reason that there must be an existing prohibition against such an arrangement. Understandably, they assume such a prohibition must lie with copyright. However, the absence of any actual copies within the models suggests things may be more complicated. It is important to properly identify the root of such objections lest we make bad law or policy based on mistaken understandings. If one's objection is based on something other than copying, they are well served by properly identifying the true source. Otherwise, they risk fighting the wrong battle.

Understanding what these AI tools are doing is of the utmost importance if we are to wield them well. Which, as you may have guessed, is an excellent transition to our micro-lesson, followed immediately by prompt work.

Artificial Neural Nets

Yesterday, we saw how if we squint, a logistic regression looks a lot like an artificial neuron. Today we ask, what happens when you connect a bunch of these neurons together like so?

It's well beyond the scope of this series to explain how it is we train these networks, adjust all those weights to get the right answers, but given what we've learned this week, you should be able to see how they work once trained. You feed in some inputs (x through xn) and at the other end you can read out answers. In the above example, the network will output three numbers. These represent three different possible answers (A, B, and C). We know these answers will show up as numbers between 0 and 1, and if we've trained things properly, the right answer will be the one with the highest value. That is if we get the answers A=0.2, B=0.7, and C=0.1, we can assume there's a 70% chance the answer is B, a 20% chance the answer is A, and a 10% chance the answer is C. The number of outputs, inputs, as well as the number of nodes in the layer between is arbitrary. In practice, folks play around with different numbers to get the best results. If you make an input for every pixel in an image and confine the output to one. You can train a neural next to tell you if something is or isn't a cat by providing a lot of pictures labeled cat or not. Here's a great video that explains the operation of neural nets from a slightly different (more mathy) perspective.

We really have come a long way from predicting snow days. As I keep noting, predicting words can't be that far off. Until then, let's build something!

We'll do our building in the LIT Prompts extension. If you aren't familiar with the 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

7 min intro video

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:

  1. Select "API keys" from the left menu
  2. 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:

  1. open the extension
  2. click on Templates & Settings
  3. 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)

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 combining two variables we've worked with before, {{innerText}} and {{highlighted}}. See the extension's documentation.

The {{innerText}} variable will be replaced by the innerText of your current page (roughly speaking the hard-coded text of a page) while the {{highlighted}} variable contains any text you have highlighted/selected in the active browser tab at the time you open the extension. We use the template just like Tuesday's, highlight a word or words; run the template, and get a definition. What's different here is that we ask for a definition that considers the context of the page you are on. As you will no doubt see when you kick the tires, this improves performance over Tuesday's template.

Here's the template text.

{{innerText}}

Use the information above to explain who/what the following word/phrase is, i.e., provide a description/definition for the word(s) as used above: {{highlighted}}

And here are the template's parameters:

Working with the above template

To work with the above template, 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. Some of these may seem a little familiar, but bear with me.


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.