## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = FALSE
)

## ----setup--------------------------------------------------------------------
#  library(conflibertR)
#  
#  # Run once, then restart R
#  conflibert_install()

## ----ner-single---------------------------------------------------------------
#  ner_results <- conflibert_ner(
#    "The United Nations deployed peacekeepers to eastern Congo
#     after rebel forces attacked Goma on Tuesday."
#  )
#  ner_results

## ----ner-batch----------------------------------------------------------------
#  ner_batch <- conflibert_ner(c(
#    "NATO forces launched airstrikes near Tripoli in March 2024.",
#    "President Zelenskyy met with General Syrskyi in Kyiv."
#  ))
#  ner_batch

## ----classify-----------------------------------------------------------------
#  classify_results <- conflibert_classify(c(
#    "Armed militants stormed a military outpost killing twelve soldiers.",
#    "The European Central Bank held interest rates steady at 4.5 percent.",
#    "Protesters clashed with riot police outside the parliament building.",
#    "A new trade agreement was signed between Japan and Australia."
#  ))
#  classify_results

## ----multilabel---------------------------------------------------------------
#  event_results <- conflibert_multilabel(c(
#    "A car bomb exploded near the government ministry in Baghdad.",
#    "Gunmen kidnapped three aid workers travelling through the Sahel region."
#  ))
#  event_results

## ----qa-----------------------------------------------------------------------
#  context <- "On 15 September 2023, ethnic clashes erupted in Manipur, India.
#    The Indian Army deployed two battalions to restore order.
#    At least 60 people were killed and over 200 injured in the violence."
#  
#  conflibert_qa(context, "How many people were killed?")
#  conflibert_qa(context, "Who was deployed to restore order?")
#  conflibert_qa(context, "Where did the clashes occur?")

## ----benchmark----------------------------------------------------------------
#  data <- conflibert_example("binary")
#  bench <- conflibert_benchmark(data$test$text, data$test$label)
#  bench

## ----finetune-binary----------------------------------------------------------
#  data <- conflibert_example("binary")
#  
#  result <- conflibert_finetune(
#    train  = data$train,
#    dev    = data$dev,
#    test   = data$test,
#    model  = "ConfliBERT",
#    task   = "binary",
#    epochs = 3
#  )
#  
#  cat("Accuracy:", result$metrics$accuracy, "\n")
#  cat("F1 Score:", result$metrics$f1, "\n")

## ----finetune-inspect---------------------------------------------------------
#  # Per-sample predicted labels
#  head(result$predictions)
#  
#  # Class probability matrix (rows = samples, columns = classes)
#  head(result$probabilities)
#  
#  # Saved model directory (NULL if save_dir was not set)
#  result$model_dir

## ----compare------------------------------------------------------------------
#  comparison <- conflibert_compare(
#    train  = data$train,
#    dev    = data$dev,
#    test   = data$test,
#    models = c("ConfliBERT", "BERT Base Uncased", "DistilBERT Base"),
#    task   = "binary",
#    epochs = 3
#  )
#  comparison

## ----models-------------------------------------------------------------------
#  conflibert_models()

## ----finetune-multiclass------------------------------------------------------
#  mc_data <- conflibert_example("multiclass")
#  
#  mc_result <- conflibert_finetune(
#    train  = mc_data$train,
#    dev    = mc_data$dev,
#    test   = mc_data$test,
#    model  = "ConfliBERT",
#    task   = "multiclass",
#    epochs = 3
#  )
#  
#  cat("Multiclass Accuracy:", mc_result$metrics$accuracy, "\n")
#  cat("Multiclass F1:      ", mc_result$metrics$f1, "\n")

