This function generates descriptive labels for each topic based on their top terms using AI providers (OpenAI, Gemini, or Ollama).
Usage
generate_topic_labels(
top_topic_terms,
provider = "auto",
model = NULL,
system = NULL,
user = NULL,
temperature = 0.5,
api_key = NULL,
openai_api_key = NULL,
verbose = TRUE
)Arguments
- top_topic_terms
A data frame containing the top terms for each topic.
- provider
AI provider to use: "auto" (default), "openai", "gemini", or "ollama". "auto" will try Ollama first, then check for OpenAI/Gemini keys.
- model
A character string specifying which model to use. If NULL, uses provider defaults: "gpt-4.1-mini" (OpenAI), "gemini-2.5-flash" (Gemini), or recommended Ollama model.
- system
A character string containing the system prompt for the API. If NULL, the function uses the default system prompt.
- user
A character string containing the user prompt for the API. If NULL, the function uses the default user prompt.
- temperature
A numeric value controlling the randomness of the output (default: 0.5).
- api_key
API key for OpenAI or Gemini. If NULL, uses environment variable. Not required for Ollama.
- openai_api_key
Deprecated. Use
api_keyinstead. Kept for backward compatibility.- verbose
Logical, if TRUE, prints progress messages.
See also
Other topic-modeling:
analyze_semantic_evolution(),
assess_embedding_stability(),
assess_hybrid_stability(),
auto_tune_embedding_topics(),
calculate_assignment_consistency(),
calculate_eval_metrics_internal(),
calculate_keyword_stability(),
calculate_semantic_drift(),
calculate_topic_probability(),
calculate_topic_stability(),
find_optimal_k(),
find_topic_matches(),
fit_embedding_model(),
fit_hybrid_model(),
fit_temporal_model(),
get_topic_prevalence(),
get_topic_terms(),
get_topic_texts(),
identify_topic_trends(),
plot_model_comparison(),
plot_quality_metrics(),
run_contrastive_topics_internal(),
run_neural_topics_internal(),
run_temporal_topics_internal(),
validate_semantic_coherence()
Examples
if (FALSE) { # \dontrun{
top_topic_terms <- get_topic_terms(stm_model, top_term_n = 10)
# Auto-detect provider (tries Ollama -> OpenAI -> Gemini)
labels <- generate_topic_labels(top_topic_terms)
# Use specific provider
labels_ollama <- generate_topic_labels(top_topic_terms, provider = "ollama")
labels_openai <- generate_topic_labels(top_topic_terms, provider = "openai")
labels_gemini <- generate_topic_labels(top_topic_terms, provider = "gemini")
} # }
