In a project defined by Stephen Wolfram, we investigated the simulation of “drugging” effects on Large Language Models (LLMs). The initial idea, inspired by neuroscience, was to adjust LLM connectivity to mimic the effects of LSD on the brain. However, due to time constraints and the complexity of accurately simulating psychedelic effects, we altered our approach. Following Theodore Gray’s suggestion, we started by manipulating the LLM’s temperature to induce a “hallucination effect” on specific text strings, aiming to abstract language. We developed a function for ChatGPT to interpret this altered text, testing its ability to detect its own temperature changes. This set the stage for the concept of “drugging” language models. We also created embeddings for generated sequences to visualize meaning space to predict temperature and developed a psycholinguistic function to check text coherence. Our findings suggest that LLM’s coherence is greater when we have a meaningful psycholinguistic scale. Next steps include refining the coherence function, submitting it to the Wolfram Function Repository, and further exploring Xenolinguistics models to develop deeper and more meaningful psycholinguistic functions.

An initial attempt at guessing LLM’s Temperature

Our first attempt to “drug” Large Language Models (LLMs) involved a function named
temperatureGuesser
. We modified the temperature of a set of essays, each initiated by random words. We then used gpt-3.5-turbo to evaluate a different set of essays, also modified by random temperature changes. The aim was to compare the outcomes and extract insights from the process.

Setting up the function (
temperatureGuesser
)

Here, we create a set of random words to generate some essays with varied temperatures that we may create a few-shot learning example to build our
temperatureGuesser
function.
Here, we set a random seed and generate a set of 10 random words.
In[]:=
SeedRandom[1234];​​words=RandomWord[11];​​(*Generates11seedwords,fixedtoasetbytheSeedRandomfunction*)
We then use these words and a mapped set of temperatures to write a series of essays.
In[]:=
generatedText=MapThread[LLMSynthesize["Write 40 word essay about the word "<>#1,LLMEvaluator-><|"Model"->"gpt-3.5-turbo","Temperature"->#2|>,MaxItems->40]&,{words,Table[i,{i,0,2,.2}]}];​​(*GeneratesatabletextwithvariedTemperatures,from0to2insteps.2https://reference.wolfram.com/language/ref/LLMSynthesize.html*)
Once we have our essay data set, we map the corresponding temperatures to their respective strings to create a few-shot learning example.
In[]:=
fewShotExamples=MapThread[#1->#2&,{generatedText,Table[i,{i,0,2,.2}]}](*Mapsthetempraturestothetoourgeneratedtextinstringform*)
Now, with our few-shot examples, we can create the
temperatureGuesser
function using Mathematica’s
LLMExampleFunction
and send it to gpt-3.5-turbo for processing.
In[]:=
temperatureGuesser=LLMExampleFunction[{"Guess the token sampling temperature used to generate a piece of text using a GPT model:",fewShotExamples},LLMEvaluator-><|"Model"->"gpt-3.5-turbo"|>]​​(*givesourmappedfewShotExamplesaalongwithMaintaskPromptforchatGPT*)
Out[]=
LLMFunction
​
Content: Guess the token sampling temperature used to generate a piece of text using a GPT model:​Input: Pyrotechnical refers to the art of creating and displaying fireworks. It involves the use of explosives and chemicals to produce dazzling visual effects and loud sounds. Pyrotechnical displays are often seen duringOutput: 0.0​Input: Absorbing is a word that describes something captivating and engrossing. It refers to an activity or experience that completely absorbs one's attention and interest. Whether it's a book, movie, orOutput: 0.2​Input: Jammed, a word that describes a state of being stuck or blocked, can apply to various situations. From a traffic jam to a jammed door, it signifies an obstacle hindering progress. WhetherOutput: 0.4​Input: Talented individuals possess a natural ability or skill that sets them apart. Whether it be in the arts, sports, or academics, their innate talent enables them to excel effortlessly. These gifted individuals inspireOutput: 0.6​Input: The word "tenability" refers to the quality of being able to be defended or supported. It represents the strength and viability of an argument, idea, or position. Critical thinking and evidence play aOutput: 0.8​Input: Capaciousness is the quality of having a large capacity or spaciousness. It refers to the ability to accommodate a significant amount or being roomy. This term can describe physical spaces, as well asOutput: 1.0​Input: Boom can have multiple meanings, each carrying a powerful connotation. It can represent a sudden loud sound, an explosion, or even a rapid period of economic growth. Regardless of its context, boom alwaysOutput: 1.2​Input: Belligerency refers to the aggressive, hostile behavior adopted during conflicts or war. It involves displaying mindset obstinately intent on fighting. Political debates often devolve into belligerent exchanges.Output: 1.4​Input: Adjective "scandalous" refers to behavior or matters that provoke or contain scandals. Sensational revelations, frauds, or unethical conduct may be considered scandalous. It captivates public attentionOutput: 1.6​Input: A whirligig is a whirl, a motion rhythmic and rapid, bringing moments of serenity as it twirls delicate ribbon-like streams, creating an enchanting spectacle.A whirlOutput: 1.8​Input: Explicit or implicit in relationship and organization management across entertainment modes widely establishes reserved forms inferred through gestures expressing transitions alert participants intervening reign episodes welcoming completion better-yodied explanations enhance management sequential connecting dialog regarding positioned proceedings concurrentOutput: 2.0​Input:
1
Output:
Parameters: 1


Applying the function (
temperatureGuesser
)

Now that we have our
temperatureGuesser
function, we need to create a test data set of essays. We’ll follow the previous steps to generate a new set of random words and temperatures, and then use these to create a set of essays for testing.
SeedRandom[1234];​​testWords=Drop[RandomWord[51],11];​​(*Generates11seedwords,fixedtoasetbytheSeedRandomfunction*)
We use random integer to get 20 different temperatures.
SeedRandom[1234];​​testTemperatures=N[RandomInteger[{0,200},40]/100]
Using the same method, we did to generate the initial essays we generate a new set for testing purposes
tests=generatedText=MapThread[LLMSynthesize["Write 40 word essay about the word "<>#1,LLMEvaluator-><|"Model"->"gpt-3.5-turbo","Temperature"->#2|>,MaxItems->40]&,{testWords,testTemperatures}];
We can now apply our
temperatureGuesser
function to our sample essay set using the
Map
function.
In[]:=
testResults=Map[temperatureGuesser,tests]
Creating a
BarChart
that displays the difference between our
testResults
and the
testTemperatures
(the original temperatures). To help evaluate the performance of our temperature prediction function.
In[]:=
BarChart[Map[ToExpression,testResults]-testTemperatures]
It seems our function is consistently overestimating temperatures?

Reworking the function (
temperatureGuesser
)

Our function is consistently overestimating temperatures, likely due to the ascending order of our training data. This ordering may cause gpt-3.5-turbo to expect each subsequent temperature to be higher. To address this, we can use Mathematica’s
RandomSample
function to randomize our data, potentially improving the function’s accuracy. Here is an example of how
RandomSample
works so you can see for yourself.
In[]:=
RandomSample[{"1"->1,2,3,4}]
Now, let’s apply the
RandomSample
function to our
temperatureGuesser
function. By shuffling the examples and rewriting our function, we aim to resolve the issue of overestimation.
In[]:=
SeedRandom[1234];​​temperatureGuesser2=LLMExampleFunction[{"Guess the token sampling temperature used to generate a piece of text using a GPT model:",RandomSample[fewShotExamples]},"Expression",LLMEvaluator-><|"Model"->"gpt-3.5-turbo"|>]
Out[]=
LLMFunction
​
Content: Guess the token sampling temperature used to generate a piece of text using a GPT model:​Input: Pyrotechnical refers to the art of creating and displaying fireworks. It involves the use of explosives and chemicals to produce dazzling visual effects and loud sounds. Pyrotechnical displays are often seen duringOutput: 0.0​Input: Boom can have multiple meanings, each carrying a powerful connotation. It can represent a sudden loud sound, an explosion, or even a rapid period of economic growth. Regardless of its context, boom alwaysOutput: 1.2​Input: A whirligig is a whirl, a motion rhythmic and rapid, bringing moments of serenity as it twirls delicate ribbon-like streams, creating an enchanting spectacle.A whirlOutput: 1.8​Input: Capaciousness is the quality of having a large capacity or spaciousness. It refers to the ability to accommodate a significant amount or being roomy. This term can describe physical spaces, as well asOutput: 1.0​Input: Explicit or implicit in relationship and organization management across entertainment modes widely establishes reserved forms inferred through gestures expressing transitions alert participants intervening reign episodes welcoming completion better-yodied explanations enhance management sequential connecting dialog regarding positioned proceedings concurrentOutput: 2.0​Input: Adjective "scandalous" refers to behavior or matters that provoke or contain scandals. Sensational revelations, frauds, or unethical conduct may be considered scandalous. It captivates public attentionOutput: 1.6​Input: Belligerency refers to the aggressive, hostile behavior adopted during conflicts or war. It involves displaying mindset obstinately intent on fighting. Political debates often devolve into belligerent exchanges.Output: 1.4​Input: The word "tenability" refers to the quality of being able to be defended or supported. It represents the strength and viability of an argument, idea, or position. Critical thinking and evidence play aOutput: 0.8​Input: Talented individuals possess a natural ability or skill that sets them apart. Whether it be in the arts, sports, or academics, their innate talent enables them to excel effortlessly. These gifted individuals inspireOutput: 0.6​Input: Jammed, a word that describes a state of being stuck or blocked, can apply to various situations. From a traffic jam to a jammed door, it signifies an obstacle hindering progress. WhetherOutput: 0.4​Input: Absorbing is a word that describes something captivating and engrossing. It refers to an activity or experience that completely absorbs one's attention and interest. Whether it's a book, movie, orOutput: 0.2​Input:
1
Output:
Parameters: 1

We can now reapply the
temperatureGuesser2
function using the previously mentioned data sets to generate our new predictions.
testResults2=Map[temperatureGuesser2,tests]
By plotting our results, it’s evident that the randomization has significantly improved the performance of our function.
In[]:=
BarChart[testResults2-testTemperatures]

A more nuanced approach, creating a Language Coherence Grader

Our function returns a numeric grade from 1-5 for each of the five psycholinguistic parameters, along with an explanation for each grade. We can format these results in a color-coded grid for easier reading and interpretation.
(The code for these graphics may be found in the notebooks appendix section).
We then did the same thing for interview text from Dr. Dre to compare and contrast and see if our function behaves somewhat stable.
(Once again, the code for these graphics may be found in the notebooks appendix section).
Our coherence grader seems to offers valuable insights across five categories: syntactic complexity, semantic complexity, cohesion, readability, and coherence. It’s reliable, consistent, has meaningful explanations, and lends itself to clear visualizations. Future enhancements include collecting more relevant datasets and refining the LLM function. If the same text is tested a number of times how much do the results vary? Currently, it’s a solid foundation and we’re considering submitting it to the Wolfram Prompt Repository or Wolfram Function Repository.

Concluding remarks

Although LLM Few-shot learning functions (alone) are not great for evaluating temperature, humans may be worse. However, randomizing learning examples, improves LLM functions. To visualize LLM high-dimensional embedding space, we plotted the trajectories of sequence of tokens and compared them at different temperatures. Using a basic psycholinguistic model we created a prompt with a one-shot learning example, that allows us to grade text coherence using an LLM.
​
In the future we would like to refine our few-shot learning examples for large language models (LLMs) and explore modifying the embedding layer, neural layer, attention layer, etc., modify activation functions. Compare our generated text against a variety of transcripts from patients on drugs. Consider submitting our work to the Wolfram Prompt Repository or Wolfram Function Repository. Enhance our understanding of psycholinguistic models to visualize “meaning-space”. In the long term, explore Xenolinguistics models to develop more profound psycholinguistic functions.

Keywords

#LLMS, Large Language Models, ChatGPT, Psychedelics, Drugs, one-shot learning, few-shot learning, Xenolinguistics, psycholinguistic, temperature, Randomizing

Acknowledgment

I would like to kindly acknowledge my mentor Jofre Espigule for guiding me through the entire process,Theodore Gray for clarity on the “hallucination effect”, Bob Nachbar for clarifying “what LLM’s are doing”, Mark Greenberg for visualizations, Aaron Carver for editing, and Stephen Wolfram for defining the project for me.

Appendix

CITE THIS NOTEBOOK

What Happens IF You "DRUG" LLMs?​
by Michael Grey​
Wolfram Community, STAFF PICKS, July 12, 2023
​https://community.wolfram.com/groups/-/m/t/2959382