Skip to contents

Loads a designated pretrained model available in the `text2map.pretrained` package. For bundled models (e.g., STM models), uses `data()`. For downloaded models, automatically detects the file format and uses the appropriate loader function.

Usage

load_pretrained(model, location = NULL, quiet = FALSE, dequantize = TRUE)

Arguments

model

Character string indicating the model name to load.

location

Optional path to the model file (or directory, for `type = "llm"`/`type = "lora"` models). If NULL, looks in the package's data folder.

quiet

Logical (default `FALSE`) to suppress progress messages.

dequantize

Logical (default `TRUE`). For `type = "contextual"` models stored in a quantized format (`int8`, `int4`, `binary`), whether to reconstruct a plug-and-play double matrix. If `FALSE`, returns the raw compact integer matrix with its `scale`/`offset`/ `quantized` attributes intact. Ignored for models that aren't quantized.

Value

The loaded model object (e.g., a matrix or list). For `type = "llm"` models, a list with `$path` (the extracted model directory) and `$config` (parsed `config.json`, or `NULL` if absent) — callers load the model itself with `reticulate`/`transformers` or another R package that reads that directory. For `type = "lora"` models, likewise a list with `$path` and `$config`, but `$config` is the parsed `adapter_config.json` (LoRA hyperparameters: `r`, `lora_alpha`, `target_modules`, `task_type`, `base_model_name_or_path`) — the base model itself is not bundled and must be fetched separately (e.g. from Hugging Face using `base_model_name_or_path`), then the adapter applied on top of it with `peft`/`transformers` via `reticulate`.

Note

The function loads models in the following format priority:

  1. .qs2 - Fastest loading (recommended, ~10x faster than .rda)

  2. .rda - Standard R format with best compression (~1x)

`type = "llm"` and `type = "lora"` models are not read into an R object; the directory path (and parsed `config.json`/`adapter_config.json`) is returned instead.