predict_sentiment: Predict Sentiment on New Data Using a Saved Pipeline Artifact

View source: R/prediction.R

predict_sentimentR Documentation

Predict Sentiment on New Data Using a Saved Pipeline Artifact

Description

This is a generic prediction function that handles different model types and ensures consistent preprocessing and vectorization for new, unseen text.

Usage

predict_sentiment(pipeline_object, text_column, threshold = 0.5)

Arguments

pipeline_object

A list object returned by the main 'pipeline()' function. It must contain the trained model, DFM template, preprocessing function, and n-gram settings.

text_column

A string specifying the column name of the text to predict.

threshold

Numeric. Optional custom threshold for binary classification. If NULL, uses the optimized threshold from training (if available).

Value

A data frame containing the 'predicted_class' and probability columns.

Examples


if (exists("my_artifacts")) {
  dummy_df <- data.frame(text = c("loved it", "hated it"), stringsAsFactors = FALSE)
  preds <- predict_sentiment(my_artifacts, df = dummy_df, text_column = "text")
 }



quickSentiment documentation built on Aug. 29, 2026, 1:07 a.m.