pipeline: Run a Full Text Classification Pipeline on Preprocessed Text

View source: R/pipeline.R

pipelineR Documentation

Run a Full Text Classification Pipeline on Preprocessed Text

Description

This function takes a data frame with pre-cleaned text and handles the data splitting, vectorization, model training, and evaluation.

Usage

pipeline(
  vect_method,
  model_name,
  text_vector,
  sentiment_vector,
  n_gram = 1,
  balance = FALSE,
  tune = FALSE,
  parallel = FALSE
)

Arguments

vect_method

A string specifying the vectorization method. Defaults to "bag_of_words".

  • "bag_of_words" (Alias: "bow") - Standard count of words.

  • "term_frequency" (Alias: "tf") - Normalized counts.

  • "tfidf" (Alias: "tf-idf") - Term Frequency-Inverse Document Frequency.

  • "binary" - Presence/Absence (1/0).

model_name

A string specifying the model to train. Defaults to "logistic_regression".

  • "random_forest" (Alias: "rf")

  • "xgboost" (Alias: "xgb")

  • "logistic_regression" (Alias: "logit", "glm")

text_vector

A character vector containing the **preprocessed** text.

sentiment_vector

A vector or factor containing the target labels (e.g., ratings).

n_gram

The n-gram size to use for BoW/TF-IDF. Defaults to 1.

balance

Logical. If TRUE, calculates inverse class weights to correct for imbalanced datasets. Defaults to FALSE.

tune

Logical. If TRUE, the pipeline will perform hyperparameter tuning for the selected model. Defaults to FALSE. [NEW]

parallel

If TRUE, runs model training in parallel. Default FALSE.

Value

A list containing the trained model object, the DFM template, class levels, and a comprehensive evaluation report.

Examples

df <- data.frame(
  text = c("good product", "excellent", "loved it", "great quality",
           "bad service", "terrible", "hated it", "awful experience",
           "not good", "very bad", "fantastic", "wonderful"),
  y = c("P", "P", "P", "P", "N", "N", "N", "N", "N", "N", "P", "P")
)


out <- pipeline("bow", "naive_bayes",  text_vector = df$text, sentiment_vector = df$y)


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