Textual Data in Explainable Predictive Process Monitoring

Cover Image

Setting: This post is about "On the Potential of Textual Data for Explainable Predictive Process Monitoring", the paper that concluded my master's thesis at the BPT chair at Hasso Plattner Institute. I wrote it together with Henrik Leopold and presented it on 24 October 2022 at the ML4PM workshop of the International Conference on Process Mining in Bozen-Bolzano. It is published in the conference proceedings of ICPM 2022. The code for all experiments is on GitHub.

Predictions that need a reason: Predictive process monitoring uses machine learning to forecast how a running case will end: whether a loan application gets accepted, how much time is left, which activity comes next. When such a prediction feeds a decision about a patient or a loan, accuracy is not enough. Someone has to be able to see why the model said what it said, and that is what explainable predictive process monitoring is for. The existing techniques build on two well-known methods: SHAP (package, paper by Lundberg and Lee, NeurIPS 2017) and LIME (package, "Why Should I Trust You?" by Ribeiro et al., KDD 2016). Both attribute a prediction to the input features that pushed it one way or the other.

All of these techniques work on numerical and categorical attributes. None of them uses text.

Why text: I find text one of the more interesting directions here, and the reason has to do with where the data comes from. Almost every approach works on event logs alone, and event logs were never built to explain anything. They are extracted from the transactional data of operational systems such as ERP or CRM systems, which record each transaction to run the business, not to explain it. What ends up in the log is which activity happened when, by whom and with which attribute values. That makes them a record of effects. You can read off that an application was cancelled after the second offer, but the reason behind it rarely appears anywhere in the log. Free text written by the people involved, such as the description of what a loan is for or a note in the file, is one of the few places where reasons show up at all.

Take a loan application. Applicants describe their financial situation, what they want the money for and how they plan to pay it back. Two cases can be identical in every structured column and still differ in that field: one applicant is paying for a wedding, the other is buying a car. For the bank this matters, because a car can be resold if the loan defaults.

An event log with case ID, activity, timestamp, loan amount, credit score and a free-text loan goal description, filled only on the first event of each case
An example event log with textual context. The loan goal on the right is the column existing explanation techniques ignore.

Text has been used in process prediction before. Teinemaa et al. (2016) appended bag-of-n-grams, TF-IDF and LDA features to the structured feature vector, Pegoraro et al. (2021) fed TF-IDF, Doc2Vec or LDA representations into an LSTM, and Cabrera et al. (2022) used contextualized word embeddings to predict the next activity and its timestamp. All three use text to predict better. None of them looks at what text does to the explanation, and that is the question we asked.

Before building anything, my thesis mapped out where text can enter explainable predictive process monitoring: a framework that runs from the data through model building to the explanation. The orange boxes mark what the thesis covers, from textual context data on case level to the combination strategies and local and global explanations with SHAP.

The explainability framework for predictive process monitoring from the thesis, in three phases: data, model building and explainability. Steps run from data preprocessing through task selection, analysis point, model search, combination strategies and explainability analysis to explainability communication. Boxes covered by the thesis are outlined in orange.
The explainability framework from my thesis. Orange marks what the thesis covers.

Two strategies: Text and structured data have to fit together twice: once for training and inference, and once for the explainability analysis. We proposed two ways to do that.

The first keeps two separate models, one for the text and one for everything else. At inference, we look at both class probabilities and, per case, take the prediction of whichever model is further away from 0.5, so the more decisive model wins. Each model gets its own explanation, which leaves you with two explanations side by side.

Strategy 1: two models, one for text and one for non-text data, combined at inference by probability or label

The second is a two-stage model. Stage one is a text model. We run SHAP on it, keep the n most important words, remove stopwords and represent what is left with TF-IDF. Those features go into the second stage together with the structured data. The explainability analysis then runs on the second stage only and sees both sources in a single explanation.

Strategy 2: a text model whose n most important features are passed into a combined second-stage model

For the structured side we used XGBoost, which had the best average performance across datasets in Teinemaa et al.'s outcome prediction benchmark. For the text we fine-tuned BERT base uncased. SHAP explains both, with the PartitionExplainer for BERT and the TreeExplainer for XGBoost.

Building a dataset: There is no public event log with rich textual data, so we made one. The base is the BPI Challenge 2017 log, a credit application process at a Dutch financial institution in which 12,792 of 31,413 loans were granted. We added loan goal descriptions from the LendingClub dataset as an attribute of the first event of each case, the filing of the application.

BPMN model of the BPIC17 loan application process in three lanes for customer, bank system and bank employee, from creating and submitting the application through offers and validation to three endings: accepted, denied by the bank, or cancelled by the customer
The BPIC17 loan application process, simplified. Accepted is one outcome; denied by the bank and cancelled by the customer together form the other.

LendingClub only contains accepted applications, so its texts could not simply be matched to outcomes. We redistributed them instead. Latent Dirichlet Allocation gave us the dominant topics, and we assigned groups of topics to the two outcomes in a controlled way: applicants writing about medical issues, for example, became less likely to get an offer. That plants a structure in the data that a model can find and that we can later look for in the explanation.

Topic analysis of the LendingClub loan descriptions with LDA: an intertopic distance map showing six topics as circles sized by their share of tokens, next to a bar chart of the 30 most relevant terms for topic 3, such as house, home, mortgage, repair and improvement
LDA on the LendingClub loan descriptions, from my thesis. Left, the six topics and how far apart they are; right, the most relevant terms for topic 3, which is about the home.

An impurity parameter sets how much of the text is assigned at random instead. At 0.0 the topics separate accepted and rejected cases cleanly; at 1.0 the text carries no information about the outcome. We generated 11 variants from 0.0 to 1.0 in steps of 0.1 and ran every experiment ten times. The plots below use purity, which is simply 1 minus impurity.

The augmentation strategy: accepted and rejected cases receive texts from two topic groups, mixed with random texts according to the impurity parameter

The preprocessing is unspectacular but determines what the explanation can talk about. The labels come from the end activities. XGBoost needs one static vector per case, so every activity becomes a feature that records whether it occurred, categorical attributes are one-hot encoded and numerical ones standardized. BERT needs little beyond its own tokenizer. The full pipeline is in the repository.

Prediction quality: We compared both strategies against XGBoost on the structured data alone and against a trivial baseline that predicts the majority class for every case. Once purity goes above 0.1, both strategies beat the structured baseline on F1 and ROC AUC. Even when most of the text is randomly assigned, adding it helps. At low purity, neither BERT on the text nor XGBoost on the structured data gets there alone. At high purity, BERT on its own catches up, because by then the text alone separates the outcomes. The two strategies end up close to each other.

Two plots: F1 score and parsimony across dataset purity from 0.0 to 1.0, for baseline, strategy 1, strategy 2 and BERT

What happens to the explanations: To measure explainability we used the metrics Stevens et al. proposed for outcome-oriented process monitoring: parsimony for interpretability and monotonicity for faithfulness.

Parsimony counts the features with a non-zero weight in the explanation; lower is easier to read. Here strategy 1 does badly. Summed over both models, its explanations use around 2,000 to 3,000 features against roughly 80 for the baseline, and the count rises with purity. Strategy 2 stays below 250, because n caps how many text features get through. By this metric, text makes explanations harder to read. I do not take that at face value. As Danilevsky et al. argue, text-based features are inherently more interpretable to humans, and a word is easier to understand than a one-hot-encoded category. Counting both as equally costly overstates the problem.

Monotonicity is the Spearman correlation between the feature importance of the model itself and the importance SHAP assigns. For XGBoost we took the number of times a feature is used to split the data across all trees. Strategy 2 and the baseline came out almost the same, with a small gap at low purity that disappears as purity rises. Strategy 1 could not be measured, because BERT has no built-in feature importance to compare against.

We also measured a rediscovery rate: how many of the topic words we planted come back among the most important features. A word counts as rediscovered if its cosine similarity to a planted word, using word2vec vectors pre-trained on Google News, is above 0.3 and its mean absolute SHAP value is above 0.005. Both strategies score high, so the models pick up the structure we put in. Strategy 1 finds more of it, since strategy 2 only ever sees n words.

Computation time: Text is expensive. Both strategies need considerably more time than the baseline for training and for explanation, and strategy 2 takes only marginally longer than strategy 1. With many features and complex models, the SHAP computation far outweighs the training. We did not derive a general ratio between the two, because it depends heavily on the model and the dataset.

A prototype: To see what this would look like for a user, we built a prototype that separates local explanations for a single case from a global view across all cases. Red pushes the prediction towards acceptance, blue towards rejection, and the text view highlights the words that moved it.

The prototype: SHAP waterfall plot for the non-textual model next to a force plot and a text view for the textual model, with words highlighted red and blue

Conclusion: Adding text costs computation time and, measured by parsimony, makes explanations larger. It also improves predictions when the text is mostly noise, and the features it adds are words a person can read. Of the two strategies, strategy 1 rediscovers more of the planted structure, strategy 2 predicts about as well with a far smaller explanation, and in one piece instead of two. For explainable predictive process monitoring, combining text with structured data is worth it.

Where I would go next: The paper names two directions for future work. The first: an explainability analysis tells you which features the model relies on, but not whether a feature is merely correlated with the outcome or actually causes it. So the explanation should be followed by a causality analysis. The approach I would take is causal structure learning, which I wrote about in an earlier post. A constraint-based method such as the PC algorithm learns a causal graph from observational data, and with that graph you can check which of the explanation's top features sit causally upstream of the outcome.

The second: relate what an explanation says to real interventions, and see whether acting on it actually changes how a case ends.

Bozen-Bolzano: Presenting the paper at the ML4PM workshop was a lot of fun. After ICPM the year before and BPM earlier in 2022, it was another chance to meet friends and fellow process mining researchers again, and Bozen-Bolzano made it easy to enjoy: a picturesque town and a week of beautiful autumn weather.

Collage from ICPM 2022: Christian Warmuth presenting next to the title slide of the paper at the ML4PM workshop, his ICPM 2022 conference badge on a blue unibz lanyard, and a view over Bozen-Bolzano from the vineyard terraces with the mountains behind

Our team had a second paper there as well. Diana Sola presented "SAP Signavio Academic Models: A Large Process Model Dataset", which we wrote together with Bernhard Schäfer, Peyman Badakhshan, Jana-Rebecca Rehse and Timotheus Kampik. It describes an academic dataset of more than one million openly available process models, and the dataset is on GitHub.