library(tidyverse)
library(casimir)
library(furrr)
gold <- tibble::tribble(
~doc_id, ~label_id,
"A", "a",
"A", "b",
"A", "c",
"B", "a",
"B", "d",
"C", "a",
"C", "b",
"C", "d",
"C", "f",
)
pred <- tibble::tribble(
~doc_id, ~label_id,
"A", "a",
"A", "d",
"A", "f",
"B", "a",
"B", "e",
"C", "f",
)
plan(sequential) # or whatever resources you have
a <- compute_set_retrieval_scores(
pred, gold,
mode = "doc-avg",
compute_bootstrap_ci = TRUE,
n_bt = 100L
)
ggplot(a, aes(x = metric, y = value)) +
geom_bar(stat = "identity") +
geom_errorbar(aes(ymin = ci_lower, ymax = ci_upper)) +
facet_wrap(vars(metric), scales = "free")
# example with graded relevance
pred_w_relevance <- tibble::tribble(
~doc_id, ~label_id, ~relevance,
"A", "a", 1.0,
"A", "d", 0.0,
"A", "f", 0.0,
"B", "a", 1.0,
"B", "e", 1 / 3,
"C", "f", 1.0,
)
b <- compute_set_retrieval_scores(
pred_w_relevance, gold,
mode = "doc-avg",
graded_relevance = TRUE
)
Run the code above in your browser using DataLab