Docs /Templates/ sinapsis-bertopic

BERTopicPredict

sinapsis-bertopicBERTopicBERTopicTopic_ModelingVisualizationNLP

Python template · sinapsis_bertopic.templates.bertopic_predict

Overview

BERTopicPredict template for topic prediction using BERTopic models.

This class provides functionality to load a pre-trained BERTopic model and generate topic predictions for document collections. It handles model loading, prediction generation, and integration with the data container pipeline.

Attributes: AttributesBaseModel: Configuration model for BERTopicPredict template. - model_path (str): Path to the saved BERTopic model file. It can point to a local saved model or a model stored in a huggingface hub repo. - visualize_predictions (bool): Whether to generate visualizations for predictions. Defaults to False. - historical_data_path (str | None): Path to historical data required for visualization. Must be provided if visualize_predictions is True. Defaults to None. - root_dir (str): Root directory for storing prediction outputs. Defaults to SINAPSIS_CACHE_DIR. - prediction_viz_path (str): Relative path for the prediction visualization file. Defaults to "prediction_viz.html". - save_topic_visualization_path (str): Relative path for the topic visualization file. Defaults to "topics_visualization.html".

Capabilities

Capabilities: not set

Installation

Install the published package using pip or uv.

Terminalbash
pip install sinapsis-bertopic==1.0.0
uv pip install sinapsis-bertopic==1.0.0
uv add sinapsis-bertopic==1.0.0

Configuration

Effective fields from the inspector schema, including nested Pydantic model fields.

metadata
sinapsis_core.template_base.base_models.TemplateMetadata | None
Optional
Default: null
root_dir

Root directory for storing prediction outputs. Defaults to SINAPSIS_CACHE_DIR.

str
Optional
Default: "/home/ariel/.cache/sinapsis"
model_pathRequired

Path to the trained BERTopic model file.

str
Required
Default: null
visualize_topics
bool
Optional
Default: true
image_export_params
ToImageParams
Optional
Default: null
scale
int | float | None
Optional
Default: null
width
int | None
Optional
Default: null
format
typing.Literal['png', 'jpg', 'jpeg', 'webp', 'svg', 'pdf']
Optional
Default: "png"
height
int | None
Optional
Default: null
validate_figure
bool
Optional
Default: true
prediction_viz_path
Relative path for the prediction visualization file. Defaults to "prediction_viz.html". Methods: validate_attributes() -> None: Validates that historical_data_path is provided when visualize_predictions is enabled.… Read full field description

Relative path for the prediction visualization file. Defaults to "prediction_viz.html". Methods: validate_attributes() -> None: Validates that historical_data_path is provided when visualize_predictions is enabled. Raises ValueError if validation fails. full_prediction_viz_path (property): Computed field that combines root_dir and prediction_viz_path into an absolute file path.

str
Optional
Default: "prediction_viz.html"
sentence_model_name
str
Optional
Default: "sentence-transformers/all-MiniLM-L6-v2"
historical_data_path

Path to historical data required for visualization. Must be provided if visualize_predictions is True. Defaults to None.

str | None
Optional
Default: null
visualize_predictions

Whether to generate visualizations for predictions. Defaults to False.

bool
Optional
Default: false
visualize_topics_params
VisualizeTopicsParams
Optional
Default: null
title
str
Optional
Default: "<b>Intertopic Distance Map</b>"
topics
list[int] | None
Optional
Default: null
use_ctfidf
bool
Optional
Default: false
figure_width
int
Optional
Default: 650
top_n_topics
int | None
Optional
Default: null
custom_labels
bool
Optional
Default: false
figure_height
int
Optional
Default: 650
export_visualization_to_image
bool
Optional
Default: true
save_topic_visualization_path
str
Optional
Default: "topics_visualization.html"

Configuration example

Generated from documented defaults. Replace any placeholders and complete required nested settings before running.

yaml
templates:
  - template_name: "BERTopicPredict"
    class_name: "BERTopicPredict"
    attributes:
      root_dir: "/home/ariel/.cache/sinapsis"
      model_path: "<required>"
      visualize_topics: true
      image_export_params:
        scale: null
        width: null
        format: "png"
        height: null
        validate_figure: true
      prediction_viz_path: "prediction_viz.html"
      sentence_model_name: "sentence-transformers/all-MiniLM-L6-v2"
      historical_data_path: null
      visualize_predictions: false
      visualize_topics_params:
        title: "<b>Intertopic Distance Map</b>"
        topics: null
        use_ctfidf: false
        figure_width: 650
        top_n_topics: null
        custom_labels: false
        figure_height: 650
      export_visualization_to_image: true
      save_topic_visualization_path: "topics_visualization.html"

Inheritance

Immediate parent: sinapsis_bertopic.templates.bertopic_base.BERTopicBase

Environment variables

Environment definitions belong to their canonical Python modules.

No directly related environment variables listed.