microsoft/augmented-interpretable-models

Interpretable and efficient predictors using pre-trained language models. Scikit-learn compatible.

Jupyter Notebook

42

198 commits

updated Nov 10, 2025

See the code

README

Augmenting Interpretable Models with LLMs during Training

This repo contains code to reproduce the experiments in the Aug-imodels paper (Nature Communications, 2023). For a simple scikit-learn interface to use Aug-imodels, use the imodelsX library. Below is a quickstart example.

Installation: pip install imodelsx

from imodelsx import AugLinearClassifier, AugTreeClassifier, AugLinearRegressor, AugTreeRegressor
import datasets
import numpy as np

# set up data
dset = datasets.load_dataset('rotten_tomatoes')['train']
dset = dset.select(np.random.choice(len(dset), size=300, replace=False))
dset_val = datasets.load_dataset('rotten_tomatoes')['validation']
dset_val = dset_val.select(np.random.choice(len(dset_val), size=300, replace=False))

# fit model
m = AugLinearClassifier(
    checkpoint='textattack/distilbert-base-uncased-rotten-tomatoes',
    ngrams=2, # use bigrams
)
m.fit(dset['text'], dset['label'])

# predict
preds = m.predict(dset_val['text'])
print('acc_val', np.mean(preds == dset_val['label']))

# interpret
print('Total ngram coefficients: ', len(m.coefs_dict_))
print('Most positive ngrams')
for k, v in sorted(m.coefs_dict_.items(), key=lambda item: item[1], reverse=True)[:8]:
    print('\t', k, round(v, 2))
print('Most negative ngrams')
for k, v in sorted(m.coefs_dict_.items(), key=lambda item: item[1])[:8]:
    print('\t', k, round(v, 2))

Reference:

@article{singh2023augmenting,
  title={Augmenting interpretable models with large language models during training},
  author={Singh, Chandan and Askari, Armin and Caruana, Rich and Gao, Jianfeng},
  journal={Nature Communications},
  volume={14},
  number={1},
  pages={7913},
  year={2023},
  publisher={Nature Publishing Group UK London}
}
ai
artificial-intelligence
deep-learning
distillation
embedding
explainability
huggingface
interpretability
language-model
large-language-models
linear
linear-models
logistic-regression
machine-learning
ml
neural-network
scikit-learn
sentiment-classification
transformer
transparent

microsoft/augmented-interpretable-models

Interpretable and efficient predictors using pre-trained language models. Scikit-learn compatible.

Jupyter Notebook

42

198 commits

updated Nov 10, 2025

See the code

README

Augmenting Interpretable Models with LLMs during Training

This repo contains code to reproduce the experiments in the Aug-imodels paper (Nature Communications, 2023). For a simple scikit-learn interface to use Aug-imodels, use the imodelsX library. Below is a quickstart example.

Installation: pip install imodelsx

from imodelsx import AugLinearClassifier, AugTreeClassifier, AugLinearRegressor, AugTreeRegressor
import datasets
import numpy as np

# set up data
dset = datasets.load_dataset('rotten_tomatoes')['train']
dset = dset.select(np.random.choice(len(dset), size=300, replace=False))
dset_val = datasets.load_dataset('rotten_tomatoes')['validation']
dset_val = dset_val.select(np.random.choice(len(dset_val), size=300, replace=False))

# fit model
m = AugLinearClassifier(
    checkpoint='textattack/distilbert-base-uncased-rotten-tomatoes',
    ngrams=2, # use bigrams
)
m.fit(dset['text'], dset['label'])

# predict
preds = m.predict(dset_val['text'])
print('acc_val', np.mean(preds == dset_val['label']))

# interpret
print('Total ngram coefficients: ', len(m.coefs_dict_))
print('Most positive ngrams')
for k, v in sorted(m.coefs_dict_.items(), key=lambda item: item[1], reverse=True)[:8]:
    print('\t', k, round(v, 2))
print('Most negative ngrams')
for k, v in sorted(m.coefs_dict_.items(), key=lambda item: item[1])[:8]:
    print('\t', k, round(v, 2))

Reference:

@article{singh2023augmenting,
  title={Augmenting interpretable models with large language models during training},
  author={Singh, Chandan and Askari, Armin and Caruana, Rich and Gao, Jianfeng},
  journal={Nature Communications},
  volume={14},
  number={1},
  pages={7913},
  year={2023},
  publisher={Nature Publishing Group UK London}
}
ai
artificial-intelligence
deep-learning
distillation
embedding
explainability
huggingface
interpretability
language-model
large-language-models
linear
linear-models
logistic-regression
machine-learning
ml
neural-network
scikit-learn
sentiment-classification
transformer
transparent

Languages

Jupyter Notebook

94.1%

Python

4.7%

HTML

1.1%