pm4py.algo.transformation.trace_encodings.variants.cases_transformers module#
PM4Py – A Process Mining Library for Python Copyright (C) 2026 Process Intelligence Solutions GmbH
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see this software project’s root or visit <https://www.gnu.org/licenses/>.
Website: https://processintelligence.solutions Contact: info@processintelligence.solutions
- class pm4py.algo.transformation.trace_encodings.variants.cases_transformers.Parameters(*values)[source]#
Bases:
Enum- CASE_ID_KEY = 'pm4py:param:case_id_key'#
- EMBEDDING_MODEL = 'embedding_model'#
- ATTRIBUTE_KEY = 'pm4py:param:attribute_key'#
- EVENT_ATTRIBUTES = 'event_attributes'#
- TRACE_ATTRIBUTES = 'trace_attributes'#
- pm4py.algo.transformation.trace_encodings.variants.cases_transformers.apply(log: DataFrame, parameters: Dict[Any, Any] | None = None) Tuple[List[str], List[List[float]]][source]#
Computes one text embedding per case.
From an event-log point of view, each trace is converted to a sentence and then embedded by a sentence-transformers model. By default, the sentence is the sequence of activity names. Additional event attributes and trace attributes can be included to represent a richer perspective.
- Example with activity-only encoding:
case 1: A, B, C -> “A B C” case 2: A, C -> “A C”
- Example with event_attributes=[“concept:name”, “org:resource”]:
event A by R1 becomes “concept:name=A|org:resource=R1”
The output is a list of case identifiers and a list of dense embedding vectors, one vector per case.
- Parameters:
log – Pandas dataframe
parameters – Parameters of the algorithm, including: - Parameters.CASE_ID_KEY => the case identifier column - Parameters.EMBEDDING_MODEL => the embedding to be used (default: all-MiniLM-L6-v2) - Parameters.ATTRIBUTE_KEY => the attribute to be used for the concatenation - Parameters.EVENT_ATTRIBUTES => event attributes to include in the case sentence. If omitted, ATTRIBUTE_KEY is used. - Parameters.TRACE_ATTRIBUTES => trace attributes to include as case context tokens.
- Returns:
cases_identifiers – The list of all the case identifiers
embeddings_list – The list of embeddings for the considered cases
- pm4py.algo.transformation.trace_encodings.variants.cases_transformers.keep_top_k_per_similarity(log: DataFrame, target_sentence: str, k: int, cases_identifiers: List[str] | None = None, embeddings_list: List[List[float]] | None = None, parameters: Dict[Any, Any] | None = None) DataFrame[source]#
Keeps the top K cases by embedding similarity with the given sentence.
For example, after encoding cases as activity sentences, the query “rejected cases” is embedded with the same model and compared with each case embedding using cosine similarity.
- Parameters:
log – Pandas dataframe
target_sentence – Target sentence
k – Number of similar cases to retain
cases_identifiers – (Optional) the list of cases identifiers in the log, as returned by the ‘apply’ method
embeddings_list – (Optional) the list of embeddings for such cases, as returned by the ‘apply’ method
parameters – Other parameters of the method
- Returns:
Event log filtered on the top K cases according to the similarity metric.
- Return type:
filtered_log