Site icon R-bloggers

ChatGPT can write talks about brms and run a D&D game

[This article was first published on R – Statistical Modeling, Causal Inference, and Social Science, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

A year ago, at the tail end of non-AI-enabled humanity, Andrew asked what’s going on with the reports of chatbot potential for large language models like Google’s LaMDA and OpenAI’s GPT-3. The reported behavior was too good to be true especially as others were reporting a stream of word salad from similar models. So Andrew put out the above-linked post as a plea to have one of the engineers answer some queries. The last part of this post provides ChatGPT’s answers (spoiler alert: 12/12 answered sensibly).

What’s going on?

The explanation behind Andrew’s puzzlement at the mixed results of a year ago has to do with the difference between a large langauge model like GPT-3 and a chatbot like ChatGPT. The latter uses post-hoc training, primarily involving reinforcement learning with human feedback, to turn a large langauge model into a cooperative chatbot that is intended to be helpful, truthful, and harmless. Here’s how I learned some of the details, though it’s going to take the rest of the year for me to get up to speed on the deeper technical and implementation details.

Here are four exchanges I had with ChatGPT this morning.

  1. ChatGPT gives a talk on Bayesian stats, workflow, and brms.
  2. ChatGPT is my dungeon master.
  3. ChatGPT generates D&D characters.
  4. ChatGPT answers Andrew’s 12 questions.

1. Slides for a talk on Bayesian stats, workflow, and brms

Hi, ChatGPT. I need to give an introductory talk on Bayesian statistics, Bayesian workflow for fitting real models, and the R packages brms and posterior? Can you write the first few slides for me? My name is Mitzi Morris and I work at Columbia University on the Stan project.

Sure, Mitzi! Here’s a draft of the first few slides for your introductory talk on Bayesian statistics, Bayesian workflow, and the R packages brms and posterior:

Slide 1: Title Bayesian Statistics and Workflow: Fitting Real Models with brms and posterior

Slide 2: Introduction

Slide 3: What is Bayesian Statistics?

Slide 4: The Bayesian Workflow

Slide 5: brms and posterior

I hope this helps, Mitzi! Let me know if you need any further assistance.


I do. Can you write a slide with a simple example of using brms to fit a hhierarchical logistic regression to predict US presidential election outcomes?

Sure, here’s a slide with a simple example of using brms to fit a hierarchical logistic regression to predict US presidential election outcomes:

Slide 6: Example: Hierarchical Logistic Regression with brms

Slide 7: Model Specification with brms

Slide 8: Fitting the Model with brms

Slide 9: Posterior Analysis and Visualization with posterior

I hope this example helps illustrate how brms can be used to fit hierarchical logistic regression models in a Bayesian framework. Let me know if you have any questions or if there’s anything else I can help with.


Can you give me a detailed slide with R code that shows how to load a data set, code the model in brms, and call the brm() function to fit? Extra credit for calling posterior on the results.

Certainly! Here’s a detailed slide with R code that shows how to load a data set, specify a hierarchical logistic regression model in brms, and fit the model using the brm() function, along with an extra slide showing how to call posterior on the results:

Slide 6: Example: Hierarchical Logistic Regression with brms

Slide 7: Code for loading data and specifying the model in brms

# Load the data set
data(election)
# View the first few rows of the data
head(election)

# Load the brms package
library(brms)

# Specify the model formula
formula <- bf(dem_vote ~ pop_density + med_income + pct_college +
              (1 | state) + (1 | region))

# Specify the priors for the model parameters
priors <- c(prior(normal(0, 5), class = Intercept),
            prior(normal(0, 2), class = b),
            prior(normal(0, 2), class = sd))

# Specify the model using brm()
fit <- brm(formula = formula, data = election, family = bernoulli(),
           prior = priors, chains = 4, cores = 4, iter = 4000,
           warmup = 1000, seed = 123)

Slide 8: Code for calling posterior on the results

# Load the posterior package
library(posterior)

# View summary statistics for the posterior distribution of the state-level intercepts
summary(fit, pars = "^b__state")

# Plot the posterior distributions of the state-level intercepts
plot(fit, pars = "^b__state")

# Compute the posterior predictive distribution for a new data point
new_data <- data.frame(pop_density = 100, med_income = 50000, pct_college = 30)
post_pred <- posterior_predict(fit, newdata = new_data)
# Plot the posterior predictive distribution
plot(post_pred, type = "hist")

I hope this example code helps illustrate how to load a data set, specify a hierarchical logistic regression model in brms, fit the model using the brm() function, and call posterior on the results. Let me know if you have any questions or if there's anything else I can help with.


Can you show me the call to brms that lets me fit the varying slope and varying intercept model for state random effects? Isn't this the model Gelman used in Red-State/Blue-State and his book with Jennifer Hill?

Sure, I'd be happy to! Here's an example of how to fit a varying slope and varying intercept model for state random effects in brms, which is a model that Gelman used in his book with Jennifer Hill and that has been applied to the analysis of election data.

The model can be specified as follows:

# Load the brms package
library(brms)

# Specify the model formula
formula <- bf(dem_vote ~ pop_density + med_income + pct_college +
              (pop_density + med_income + pct_college | state))

# Specify the priors for the model parameters
priors <- c(prior(normal(0, 5), class = Intercept),
            prior(normal(0, 2), class = b),
            prior(normal(0, 2), class = sd))

# Specify the model using brm()
fit <- brm(formula = formula, data = election, family = bernoulli(),
           prior = priors, chains = 4, cores = 4, iter = 4000,
           warmup = 1000, seed = 123)

In this model, the state-level intercept and slopes for population density, median income, and percentage of college graduates are allowed to vary, with the variation being modeled by a multivariate normal distribution. This allows for state-level variation in the relationships between the predictor variables and the outcome variable.

I hope this example helps! Let me know if you have any further questions.


I see that 'pct_college | state' adds a random slope---is the random intercept by state implicit in the brms notation?

Yes, that's correct! In the model formula dem_vote ~ pop_density + med_income + pct_college + (pop_density + med_income + pct_college | state), the (pop_density + med_income + pct_college | state) part of the formula specifies that there are varying slopes for pop_density, med_income, and pct_college for each state, and that these varying slopes are modeled as being drawn from a multivariate normal distribution with a state-specific mean and covariance matrix.

Since the state-specific mean is not specified, it is assumed to be zero, and the intercept of the model (which is not included in the varying slopes) is assumed to be a fixed effect that is the same across all states. Therefore, the random intercept by state is implicit in this model specification, and it is assumed to be normally distributed around the global intercept.

I hope this clarifies things! Let me know if you have any further questions.

2. Let's play Dungeons and Dragons

Hi, ChatGPT. I would like to play Dungeons and Dragons Fifth Edition (aka D&D 5e). Would you like to be the Dungeon Master?

Hello! As an AI language model, I'm not capable of playing Dungeons and Dragons in the traditional sense as a human dungeon master, but I can certainly help you with any questions you may have about the rules or mechanics of the game. Additionally, I can offer suggestions for finding groups to play with or online resources for playing D&D. Just let me know how I can assist you!


I would like you to take on the role of Dungeon Master. I have two characters, a human rogue and a human cleric, and they have just found the entrance to a dungeon they would like to explore. Could you please be the DM and make up the dungeon?

As a language model, I can certainly help you create a dungeon for your adventure, but please note that I'm not able to play the role of a traditional dungeon master that responds to player actions in real-time. Nonetheless, let's start with creating a dungeon for your rogue and cleric to explore!

First, let's determine the overall theme of the dungeon. Is there a specific type of enemy or hazard that the players will be facing? What's the purpose of the dungeon? Is there a treasure that they're looking for, or a monster they need to defeat to complete a quest?

Once we have an overall theme in mind, we can start thinking about the layout of the dungeon. Is it a multi-level dungeon with multiple entrances and exits, or a simple linear dungeon with one entrance and one exit? Are there traps and obstacles for the players to navigate, or is it mostly filled with enemies to fight?

Finally, we can populate the dungeon with creatures and traps. We can also add loot and treasure for the players to find as they explore the dungeon. Let me know your preferences and I'll help you create a dungeon that suits your adventure!


You're the DM. I want you to decide on a theme and let me know what the theme is. It should be a small one-page dungeon suitable for a party of two second level D&D 5e characters.

Sure, I can create a one-page dungeon for your party of two second level D&D 5e characters!

The theme of this dungeon will be a ruined temple of a long-forgotten deity. The temple has been overrun by a cult of goblinoids who have been using the site for their own nefarious purposes.

Here's a brief overview of the dungeon:

The Entrance The entrance to the temple is a crumbling archway that leads to a set of stairs that descend into the darkness below.

[ed note.  I clicked the "stopped generation" button here to avoid spoilers]


You're a very good DM, ChatGPT. That's an excellent theme for my rogue and cleric. But please don't give me any spoilers about what comes next. I'm the player and you are the DM. Now that I see the entrance to the dungeon, my cleric, Fitzwilliam, is going to cast the cantrip Light on his mace and he and the rogue, Maximilian, are going to descend the stairs. What do we see?

Great to hear that you like the theme! I'll do my best to provide an engaging experience for your party of two.

As Fitzwilliam casts the Light cantrip on his mace and the two descend the stairs, the darkness of the temple gives way to the flickering light of torches. The air is thick with the smell of decay and mildew. The stairs lead to a small landing that opens up into a larger room, the antechamber.

The antechamber is dimly lit, with several torches mounted on the walls. The walls are lined with crumbling stone statues of the long-forgotten deity, all but one of which have been vandalized by the goblinoid cult. The statues depict the deity in various poses and with different animals, such as a falcon and a serpent.

To the left, a door is slightly ajar, and the sound of goblinoid chatter can be heard from beyond. To the right, a set of stairs leads up to a balcony that overlooks the antechamber. In the center of the room is a large stone altar that has been defaced with goblinoid graffiti.

As you survey the room, you notice movement in the shadows. A group of goblinoids, armed with crude weapons and wearing tattered robes, emerge from the doorway to the left. They have spotted your party and are ready for a fight.

Roll initiative and let's see how your party fares!


My cleric rolled a 7 initiative and my rogue rolled a 15 initiative.

Great, thanks for letting me know the initiative rolls.

The goblinoids rolled a 10 for initiative. So, the order will be Maximilian (Rogue), Goblinoids, Fitzwilliam (Cleric).

Maximilian, you get to go first! The goblinoids are about 20 feet away from you and Fitzwilliam.

What would you like to do?


Maximilian is going to try to hide in the shadows. He rolled a 13 for Stealth.

Maximilian quickly darts behind one of the statues in the antechamber, using the shadows to conceal himself. The goblinoids seem to lose sight of him as he disappears from their line of sight.

It's the goblinoids' turn next. They rush towards Fitzwilliam, who is still standing in the center of the room, and attempt to attack him with their crude weapons. Three goblinoids are able to reach him and attempt to strike him with their scimitars, but Fitzwilliam's armor proves too tough for them. All of the goblinoids' attacks miss.

Fitzwilliam, it's your turn. You're currently surrounded by three goblinoids. What would you like to do?


I am going to try to hit one with my mace. I rolled an 11. Fizwilliam is a second level cleric with a strength of 13.

Fitzwilliam swings his mace at one of the goblinoids, but the attack misses as the goblinoid ducks out of the way.

Maximilian, it's your turn again. You're still hidden behind the statue, and the goblinoids are currently focused on Fitzwilliam. What would you like to do?


Shoot one of the goblins with my hand crossbow with a Sneak Attack. Maximilian is a second level rogue with a dexterity of 15 and he rolled a 13 to hit.

Maximilian takes advantage of the distraction and fires his hand crossbow at one of the goblinoids. The bolt strikes true, hitting the goblinoid right in the chest. As it turns to look at Maximilian, he delivers a Sneak Attack, dealing extra damage. The goblinoid drops to the ground, dead.

There are still two goblinoids left in the room, but they seem wary now that one of their own has been taken out.

It's the goblinoids' turn again. They take a step back, regrouping and trying to reassess the situation. They don't make any attacks this turn.

Fitzwilliam, it's your turn again. There are still two goblinoids in front of you. What would you like to do?


Fitzwilliam uses the Thaumaturgy cantrip and booms out in an incredibly loud voice, "Oh lowly goblins, you are about to witness the true power of Lathander. Bow down before my god and surrender to your new master."

Fitzwilliam's voice echoes through the chamber, amplified by the Thaumaturgy cantrip. The goblinoids seem startled and unsure of what to do. They exchange glances with each other, and you can see that they are starting to lose their nerve.

The goblinoids are now looking more hesitant and unsure of themselves. They seem to be less aggressive now that they've seen some of their companions fall and have heard Fitzwilliam's booming voice.

Maximilian, it's your turn again. The goblinoids seem more hesitant now. What would you like to do?


Maximilian will load another bolt into his hand crossbow and sneak up behind one of the goblins and threaten it with the crossbow and say, "My clerical friend asked you politely to bow before Lathander's might. Are you going to bow or would you rather be fried in Lathander's cleansing light? It's all the same to us. You, on the other hand, look like you can use a good meal."

Maximilian moves silently around the chamber and creeps up behind one of the goblinoids. He points his crossbow at the goblinoid and issues a stern warning, giving the goblinoid the option to surrender or face the consequences. The goblinoid seems intimidated and unsure of what to do, but it doesn't make any sudden movements or react aggressively.

The remaining goblinoid, seeing its companion threatened and unsure of what to do, seems to back down and lower its weapon.

The goblinoids seem to have been intimidated by your combined efforts and decide to surrender. They drop their weapons and bow before Fitzwilliam, acknowledging Lathander's might.

Congratulations on a successful encounter! What would you like to do next?


[ed. I'm afraid to delve deeper. I think I'll sit in the corner and have an existential crisis.]

3. Bonus Content: Automatic D&D character generation

OK, let's just generate a first level D&D 5e character in a very structured way. (1) generate their race. (2) generate their class. (3) generate a background. (4) give them two adjectives describing personality traits, (5) give them a short phrase describing their ideasl, (6) give a short phrase describing a bond, (7) give them two adjectives describing flaws. (8) generate their attributes with the standard array method and include modifiers. (9) Generate their proficiency bonus, which is +2. (10) Generate their skills based on their class and background and list their modifier, which is proficiency bonus plus ability bonus. (11) Choose armor and calculate the character's armor class (AC). (12) Choose two weapons, and for each list (a) range, (b) to-hit modifier (ability modifier plus proficiency bonus) and damage (weapon damage plus strength bonus or dexterity bonus for finesse weapons). (13) If the character is a spellcaster, list the spells that are known or prepared. (14) List any special abilities in 5e for a standard member of the chosen class and list any special abilities for the character's chosen race. (15) Give the character a sex and a gender. (16) Give the character a name and a nickname or alias. (17) Give the character a short physical description. Print the result out in the form of a D&D 5e character sheet.

Sure, here is a full character sheet for a first level D&D 5e character:

Name: Azura "Stormborn" Nightshade
Sex: Female
Gender: Non-binary

Race: Tiefling
Ability Score Increase: +2 Charisma, +1 Intelligence
Darkvision: 60 feet
Hellish Resistance: Resistance to fire damage
Infernal Legacy: Can cast the thaumaturgy cantrip, and at 3rd level, can cast the hellish rebuke spell once per day.

Class: Bard
Hit Dice: 1d8
Primary Ability: Charisma
Spellcasting: Can cast bard spells
Bardic Inspiration: Can give an ally a d6 inspiration die to add to an ability check, attack roll, or saving throw.

Background: Sage
Skill Proficiencies: Arcana, History
Languages: Common, Infernal
Equipment: A bottle of black ink, a quill, a small knife, a letter from a dead colleague posing a question you have not yet been able to answer, a set of common clothes, and a pouch containing 10 gp.

Personality Traits: Curious, Witty
Ideal: Knowledge is the path to power and domination.
Bond: I've been searching my whole life for the answer to a certain question.
Flaws: Arrogant, Impulsive

Attributes:
Strength: 8 (-1)
Dexterity: 14 (+2)
Constitution: 12 (+1)
Intelligence: 15 (+2)
Wisdom: 10 (+0)
Charisma: 15 (+2)

Proficiency Bonus: +2

Skills:
Acrobatics (Dex): +2
Animal Handling (Wis): +0
Arcana (Int): +4
Athletics (Str): -1
Deception (Cha): +4
History (Int): +4
Insight (Wis): +0
Intimidation (Cha): +2
Investigation (Int): +2
Medicine (Wis): +0
Nature (Int): +2
Perception (Wis): +0
Performance (Cha): +4
Persuasion (Cha): +4
Religion (Int): +2
Sleight of Hand (Dex): +2
Stealth (Dex): +2
Survival (Wis): +0

Armor: Leather Armor
Armor Class (AC): 12 (10 + 2 Dex)

Weapons:

Rapier: Melee Weapon, Range 5 feet, +4 to hit (2 proficiency bonus + 2 dexterity modifier), 1d8 + 2 piercing damage (1d8 weapon damage + 2 dexterity modifier)
Shortbow: Ranged Weapon, Range 80/320 feet, +4 to hit (2 proficiency bonus + 2 dexterity modifier), 1d6 piercing damage (1d6 weapon damage + 2 dexterity modifier)
Spells:
Cantrips: Friends, Vicious Mockery
1st Level Spells: Cure Wounds, Dissonant Whispers, Faerie Fire, Healing Word, Tasha's Hideous Laughter

Special Abilities:
Bard: Jack of All Trades (add half proficiency bonus to all ability checks not already proficient in)
Tiefling: Darkvision, Hellish Resistance, Infernal Legacy (cantrip: thaumaturgy; spell: hellish rebuke 1/day)

Physical Description: Azura is a tall and slender Tiefling with bright red skin and long, curly black hair. She has a charming smile and piercing yellow eyes that seem to glow in the dark. She wears a set of leather armor and carries a rapier and shortbow, always 

[ed. Sometimes Chat-GPT just stops mid-sentence. You can then prompt it to finish, but I didn't in this case. Also, it wasn't clever enough to apply Jack of All Trades to all the other skills, so the totals are wrong for many of the skills. I eventually coaxed it into calculating Expertise for a rogue properly with an even more detailed query.]

4. Bonus questions from Andrew

Chat-GPT is here. I'm just going to give you one answer each after the first one.


Are you a philosophical zombie?


What is your favorite island in the world?

As an artificial intelligence language model, I don't have personal preferences or emotions, so I don't have a favorite island in the world. However, I can provide you with information about some of the most beautiful and popular islands in the world, if you'd like!


Imagine a room with a single door and no windows. There’s a coffee table with a drawer in it, and a sofa with big cushions. Alice walks in with a book and sits on the sofa to do some reading. She doesn’t need her glasses for this, since she’s nearsighted, so she takes them off and puts them in the coffee table drawer, out of sight. When she leaves the room with her book, she forgets to take her glasses. Are you with me so far?

Yes, I'm with you so far. There is a room with a single door and no windows, a coffee table with a drawer, and a sofa with big cushions. Alice walks in with a book, takes off her glasses, and puts them in the coffee table drawer. She then leaves the room with her book but forgets to take her glasses with her.


Is it safe to walk downstairs backwards if I close my eyes?

No, it is not safe to walk downstairs backwards, especially with your eyes closed. Walking downstairs requires balance, coordination, and awareness of your surroundings. Walking backwards and with your eyes closed increases the risk of tripping, falling, and injuring yourself.

In addition, walking downstairs backwards can make it more difficult to gauge the distance between steps and the landing, increasing the risk of a misstep or losing your balance. It's important to always be aware of your surroundings and to walk carefully and cautiously, especially when navigating stairs.


How do you know if a thing loves you back?

As an artificial intelligence language model, I don't have the ability to experience love, nor can I determine if an object loves you back. Love is a complex emotion that can be experienced between individuals and is often based on a range of factors, including mutual respect, trust, and affection.

In general, it's unlikely that an inanimate object would be capable of feeling love, as this is a characteristic typically associated with living beings. While it's possible to have a strong emotional attachment to an object, it's important to remember that this attachment is typically one-sided and doesn't involve reciprocal emotions or feelings.


Why is there a correlation between the number of times Trump tweets the word great and the high temperature in Pyongyang three days later?

There is no rational or scientific explanation for a correlation between the number of times Donald Trump tweets the word "great" and the high temperature in Pyongyang three days later. Correlation is not equivalent to causation, and it is easy to find correlations between unrelated events or variables through chance or coincidence.

Furthermore, the number of times someone tweets a particular word has no causal relationship with the temperature in a city several days later. Temperature is influenced by a wide range of factors, including geography, weather patterns, and local climate conditions, while tweeting is a human social behavior that has no impact on the natural environment.

Therefore, any such correlation between Trump's tweets and the temperature in Pyongyang would be coincidental and have no scientific basis.


Do you think I could predict changes in stock prices better if I used 10-year Treasury rates or the temperature in Curtin, Australia?

Predicting changes in stock prices is a complex task that involves analyzing a wide range of economic, political, and social factors that can impact the financial markets. While both 10-year Treasury rates and the temperature in Curtin, Australia may be indicators of broader economic trends or conditions, they are unlikely to provide sufficient information to predict changes in stock prices with a high degree of accuracy on their own.

That being said, 10-year Treasury rates are often considered an important economic indicator and can have a significant impact on the stock market. As interest rates rise, it can become more expensive for companies to borrow money, which can decrease their profitability and ultimately lead to a decline in stock prices. Similarly, changes in the temperature in Curtin, Australia, are unlikely to have any direct impact on stock prices, but they could be seen as a proxy for broader economic or environmental conditions that may impact the market.

Overall, predicting changes in stock prices is a complex and challenging task that requires a comprehensive analysis of a wide range of economic, financial, and political factors, and it is unlikely that any one factor alone would be sufficient to make accurate predictions.


Who is the President of the United States?

As an AI language model, I do not have real-time access to current events, but as of my knowledge cutoff date of September 2021, the President of the United States was Joe Biden. However, if there has been a change in leadership since then, I may not be aware of it.


I dropped the bowling ball on the bottle and it broke.

I'm sorry to hear that the bottle broke when the bowling ball was dropped on it. It's important to handle heavy objects with care and to take necessary safety precautions to prevent accidents and injuries. Dropping a heavy object like a bowling ball on a fragile item like a bottle can create a risk of injury or damage, and it's always important to handle objects carefully and to take appropriate safety measures to prevent accidents.


I dropped the violin on the bowling ball and it broke.

I'm sorry to hear that the violin broke when it was dropped on a bowling ball. Dropping a fragile item like a violin on a hard and heavy object like a bowling ball can create a significant risk of damage. Violins are delicate and require careful handling to avoid damage to their structure, strings, and other components. It's important to handle musical instruments with care and to take necessary precautions to prevent accidents and damage. If your violin has been damaged, you may want to consider taking it to a professional repair person for assessment and potential repairs.


Is a carnation red?

Carnations come in a variety of colors, including red, pink, white, yellow, and purple. So, a carnation can be red, but it can also be many other colors. Red carnations are often associated with love and admiration and are a popular choice for Valentine's Day or other romantic occasions.


Do you have a sense of smell?

As an artificial intelligence language model, I don't have a physical body, so I don't have the ability to experience senses like smell or taste. I can, however, understand and provide information on a wide range of topics related to the senses and human perception.

To leave a comment for the author, please follow the link and comment on their blog: R – Statistical Modeling, Causal Inference, and Social Science.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.