Skip to content

Reference

The Comet MPM class is used to upload a model's input and output features to MPM

CometMPM.init

__init__(api_key: Optional[str] = None,
    workspace_name: Optional[str] = None,
    model_name: Optional[str] = None,
    model_version: Optional[str] = None,
    disabled: Optional[bool] = None, asyncio: bool = False,
    max_batch_size: Optional[int] = None,
    max_batch_time: Optional[int] = None)

Creates the Comet MPM Event logger object.

Args:

  • api_key: The Comet API Key
  • workspace_name: The Comet Workspace Name of the model
  • model_name: The Comet Model Name of the model
  • model_version: The Comet Model Version of the model
  • disabled: If set to True, CometMPM will not send anything to the backend.
  • asyncio: Set to True if you are using an Asyncio-based framework like FastAPI.
  • max_batch_size: Maximum number of MPM events sent in a batch, can also be configured using the environment variable MPM_MAX_BATCH_SIZE.
  • max_batch_time: Maximum time before a batch of events is submitted to MPM, can also be configured using the environment variable MPM_MAX_BATCH_SIZE.

CometMPM.connect

connect() -> None

When using CometMPM in asyncio mode, this coroutine needs to be awaited at the server start.

CometMPM.join

join(timeout: Optional[int] = None) -> Optional[Awaitable[None]]

When using CometMPM in asyncio mode, this coroutine needs to be awaited at the server stop.

CometMPM.log_dataframe

log_dataframe(dataframe, prediction_id_column: str,
    feature_columns: Optional[List[str]] = None,
    output_value_column: Optional[str] = None,
    output_probability_column: Optional[str] = None,
    output_features_columns: Optional[List[str]] = None,
    timestamp_column: Optional[str] = None) -> LogEventsResult

This function logs each row of a Pandas DataFrame as an MPM event. The events are structured as described in the log_event method, so please refer to it for full context.

Args:

  • dataframe: The Pandas DataFrame to be logged.
  • prediction_id_column: This column should contain the prediction_id values for the events.
  • feature_columns: Deprecated. If provided, these columns will be used as the input_features for the events.
  • output_value_column: Deprecated. If provided, this column will be used as the output_value for the events.
  • output_features_columns: If provided, these columns will be used as the output_features for the events.
  • output_probability_column: If provided, this column will be used as the output_probability for the events.
  • timestamp_column: If provided, this column will be used as the timestamp (seconds since epoch start in UTC timezone) for the events.

CometMPM.log_event

log_event(prediction_id: str, input_features: Optional[Dict[str,
    Any]] = None, output_value: Optional[Any] = None,
    output_probability: Optional[Any] = None,
    output_features: Optional[Dict[str, Any]] = None,
    timestamp: Optional[float] = None) -> Optional[Awaitable[None]]

Asynchronously log a single event to MPM. Events are identified by the mandatory prediction_id parameter. You can send multiple events with the same prediction_id, and the events will be automatically merged on the backend side.

Args:

  • prediction_id: The unique prediction ID. It can be provided by the framework, you, or a random unique value such as str(uuid4()).
  • input_features: If provided, it must be a flat dictionary where the keys are the feature names, and the values are native Python scalars, such as integers, floats, booleans, or strings. For example: {"age": 42, "income": 42894.89}.
  • output_features: A dictionary of output features. Must follow a similar format to input_features.
  • output_value: Deprecated. The prediction as a native Python scalar, such as an integer, float, boolean, or string.
  • output_probability: Deprecated. If provided, it must be a float between 0 and 1, indicating the model's confidence in the prediction.
  • timestamp: An optional timestamp to associate with the event (seconds since epoch in UTC timezone). If not provided, the current time will be used.

CometMPM.log_label

log_label(prediction_id: str, label: Any) -> Optional[Awaitable[None]]

Send an MPM event containing the ground truth value for a prediction whose input and output features are already stored in Comet.

Args:

  • prediction_id: The unique prediction ID
  • label: The ground truth value for the prediction
Jun. 14, 2024