HANNA: Hard-constraint Neural Network for Consistent Activity Coefficient Prediction

Thomas Specht, Mayank Nagda, Sophie Fellenz, Stephan Mandt, Hans Hasse, Fabian JirasekarXiv 2024 · DOI

TL;DR

Researchers have developed HANNA, a novel neural network that strictly enforces thermodynamic laws to predict activity coefficients in mixtures. This "hard-constraint" approach ensures physically consistent predictions, outperforming existing models like UNIFAC in accuracy and applicability, and only requires molecular structures (SMILES) as input.

What Problem Does This Paper Address?

Predicting thermodynamic properties, like activity coefficients, is crucial for chemical engineering applications, from process design to simulating chemical reactions. Traditional neural networks, while powerful function approximators, often struggle with this task because they are "agnostic" to physical laws. This can lead to predictions that violate fundamental thermodynamic principles, undermining their reliability and adoption. Existing physics-informed neural networks (PINNs) often use "soft constraints," which penalize violations but don't strictly enforce them, a limitation that is unacceptable for critical thermodynamic models. Furthermore, experimental data for these properties is often scarce, especially for complex mixtures, making purely data-driven approaches challenging.

Methods

The core innovation is HANNA (HArd-constraint Neural Network for Activity coefficient prediction), a hard-constraint neural network designed to predict activity coefficients. Instead of directly predicting activity coefficients, HANNA first predicts the Gibbs excess energy ($g^E$) of a mixture. This approach leverages the fact that activity coefficients can be derived from $g^E$ through thermodynamic relationships, inherently ensuring consistency.

Key methodological aspects include:

  • Hard-coding Physical Constraints: Thermodynamic consistency criteria, such as the Gibbs-Duhem equation and the fact that activity coefficients of pure components are unity, are embedded directly into the network's architecture. This is achieved through specific architectural choices and loss function formulations.
  • Deep-Set Architecture: Inspired by deep-set models, HANNA's architecture ensures permutation invariance, meaning the order in which components are presented to the network does not affect the final prediction.
  • Component Embeddings: Molecular structures are first converted into numerical "embeddings" using a pre-trained language model (ChemBERTa-2). These embeddings are then refined to incorporate thermodynamic properties.
  • Gibbs Excess Energy Prediction: The network learns to predict the molar Gibbs excess energy ($g^E$) of the mixture, which is then used to derive activity coefficients. This intermediate step is key to enforcing thermodynamic consistency.
  • Auto-differentiation: PyTorch's auto-differentiation capabilities are used to derive the activity coefficients from the predicted $g^E$, ensuring the Gibbs-Duhem consistency.

Datasets

The primary dataset used is the Dortmund Data Bank (DDB), a comprehensive source of experimental thermodynamic data. The authors utilized 317,421 data points for activity coefficients in binary mixtures from the DDB. This dataset was preprocessed to exclude poor-quality data and components for which SMILES strings could not be generated. The data was split system-wise into 80% for training, 10% for validation, and 10% for testing.

Key Insights and Ideas

  • Hard Constraints are Crucial for Thermodynamics: The paper strongly suggests that for thermodynamic modeling, simply penalizing violations (soft constraints) is insufficient. Directly embedding physical laws into the network architecture (hard constraints) is essential for reliable and trustworthy predictions.
  • Predicting $g^E$ is More Robust than Direct Activity Coefficient Prediction: By focusing on the Gibbs excess energy as an intermediate prediction, HANNA inherently enforces thermodynamic consistency, a feat difficult to achieve when predicting activity coefficients directly.
  • Generalizability Beyond Training Data: HANNA demonstrates remarkable ability to generalize to binary mixtures not seen during training, outperforming UNIFAC, which is limited by its parameter availability.
  • SMILES as a Universal Input: The ability to use only SMILES strings as input makes HANNA applicable to virtually any binary mixture, a significant advantage over models requiring specific parameters for each component.

Key Results

  • Superior Prediction Accuracy: HANNA achieved significantly higher prediction accuracies than the state-of-the-art model UNIFAC. The mean absolute error (MAE) for HANNA was reduced to almost a third of UNIFAC's on the "UNIFAC horizon" (data predictable by both models).
  • Broader Applicability: HANNA could predict all 3,502 systems in the test set, whereas UNIFAC could only model 1,658 due to missing parameters.
  • Robust Extrapolation: HANNA showed significantly better performance when extrapolating to systems with unknown components compared to UNIFAC.
  • Thermodynamic Consistency: The model strictly adheres to thermodynamic consistency criteria, including the Gibbs-Duhem equation and pure component activity coefficients being unity, as validated by the zero error in Gibbs-Duhem consistency metrics.

Limitations and Future Work

  • Focus on Binary Mixtures: While the framework is extensible, the current implementation and evaluation focus on binary mixtures. The authors note that multicomponent mixtures can be handled by predicting binary subsystems and then extrapolating using established models.
  • Extension to Other Properties: The current work focuses on activity coefficients. The authors suggest that the framework, based on Gibbs excess energy, can be easily extended to include other thermodynamic properties like excess enthalpies, which would improve the description of temperature dependence.
  • Broader Thermodynamic Models: The approach could be transferred to other thermodynamic modeling frameworks, such as equations of state based on Helmholtz energy.
  • Generalizability to Other Fields: The broader concept of merging physical theory with NNs using hard constraints could be adapted for applications in other scientific fields.

Summary updated

Abstract

We present the first hard-constraint neural network for predicting activity coefficients (HANNA), a thermodynamic mixture property that is the basis for many applications in science and engineering. Unlike traditional neural networks, which ignore physical laws and result in inconsistent predictions, our model is designed to strictly adhere to all thermodynamic consistency criteria. By leveraging deep-set neural networks, HANNA maintains symmetry under the permutation of the components. Furthermore, by hard-coding physical constraints in the network architecture, we ensure consistency with the Gibbs-Duhem equation and in modeling the pure components. The model was trained and evaluated on 317,421 data points for activity coefficients in binary mixtures from the Dortmund Data Bank, achieving significantly higher prediction accuracies than the current state-of-the-art model UNIFAC. Moreover, HANNA only requires the SMILES of the components as input, making it applicable to any binary mixture of interest. HANNA is fully open-source and available for free use.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
DDB · Test set, UNIFAC horizonHANNAMedian system-specific MAE of predicted ln γᵢ0.05-0.04 vs baselineActivity Coefficient Prediction · split: test · horizon=UNIFAC
Source quote
L104: Figure~\ref{Figure1} shows the system-specific MAE of the predicted logarithmic activity coefficients in boxplots; the whisker length is 1.5 times the interquartile range. Outliers are not depicted for improved visibility. The left panel of Figure~\ref{Figure1} shows the results for the UNIFAC horizon, i.e., for the data points that can be predicted with both models. HANNA significantly outperforms UNIFAC, with a mean MAE reduced to almost a third of UNIFAC's, particularly indicating a reduced number of very poorly predicted data points. Furthermore, the significantly reduced median MAE (from 0.09 to 0.05) indicates higher overall accuracy than UNIFAC. Figure~\ref{Figure1} (right) shows that the performance of our model on all test data (``complete horizon''), including those that cannot be predicted with UNIFAC, is similar to the UNIFAC-horizon performance. In Figure~S.4 in the Supporting Information, we show the robustness of HANNA over different random seeds for data splitting.
DDB · binary-mixture test setHANNATest systems for which a prediction is available3,502 systemsActivity Coefficient Prediction · split: test · unit=systems
Source quote
L102: We compare the performance of the models using a system-wise error score. Specifically, we calculate system-specific mean absolute errors (MAE) by averaging the absolute deviations of the predicted logarithmic activity coefficients from the experimental data for each system from the test set. This procedure ensures equal weighting of all systems irrespective of the number of data points and prevents overweighting well-studied systems like water + ethanol. All 3,502 systems in the test set can be predicted with HANNA, but due to missing parameters, only 1,658 can be modeled with UNIFAC. Therefore, both models are compared on the smaller shared horizon, called the ``UNIFAC horizon'' in the following.
Reported baseline / comparator measurements (2)
BenchmarkMethodMetricScoreProtocol / Evidence
DDB · Test set, UNIFAC horizonUNIFAC (modified UNIFAC (Dortmund)) baselineMedian system-specific MAE of predicted ln γᵢ0.09Activity Coefficient Prediction · split: test · model=modified UNIFAC (Dortmund) · horizon=UNIFAC
Source quote
L104: Figure~\ref{Figure1} shows the system-specific MAE of the predicted logarithmic activity coefficients in boxplots; the whisker length is 1.5 times the interquartile range. Outliers are not depicted for improved visibility. The left panel of Figure~\ref{Figure1} shows the results for the UNIFAC horizon, i.e., for the data points that can be predicted with both models. HANNA significantly outperforms UNIFAC, with a mean MAE reduced to almost a third of UNIFAC's, particularly indicating a reduced number of very poorly predicted data points. Furthermore, the significantly reduced median MAE (from 0.09 to 0.05) indicates higher overall accuracy than UNIFAC. Figure~\ref{Figure1} (right) shows that the performance of our model on all test data (``complete horizon''), including those that cannot be predicted with UNIFAC, is similar to the UNIFAC-horizon performance. In Figure~S.4 in the Supporting Information, we show the robustness of HANNA over different random seeds for data splitting.
DDB · binary-mixture test setUNIFAC (modified UNIFAC (Dortmund)) baselineTest systems that can be modeled1,658 systemsActivity Coefficient Prediction · split: test · unit=systems · model=modified UNIFAC (Dortmund) · horizon=UNIFAC
Source quote
L102: We compare the performance of the models using a system-wise error score. Specifically, we calculate system-specific mean absolute errors (MAE) by averaging the absolute deviations of the predicted logarithmic activity coefficients from the experimental data for each system from the test set. This procedure ensures equal weighting of all systems irrespective of the number of data points and prevents overweighting well-studied systems like water + ethanol. All 3,502 systems in the test set can be predicted with HANNA, but due to missing parameters, only 1,658 can be modeled with UNIFAC. Therefore, both models are compared on the smaller shared horizon, called the ``UNIFAC horizon'' in the following.
BibTeX
@misc{specht2024hanna,
  author = {Thomas Specht and Mayank Nagda and Sophie Fellenz and Stephan Mandt and Hans Hasse and Fabian Jirasek},
  title = {{HANNA: Hard-constraint Neural Network for Consistent Activity Coefficient Prediction}},
  year = {2024},
  eprint = {2407.18011},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.18011},
}
Figure