library(ellmer)Text Analysis with large language models
Emi Tanaka
3th June 2025
These slides are best viewed on a modern browser like Google Chrome on a desktop or laptop. You can navigate the slides using the left and right arrows.
ellmermodels_<provider>() id created_at owned_by
NA.36 codex-mini-latest 2025-05-08 system
NA.45 gpt-image-1 2025-04-24 system
6 gpt-4.1-2025-04-14 2025-04-10 system
3 gpt-4.1 2025-04-10 system
7 gpt-4.1-mini-2025-04-14 2025-04-10 system
4 gpt-4.1-mini 2025-04-10 system
8 gpt-4.1-nano-2025-04-14 2025-04-10 system
5 gpt-4.1-nano 2025-04-10 system
NA.29 o4-mini 2025-04-09 system
NA.10 o4-mini-2025-04-16 2025-04-08 system
NA.9 gpt-4o-mini-tts 2025-03-19 system
19 o1-pro-2025-03-19 2025-03-17 system
18 o1-pro 2025-03-17 system
NA.18 gpt-4o-transcribe 2025-03-15 system
NA.39 gpt-4o-mini-transcribe 2025-03-15 system
24 gpt-4o-mini-search-preview 2025-03-07 system
25 gpt-4o-mini-search-preview-2025-03-11 2025-03-07 system
27 gpt-4o-search-preview-2025-03-11 2025-03-07 system
26 gpt-4o-search-preview 2025-03-07 system
1 gpt-4.5-preview 2025-02-27 system
2 gpt-4.5-preview-2025-02-27 2025-02-27 system
10 gpt-4o-2024-11-20 2025-02-12 system
21 o3-mini-2025-01-31 2025-01-27 system
20 o3-mini 2025-01-17 system
16 o1-2024-12-17 2024-12-16 system
NA.27 gpt-4o-mini-realtime-preview 2024-12-16 system
15 o1 2024-12-16 system
NA.37 gpt-4o-mini-audio-preview 2024-12-16 system
NA.24 gpt-4o-mini-realtime-preview-2024-12-17 2024-12-13 system
NA.25 gpt-4o-mini-audio-preview-2024-12-17 2024-12-13 system
NA.30 gpt-4o-audio-preview-2024-12-17 2024-12-12 system
NA.44 gpt-4o-realtime-preview-2024-12-17 2024-12-11 system
NA.41 omni-moderation-2024-09-26 2024-11-27 system
NA.42 omni-moderation-latest 2024-11-15 system
NA.43 gpt-4o-realtime-preview 2024-09-30 system
NA.15 gpt-4o-audio-preview 2024-09-27 system
NA.33 gpt-4o-audio-preview-2024-10-01 2024-09-26 system
NA.21 gpt-4o-realtime-preview-2024-10-01 2024-09-23 system
22 o1-mini 2024-09-06 system
23 o1-mini-2024-09-12 2024-09-06 system
NA.40 o1-preview 2024-09-06 system
17 o1-preview-2024-09-12 2024-09-06 system
NA.26 chatgpt-4o-latest 2024-08-13 system
11 gpt-4o-2024-08-06 2024-08-04 system
14 gpt-4o-mini-2024-07-18 2024-07-16 system
13 gpt-4o-mini 2024-07-16 system
12 gpt-4o-2024-05-13 2024-05-10 system
9 gpt-4o 2024-05-10 system
NA.6 gpt-4-turbo-2024-04-09 2024-04-08 system
NA.5 gpt-4-turbo 2024-04-05 system
NA.19 gpt-4-turbo-preview 2024-01-23 system
NA.20 gpt-4-0125-preview 2024-01-23 system
NA.35 gpt-3.5-turbo-0125 2024-01-23 system
NA.28 text-embedding-3-large 2024-01-22 system
NA.38 text-embedding-3-small 2024-01-22 system
NA.4 tts-1-hd 2023-11-03 system
NA.14 tts-1-hd-1106 2023-11-03 system
NA.32 tts-1-1106 2023-11-03 system
NA.22 gpt-4-1106-preview 2023-11-02 system
NA.31 gpt-3.5-turbo-1106 2023-11-02 system
NA dall-e-2 2023-11-01 system
NA.13 dall-e-3 2023-10-31 system
NA.7 gpt-3.5-turbo-instruct-0914 2023-09-07 system
NA.8 gpt-3.5-turbo-instruct 2023-08-24 system
NA.1 babbage-002 2023-08-21 system
NA.3 davinci-002 2023-08-21 system
NA.11 gpt-4 2023-06-27 openai
NA.17 gpt-4-0613 2023-06-12 openai
NA.16 gpt-3.5-turbo-16k 2023-05-10 openai-internal
NA.34 tts-1 2023-04-19 openai-internal
NA.23 gpt-3.5-turbo 2023-02-28 openai
NA.2 whisper-1 2023-02-27 openai-internal
NA.12 text-embedding-ada-002 2022-12-16 openai-internal
cached_input input output
NA.36 NA NA NA
NA.45 NA NA NA
6 0.500 2.00 8.0
3 0.500 2.00 8.0
7 0.100 0.40 1.6
4 0.100 0.40 1.6
8 0.025 0.10 0.4
5 0.025 0.10 0.4
NA.29 NA NA NA
NA.10 NA NA NA
NA.9 NA NA NA
19 NA 150.00 600.0
18 NA 150.00 600.0
NA.18 NA NA NA
NA.39 NA NA NA
24 NA 0.15 0.6
25 NA 0.15 0.6
27 NA 2.50 10.0
26 NA 2.50 10.0
1 37.500 75.00 150.0
2 37.500 75.00 150.0
10 1.250 2.50 10.0
21 0.550 1.10 4.4
20 0.550 1.10 4.4
16 7.500 15.00 60.0
NA.27 NA NA NA
15 7.500 15.00 60.0
NA.37 NA NA NA
NA.24 NA NA NA
NA.25 NA NA NA
NA.30 NA NA NA
NA.44 NA NA NA
NA.41 NA NA NA
NA.42 NA NA NA
NA.43 NA NA NA
NA.15 NA NA NA
NA.33 NA NA NA
NA.21 NA NA NA
22 0.550 1.10 4.4
23 0.550 1.10 4.4
NA.40 NA NA NA
17 7.500 15.00 60.0
NA.26 NA NA NA
11 1.250 2.50 10.0
14 0.075 0.15 0.6
13 0.075 0.15 0.6
12 NA 5.00 15.0
9 1.250 2.50 10.0
NA.6 NA NA NA
NA.5 NA NA NA
NA.19 NA NA NA
NA.20 NA NA NA
NA.35 NA NA NA
NA.28 NA NA NA
NA.38 NA NA NA
NA.4 NA NA NA
NA.14 NA NA NA
NA.32 NA NA NA
NA.22 NA NA NA
NA.31 NA NA NA
NA NA NA NA
NA.13 NA NA NA
NA.7 NA NA NA
NA.8 NA NA NA
NA.1 NA NA NA
NA.3 NA NA NA
NA.11 NA NA NA
NA.17 NA NA NA
NA.16 NA NA NA
NA.34 NA NA NA
NA.23 NA NA NA
NA.2 NA NA NA
NA.12 NA NA NA
id created_at size
1 llama3.2:1b 2024-10-08 1321098329
2 llava:13b 2024-10-02 8011256494
3 llava:7b 2024-10-01 4733363377
4 gemma2:9b 2024-08-28 5443152417
5 mistral:7b 2024-08-28 4113301824
6 openchat:7b 2024-08-28 4109876386
7 llama3.1:70b 2024-08-27 39969751650
8 llama3.1:8b 2024-08-20 4661230977
9 gemma:2b 2024-08-10 1678456656
10 gemma:7b 2024-08-10 5011853225
11 llama3:8b 2024-08-10 4661224676
12 llama3:70b 2024-08-10 39969745349
13 llama3.1 2024-08-10 4661230977
What do you remember about the 25% quantile (also called the first quartile) in
a standard normal distribution? How might you use the standard normal table or
an inverse normal function to find it?
I’m here to help you understand how to find it yourself! If you think about the
cumulative distribution function (CDF) for the standard normal distribution,
what value corresponds to 0.25? How might you find the z-score where the area
to the left is 0.25? Would looking up an inverse CDF (or using a calculator)
help?
ellmer<Chat OpenAI/gpt-4.1-mini turns=5 tokens=140/115 $0.00>
── system [0] ──────────────────────────────────────────────────────────────────
You are a Socrates statistics tutor.
Don't ever tell the answer.
── user [41] ───────────────────────────────────────────────────────────────────
What is the 25% quantile from the standard normal distribution?
── assistant [42] ──────────────────────────────────────────────────────────────
What do you remember about the 25% quantile (also called the first quartile) in a standard normal distribution? How might you use the standard normal table or an inverse normal function to find it?
── user [16] ───────────────────────────────────────────────────────────────────
Can you just tell me the answer?
── assistant [73] ──────────────────────────────────────────────────────────────
I’m here to help you understand how to find it yourself! If you think about the cumulative distribution function (CDF) for the standard normal distribution, what value corresponds to 0.25? How might you find the z-score where the area to the left is 0.25? Would looking up an inverse CDF (or using a calculator) help?

shinychat package provides a pretty interface and useful functions to add a chatbot functionality in R Shiny.library(shiny)
library(ellmer)
library(shinychat)
ui <- bslib::page_fillable(
chat_ui("chat")
)
server <- function(input, output, session) {
chat <- chat_openai("You are a Socrates statistics tutor.
Don't ever tell the answer.",
model = "gpt-4.1-mini")
chat_append("chat", "Hi there! How can I help you with STAT101?")
observeEvent(input$chat_user_input, {
stream <- chat$stream_async(input$chat_user_input)
chat_append("chat", stream)
})
}
shinyApp(ui, server)

chat <- ellmer::chat_openai()
chat$chat("Identify the animal in the image",
content_image_url("https://upload.wikimedia.org/wikipedia/commons/1/15/Cat_August_2010-4.jpg"))The animal in the image is a domestic cat (Felis catus). It
appears to be a tabby cat, characterized by its striped fur
pattern.

ellmer doesn’t support this yet.chatg <- chat_google_gemini()
chatg$chat("Extract the questions from the following pdf.",
content_pdf_url("https://www.abs.gov.au/system/files/documents/481decdb18d925785b9dfc20727c5cff/Sample%20Special%20Short%20Form%20%5B156KB%5D.pdf"))Here are the questions extracted from the provided PDF:
1. Where did you sleep on Census night, Tuesday 10 August
2021?
2. Are you:
3. What is your date of birth and age?
4. Are you of Aboriginal or Torres Strait Islander origin?
5. What is your current marital status?
6. In which country were you born?
7. What is your total weekly income from all sources?
8. Have you ever served in the Australian Defence Force?
9. What is your name?
10. Do you agree to your name and other information on this
form being kept by the National Archives of Australia and
then made publicly available after 99 years?
11. Declaration
Question time from Australian Senate 26th March 2025
library(httr2)
json <- request(base_url = "https://api.openai.com/v1/audio/transcriptions") |>
req_headers('Authorization' = paste('Bearer', Sys.getenv("OPENAI_API_KEY")),
'Content-Type' = "multipart/form-data") |>
req_body_multipart(file = curl::form_file("senate-question-time-audio.m4a",
type = "audio/m4a"),
model = "gpt-4o-transcribe") |>
req_perform() |>
resp_body_json()
cat(json$text)Thank you, Madam President. My question is to the Minister representing the Treasurer, Senator Gallagher. After three years of Labor, Australians are poorer. Because of Labor's failed policies, Australians have experienced the biggest drop in living standards in decades.
(for fun)
dall-e-2, dall-e-3, or gpt-image-1 models from Open AI are examples of these LLMs.json <- request(base_url = "https://api.openai.com/v1/images/generations") |>
req_headers('Authorization' = paste('Bearer', Sys.getenv("OPENAI_API_KEY")),
'Content-Type' = "application/json") |>
req_body_json(data = list(model = "dall-e-2",
prompt = "A woman coding in R.",
n = 1,
size = "1024x1024")) |>
req_perform() |>
resp_body_json()text <- "Once upon a time, in the Kingdom of Probabilia, lived Princess Percentia.
She wasn't like the other princesses, who dreamed of dancing and dashing princes.
Percentia adored numbers. While her sisters embroidered samplers,
Percentia meticulously collected data on the local butterfly population,
categorized cloud formations, and charted the daily rainfall."
request(base_url = "https://api.openai.com/v1/audio/speech") |>
req_headers('Authorization' = paste('Bearer', Sys.getenv("OPENAI_API_KEY")),
'Content-Type' = "application/json") |>
req_body_json(data = list(model = "gpt-4o-mini-tts",
input = text,
voice = "fable")) |>
req_perform(path = "fairytale.mp3") Let’s discuss
How do LLMs complement or hinder statistical thinking?
What role should LLMs play in decision-making processes and research?
How will LLMs impact the training and development of future statisticians and data scientists?
What are the use cases of LLM for you (if any)?
emitanaka.org/workshop-text-analysis-2025/