Learn R Programming

NaileR (version 1.2.2)

dist_mat_llm: LLM distance matrix

Description

Compute a distance matrix between randomly-generated responses to an LLM prompt.

Usage

dist_mat_llm(ppt, n, per_miss = 0)

Value

A list containing:

  • a list of the LLM results for each iteration;

  • a distance matrix.

Arguments

ppt

an LLM prompt.

n

the number of responses to be generated.

per_miss

the proportion of missing values in the final matrix (between 0 and 1; 0 by default).

Details

The final percentage of missing values might differ from the per_miss parameter value; rather than a percentage of values being turned to NA, each value has a per_miss probability of being NA.

Examples

Run this code
if (FALSE) {
# Processing time is often longer than ten seconds
# because the function uses a large language model.

data(iris)

intro_iris <- "A study measured various parts of iris flowers
from 3 different species: setosa, versicolor and virginica.
I will give you the results from this study.
You will have to identify what sets these flowers apart."
intro_iris <- gsub('\n', ' ', intro_iris) |>
stringr::str_squish()

req_iris <- "Please explain what makes each species distinct.
Also, tell me which species has the biggest flowers,
and which species has the smallest."
req_iris <- gsub('\n', ' ', req_iris) |>
stringr::str_squish()

res_iris <- nail_catdes(iris, num.var = 5,
introduction = intro_iris, request = req_iris)

dist_mat_llm(res_iris$prompt, n = 5, per_miss = 0)
}

Run the code above in your browser using DataLab