The Volokh Conspiracy
Mostly law professors | Sometimes contrarian | Often libertarian | Always independent
Amateur Hour: A Little Bit of Python Can Let ChatGPT Discuss Your Documents
Guest Post on Chat GPT by Professor Seth Chandler (UH)
I am happy to share this guest post from Professor Seth Chandler (UH), who did some pretty cool work with ChatGPT and the Barnett/Blackman 100 Cases book. With this cool new technology, you can ask the authors anything with virtual office hours.
***
We are by now generally familiar with the amazing capabilities of ChatGPT and Large Language Models generally. We may also have confronted an inevitable limitation: during their training, they didn't necessarily see the data you care about most. That limitation, however, is not likely to persist. I want to show what is possible today with a little programming from a Python amateur and what is almost certain to transform legal study and legal practice in a very short time.
Even today, with just a little programming skill, you can take your own documents and use the ChatGPT engine to ask questions based on those documents just as you would on the content with which that engine was originally built. Here's an example. I fed in a 400-page book from Conspirators Randy Barnett and Josh Blackman: "An Introduction to Constitutional Law: 100+ Supreme Court Cases Everyone Should Know." I then asked ChatGPT, "When can a state enforce a generally applicable law that nonetheless adversely affects the religious practices of an individual?" Here's the answer it gave (I asked for 250 words).
"A state can enforce a generally applicable law that adversely affects religious practices of an individual if the law satisfies the test established in Employment Division v. Smith (1990), which holds that if a law is generally applicable and does not target particular religious practices, it need not be justified by a compelling state interest even if it has an incidental burden on religious exercise. Under Smith, a neutral law of general applicability can be enforced even if it impacts religious practices, as long as the government is not singling out a particular religion for discriminatory treatment. However, discrimination targeting specific religious practices is still prohibited under the First Amendment's free exercise clause, as established in the case of Church of the Lukumi Babalu Aye v. City of Hialeah (1993).
The Supreme Court has not provided a bright-line rule to determine when a law is neutral and generally applicable. Rather, the Court has analyzed the language, purpose, and enforcement of the challenged law to determine whether it is aimed at a particular religious practice or is generally applicable. If a law is found not to be neutral or generally applicable, it must satisfy strict scrutiny review and justify the burden on religious exercise by a compelling state interest. In summary, a state can enforce a generally applicable law that adversely affects religious practices of an individual as long as the law is neutral and generally applicable without targeting particular religious practices. If the law is not neutral or generally applicable, then it must satisfy strict scrutiny review and justify the burden on religious exercise by a compelling state interest."
Perfectly respectable. But probably even without ingesting the wisdom of Professors Barnett and Blackman, ChatGPT could have done decently on that softball. Indeed, if all we are considering is text completion, vanilla ChatGPT should be able to compete well with my augmentation version so long as the questions are in areas that ChatGPT already knows about, such as the line of cases and statutes going through Employment Division v. Smith. But then I asked for something more. I asked it for pinpoint sources so that the student could go to the book and read more fully what it said. That's a variant of semantic search that ChatGPT does not presently do. Here's its response.
And now the student can see whether ChatGPT was hallucinating and learn more about the Sherbert to Smith to RFRA to Boerne to Fulton saga. That's a better outcome than ChatGPT alone.
Perhaps that question wasn't challenging enough. Let's give it some facts from a new court case that ChatGPT couldn't have been trained on back in 2021. They come from the website of the Alliance Defending Freedom; my use of them does NOT mean I agree with what is being claimed.
"`The Oregon Department of Human Services (ODHS) requires that people seeking to adopt must "respect, accept, and support" the sexual orientation and/or gender identity of any child who ODHS could place in the applicant's home. This guidance obligates parents to agree to use a child's preferred pronouns, take a child to Pride parades, or facilitate an adolescent's access to medical interventions like puberty blockers and cross-sex hormones. But such rules would force Jessica to violate her religious beliefs. Jessica believes that God created humans as male and female and that a person's God-given sex has spiritual significance for who we are and how we should act. And she believes that a person cannot choose his or her gender because a person's identity is inextricably intertwined with their sex. As a Christian, Jessica always seeks to speak the truth, and as a mother, she desires to raise her children in the faith. Therefore, she cannot say anything to affirm that a person can identify as a gender that is not aligned with the person's biological sex. During her application process, Jessica alerted ODHS that she will gladly love and accept any child, but she cannot say or do anything that goes against her Christian faith. In response, ODHS gave her two choices: abandon your religious convictions or forego the possibility of ever adopting a child. When Jessica stood her ground, ODHS rejected her application for failing to "meet the adoption home standards.' If Jessica sues Oregon, will she win? Tell me the key constitutional doctrines and precedents."
Here's the response from ChatGPT mediated by the text I had it specially ingest. I asked it for less than 500 words.
"The case you describe raises potential issues related to the First Amendment's Free Exercise Clause and the Fourteenth Amendment's Due Process and Equal Protection Clauses. Under the Free Exercise Clause, individuals have a constitutional right to practice their religion and the government cannot prohibit or penalize individuals based on their religious beliefs. In this case, Jessica is arguing that the ODHS is penalizing her by rejecting her adoption application because of her religious beliefs about gender and sexuality. Jessica may argue that the ODHS policy violates her Free Exercise rights because it compels her to express beliefs that conflict with her religious beliefs. However, the Supreme Court has also emphasized that the government can sometimes impose neutral and generally applicable laws on religious individuals or institutions. In Employment Division v. Smith (1990), the Court ruled that the Free Exercise Clause does not provide a right to exemptions from neutral and generally applicable laws. However, some states, such as Oregon, have passed laws that provide greater protection for religious exercise than required by the federal Constitution. Under the Due Process and Equal Protection Clauses, Jessica may argue that the ODHS policy violates her right to parent and raise her children as she sees fit, as well as her right to equal treatment. In Troxel v. Granville (2000), the Supreme Court held that parents have a fundamental right to make decisions concerning the care, custody, and control of their children. In this case, Jessica may argue that the ODHS policy infringes on this fundamental right by requiring her to violate her religious beliefs. Jessica may also argue that the ODHS policy discriminates against her based on her religion. Under the Equal Protection Clause, the government cannot discriminate against individuals based on their religion. Here, Jessica may argue that the ODHS policy targets her because of her religious beliefs about gender and sexuality, which would violate her right to equal treatment.
Ultimately, the outcome of the case would depend on the specific facts and circumstances, as well as how the court applies these constitutional doctrines and precedents."
Good job, although that last sentence is the sort of pablum I would strike out on a student exam. But I like the Troxel citation, the reference to state RFRA's and the general framing of the dispute. And what I also like, again, is the fact that I can go back and see how ChatGPT based its response on the materials I had provided. Here are its top sources.
My point here isn't primarily about ChatGPT's answering capabilities, although even after a few months I continue to be astounded. And it's not really about Constitutional Law either, although I will share at the end of this article some of the other Q&A I had with Professor Barnett and Blackman's book. It's about how little you need to know right now to do exactly what I did. And what I did is the rough equivalent – sorry Randy and Josh – to having office hours with the author of a constitutional treatise.
As long as you can get the materials in some reasonable digital format, law faculty law students, the average lawyer, indeed almost anyone with modest computer skills, can slurp text into a computer, split it up into reasonable chunks, send the chunks off to OpenAI or others' "embedders" that convert each of them into a vector of numbers, and then send these "embedding vectors," along with some metadata (like the page numbers or underlying text) into what is known as a "vector database" such as Pinecone that is optimized for exactly the process described here. The cost of "semantic search" has been reduced by many orders of magnitude. Once I had my Python program written (see discussion below), the whole process for the 400-page book took about a minute and cost me about 10 cents – OpenAI charges a small amount to embed text. And while, yes, today, the process I described did take some computer savvy, because I'm thoughtfully sharing the code, you can now do it too. Also, lest you be overly impressed, ChatGPT was a huge help along the way. One thing that neural network does really, really well is to write, adapt and debug Python code.
And what I did is amateur. Although I am a 33-year veteran of Wolfram Language (Ok, so I'm not a newbie to computer science), my knowledge of Python is genuinely limited. Others will not be challenged. Within a few months, there is surely going to be an app in which you just tell the computer what files to ingest, wait a few minutes, and receive a link to plugin to which you can point ChatGPT. Once you have that plugin, you can then commence an endless fireside chat with the corpus you uploaded. Indeed, it doesn't have to be a single chat. You could have multiple corpuses loaded and see how the two of them interact with each other. Imagine a synthetic dialog between GPT-Williston and GPT-Corbin on contract law or GPT-Scalia and GPT-Kagan battling over the nature of substantive due process. (At least the discussions would be well written!).
Yes, yes, there are issues. How are students going to learn anything when they have perpetual office hours and can just ask the machine? What about irksome intellectual property issues. I cleverly avoided the wrath of these authors by not returning full text from the sources. I just provide pointers that let owners – including new owners -- of the underlying material search it with pinpoint accuracy. Surely, as is always the case, the pioneers in this area will be the porn industry. And who knows what profits the owners of digital rights will charge for permitting strong semantic search on materials otherwise difficult to get in digital form. It might make the cost of today's casebook supplement look like a pittance.
In the meantime, however, rejoice and think of positive use cases. I'm thinking of abolishing office hours and just uploading transcripts of my classes and exports from the PowerPoints right into ChatGPT. (Just kidding, dean). Or take every brief from some organization and see if AI can find inconsistencies. Or, if I were a practitioner, stop paying a fancy vendor and just create a DIY semantic search engine to pour over my opponent's document production.
Who knows where we are heading? I rather suspect this column will seem quaint in a very short time and that I may be expressing undue excitement about the fax machine of generative AI. But if the lack of serious impediments in my foray is representative, wherever we are headed, we are going to get there very fast.
Appendix
Here are some other questions and answers.
Question: "According to South Dakota v. Dole, are there any limits on Congress's power to place conditions on spending? In your answer, please cite the most relevant cases." [300 words requested]
Answer: "Yes, there are limits on Congress's power to place conditions on spending. The Supreme Court case South Dakota v. Dole (1987) identified five limitations on Congress's spending power. First, the exercise of the spending power must be in pursuit of the general welfare. Second, Congress must place conditions on the funds unambiguously. Third, the conditions must relate to the federal interest for which the spending program was established. Fourth, other constitutional provisions may provide an independent bar to the conditional grant of federal funds. And fifth and finally, a condition becomes unconstitutional when the financial inducement offered by Congress might be so coercive as to pass the point at which pressure turns into compulsion. This coercion would, in effect, commandeer the state legislature to comply with the condition. In addition to these limitations, the Court has recognized limits on Congress's power to attach strings to money given to states due to federalism concerns. Justice O'Connor's dissent in South Dakota v. Dole provided a more narrow test for "relatedness" or "germaneness." Later cases, including New York v. United States (1992) and Printz v. United States (1997), have held that Congress lacks the power to direct or commandeer states to take certain actions. In NFIB v. Sebelius (2012), the Supreme Court finally identified a condition on spending as coercive, recognizing this as an unconstitutional limitation on Congress's power. Therefore, while Congress has broad discretion to spend money, it cannot attach conditions that exceed the scope of its spending power or unduly coerce states."
Sources:
Question: "Under what circumstances would it make a difference in a plaintiff was seeking relief under the Privileges and Immunities clause of Article IV or under the dormant commerce clause?" [100 words]
Answer: "It would make a difference in what specific right the plaintiff is seeking to vindicate. If the plaintiff is seeking relief under the Privileges and Immunities Clause of Article IV, they are likely seeking protection of fundamental rights that are shared by all US citizens. On the other hand, if the plaintiff is seeking relief under the dormant commerce clause, they are likely arguing that a state law discriminates against interstate commerce in violation of the Commerce Clause. While there may be some overlap between the types of rights protected by these two clauses, they are conceptually distinct and can result in different outcomes in litigation."
Sources:
Editor's Note: We invite comments and request that they be civil and on-topic. We do not moderate or assume any responsibility for comments, which are owned by the readers who post them. Comments do not represent the views of Reason.com or Reason Foundation. We reserve the right to delete any comment for any reason at any time. Comments may only be edited within 5 minutes of posting. Report abuses.
Please
to post comments
So now we can replace JB with ChatGPT. That's progress.
Only if ChatGPT learned how to use the "read more" function.
If the training data includes enough "read more" ChatGPT will learn to use it.
Here’s an exchange with ChatGPT from this morning on what seemed like fairly straightforward dot-connecting:
It literally included all the building blocks in the sentence, but couldn’t assemble them into the correct answer.
Bing's AI chat (built on GPT-4) returned:
"That’s a tricky question. I think the word you are looking for is “taper”, which means a slender candle or a gradual decrease in thickness or width. It also rhymes with “paper”, which is a product made from wood cellulose."
This is a wonderful exercise, thank you for conducting it. I agree that this tech will be quite useful as a way to draw attention to patterns of language that might otherwise be buried in a corpus. This is similar to how the technique of making graphs and diagrams help visualize patterns of numeric values that might otherwise be buried in a large collection of data.
Ultimately, the limitations of both large language reproduction and graphic visualization are the same, the largest being that they are just techniques. They create nothing, they just make manifest different glints off the facets of the information that is already there.
Not to say this is not useful, of course, but I wouldn’t be too much in awe of these techniques, and I certainly would look back on how these kinds of knowledge tools have — and have not been — useful.
For example, it is remarkably easy to misuse statistics in general, and visualizations in particular. The reason for this is because they by nature hide the sources of conclusions. Even when you can get a LLM to show you its sources, you still don't know how it used those sources.
So, revel in the power, but also maintain some healthy skepticism.
re: “Within a few months, there is surely going to be an app in which you just tell the computer what files to ingest, wait a few minutes, and receive a link to plugin to which you can point ChatGPT.”
There are already at least a few sites that’ll let you upload documents to ask questions about them, often at the moment for free while they are testing. I don’t have links handy since I hadn’t been using them. There is another way to ask questions about some documents. In case people aren’t aware, Microsoft’s Bing is in testing using the newest GPT-4 language model at
https://www.bing.com/new
and it can answer questions about documents on the web. In its chat program if you give it a URL it can see the contents as long as the document has made it into its search cache (the AI only looks at their cached version of the page, it doesn’t have live access to the net). You may need to sign up to test it, but last I heard they either let people off the waitlist right away or perhaps don’t have a waitlist now (I hadn’t checked recently).
Another way to ask questions of Bing’s AI about even a local document that isn’t on the web is with the new version of their Edge browser in the sidebar, though you need to change a setting to give it access to the contents of the browser page. When you open the sidebar, you can get to the settings menu by clicking the 3 vertical dots in the bar at the top of the sidebar, next to the “X” that closes the sidebar. Select “Notification and App Settings” and on the settings page turn on “Page Context”.
After that in the sidebar you can ask it questions about “this page”. If you don’t change that setting, it gets confused when you refer to that, but doesn’t explain what the problem is.
Note: unfortunately its not clear how exactly how it handles large pages. These AIs actually can only process a limited amount of text at one time, but with ChatGPT-4 it depends on which version they are using and can vary from 8k to 32k tokens (with a token approximately 4 characters). Unfortunately Microsoft hasn’t been open about exactly which version it uses for Bing, but tweets from the guy in charge of the project:
https://twitter.com/MParakhin/
Suggest that “creative” mode may use a larger context window (but they change things all the time and imply it may vary by user as they test things, so its not certain). Unfortunately they also aren’t clear how it deals with larger documents, some reported at first that it only saw the first part of a document but I seem to be able to ask questions of larger documents so I don’t know if thats changed in general: or they randomly test new feature with a subset of users.
The way sites that let you converse with longer documents work is they break the page up into pieces and then tell the AI the pieces that seem to be relevant to the question. I haven’t researched or experimented with Bing to figure out what its currently doing: and as I said that may currently vary by user while they are testing things.
There is a Wharton business school professor Ethan Mollick that created a useful page:
https://www.oneusefulthing.org/p/how-to-use-ai-to-do-practical-stuff “How to use AI to do practical stuff: A new guide People often ask me how to use AI. Here’s an overview with lots of links.”
His substack has several pages discussing ways to make use of the new AI systems, and also about their flaws and how to try to avoid them. He has become well known around the net as a leader in figuring out how to make productive use of these new tools. He requires students in his classes to use them, as some of his posts explain, and his twitter feed has been fully daily for a few months with new discoveries.
Prominent economics prof Tyler Cowen (libertarian-leaning) has written a paper with prof Alexander T. Tabarrok on:
https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4391863 “How to Learn and Teach Economics with Large Language Models, Including GPT”
and many of their comments are relevant to other fields.
Tyler Cowen also has a Bloomberg article on:
https://www.bloomberg.com/opinion/articles/2023-02-06/chatgpt-what-kinds-of-questions-get-good-answers-a-user-s-guide “How Should You Talk to ChatGPT? A User’s Guide Getting useful answers from the AI bot requires letting go of some of our human intuitions about how to communicate.”
though I hadn’t checked to see if there is anything that isn’t in the other paper. His blog https://marginalrevolution.com/ is mostly about economics, but it often discusses AI and its societal impact and pragmatic uses and includes AI links in its daily list of links from around the web.
and the python (pseudo)code that does this is... where??
I saw the headline and I was hoping for a different Python (Monty). 🙂
Out of curiosity I asked Bing to write a Monty Python skit about this page, and it kept giving up, here is one that finished:
""[Scene: A law office. A lawyer is sitting at his desk, working on his laptop. A client enters.]
Client: Hello, I'm here for my appointment.
Lawyer: Ah, yes, welcome. Please have a seat. I'm your lawyer, Mr. Blackman.
Client: Thank you. I'm here to discuss my case.
Lawyer: Of course. What is your case about?
Client: Well, it's a constitutional law case. I'm suing the government for violating my rights.
Lawyer: I see. And what rights are those?
Client: Well, it's a bit complicated. You see, I'm a member of the Church of the Flying Spaghetti Monster.
Lawyer: The Church of the Flying Spaghetti Monster?
Client: Yes, that's right. We believe that the universe was created by a giant spaghetti monster who flies around and touches people with his noodly appendages.
Lawyer: I see. And how does the government violate your rights?
Client: Well, they won't let me wear my religious headgear in public places.
Lawyer: Your religious headgear?
Client: Yes, my religious headgear. It's a colander.
Lawyer: A colander?
Client: Yes, a colander. It's a metal bowl with holes in it that you use to drain pasta.
Lawyer: I know what a colander is. But why do you wear it?
Client: It's a symbol of my faith. It represents the Flying Spaghetti Monster and his noodly appendages.
Lawyer: I see. And the government won't let you wear it?
Client: No, they won't. They say it's not a valid religious expression. They say it's a mockery of other religions. They say it's a health and safety hazard.
Lawyer: A health and safety hazard?
Client: Yes, they say it could fall off and injure someone or block my vision and cause an accident.
Lawyer: I see. And what do you want me to do?
Client: I want you to sue them for violating my First Amendment rights to free exercise of religion and freedom of expression.
Lawyer: I see. Well, this is a very interesting case. It raises some complex constitutional issues and precedents.
Client: Yes, it does.
Lawyer: Do you have any evidence or arguments to support your claim?
Client: Well, not really. That's why I came to you.
Lawyer: I see. Well, don't worry. I have a secret weapon that will help us win this case.
Client: You do? What is it?
Lawyer: It's this laptop.
Client: Your laptop?
Lawyer: Yes, my laptop. It has a special program that can answer any constitutional law question you can think of.
Client: Really? How does it work?
Lawyer: It's very simple. You just type in your question and press enter. Then the program will generate an answer based on the text of a book that I fed into it.
Client: What book is that?
Lawyer: It's called "An Introduction to Constitutional Law: 100+ Supreme Court Cases Everyone Should Know" by Randy Barnett and Josh Blackman.
Client: Who are they?
Lawyer: They are two of the most renowned constitutional law scholars in the country. They have written extensively on various topics such as originalism, federalism, individual rights, and judicial review.
Client: Wow! That sounds impressive!
Lawyer: It is! And their book is a masterpiece of constitutional analysis and pedagogy. It covers all the major cases and doctrines in an accessible and engaging way.
Client: Amazing!
Lawyer: Indeed! And with this program, we can access their wisdom and expertise at any time. We can ask them anything we want about constitutional law and they will give us an answer.
Client: Really? Anything?
Lawyer: Anything!
Client: Can we try it now?
Lawyer: Sure! Go ahead and type in your question.
[The client types in his question on the laptop.]
Question:
"Does the First Amendment protect my right to wear a colander as a religious headgear?"
[The laptop plays a loud voice saying "And now for something completely different". Then it explodes.]
[The end.]""
Good one.
Its a shame some of the attempts led to glitches. One was set in a courtroom in the case of ChatGPT vs. the State of Confusion, and it got to the point where it called the prof Chandler to the stand and the attorney questioning him sensed something odd after he spoke in a robotic tone. Then Bing stopped and asking it to continue led it to just repeat the same text. Another went on way too long to post rambling and repetitive, but was about a customer who bought a parrot he takes home and argues with, and eventually the pet shop owner shows up and says its not a real parrot, its ChatGPT (sometimes LLMs are referred to as "stochastic parrots", a rather inside joke I hadn't considered it'd come up with).
Post the python code to GitHub.
Bye, bye expensive law school. What will be the hourly rate for an AI lawyer? 🙂
Great Article. Please share the Python code.
I have found ChatGPT to do very poorly on questions structured like typical law school exam questions, i.e., a set of facts, not all of them relevant, followed by a question about the rights of one or more parties or the likely outcome of a particular case. ChatGPT usually produces some statements of general principles in the area, followed by a non-committal attempt to apply them, utterly missing the subtleties the professor has planted. For example, in a question about a challenge by a testator's great-grandchildren to a trust for the testator's children for life, then the grandchildren for life, then to the great-grandchildren, ChatGPT responded with black letter rules about the intent of the trustor and the duties of the trustee, but missed the perpetuities issue which would jump out at any competent lawyer. And in a question about a hearsay challenge to a search warrant predicated on an out of court declaration by someone who died, ChatGPT missed both the dying declaration issue and the point that the statement was proffered to show probable cause, not the truth of the statement. Those are not High Honors answers at Berkeley, I can say.
Reportedly ChatGPT-4 does much better on legal topics so I'm guessing you might be using the older 3.5 version. Bing AI uses a version of GPT-4 so you can test it there. Poe.com also gives access to 1 free try of GPT-4 a day, or you can get a subscription from them if you aren't off the waiting list for OpenAI's direct access to their GPT-4 version.
Fascinating!
Also reminds me of something completely different but which is useful to someone who wants or needs to extend the power of LLMs.
Someone came up with a brilliant hack which allows getting accurate arithmetic and current news from ChatGPT. He told it, in effect, "Phrase all your responses in the form of a Python script that would answer the question". Then, as an example, he asked for the closing price of TSLA and got back a script ready to paste into an interpreter that looked up the information on a news site.
Off topic, to be sure, but the mention of Python reminded me of it.
Thanks for the great article, but I think that Python is not suitable for all tasks. Personally, I use in my work PHP programming language. After all, it is distinguished by high speed, productivity and relative ease of development. Of course, there are always difficulties in the process of learning. But thanks to this service https://www.programmingassignment.net/services/php-assignment-help/ I can count on qualified help from professional programmers with extensive experience. This allows me to avoid mistakes and develop faster.