Coipee
A demo implementation of the Caipi explanatory interactive learning algorithm. Coipee implements a model which one can query to retrieve uncertain instances on which it lacks confidence, alongside an explanation of the model prediction. The user can then correct such explanation, then feed it back to Coipee to trigger an additional training guided by the explanation.
This implementation leverages feature masks as explanation, i.e., masks which can enable or disable input features.
Quickstart
Install through pip and venv:
mkvirtualenv -p python3.12 coipee
pip install coipee
Usage
Coipee revolves around a Coipee object:
barman = Coipee(
model=base_model, # the model to explain, e.g. a neural network
fit_model=fit_model, # the function to train the model, invoked after a correction
pool=data_train, # pool of data to measure the model's uncertainty, also used for query
pool_labels=labels_train # labels of the pool
)
A typical use involves querying the model for a number of uncertain instances
number_of_instances = 10
artifact = barman.query(10)
print(artifact.explanation)
and retrieve a feature mask: features important to the model are marked as True, while others as False.
We can also threshold importance at different levels: the higher the threshold, the higher the required importance
to mark a feature as important:
artifact = barman.query(10, threshold=0.01)
print(artifact.explanation)
Once we have our explanation, we can correct it by marking some important features as not important, and vice versa:
import copy
corrected_artifact = copy.deepcopy(artifact)
corrected_artifact.explanation[:] = False
corrected_artifact.explanation[[0, 1, 2]] = True
Here, we have simply said to the model that actually, only the features 0, 1, 2 are actually important.
We can also directly retrieve differences between artifacts through the diff method:
print(f"Difference: {artifact.diff(corrected_artifact)}")
Now that we have corrected the explanation, we can feed it back to the model:
barman.stack_correction(corrected_artifact) # adds the correction to correction stack of the model
barman.correct_model() # triggers a training phase
Metadata
Release files for coipee 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| coipee-0.0.2.tar.gz | 21.5 kB | Without provenance | Details for coipee-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| coipee-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for coipee-0.0.2-py3-none-any.whl |
Total release size: 41.4 kB
Release files / coipee-0.0.2.tar.gz
| Download URL | coipee-0.0.2.tar.gz |
|---|---|
| Size | 21.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2309eb804fbf49ced741ed3f89c635247ae8b97d1b52dc21263ba6ffae50bab0
|
|
BLAKE2b-256 checksum How to use checksums |
29812ef7a97afcaf134d81b41ba96aac137760ed37ce4dd0ac007b3c7bab68ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Release files / coipee-0.0.2-py3-none-any.whl
| Download URL | coipee-0.0.2-py3-none-any.whl |
|---|---|
| Size | 19.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
35dc4395ba48b518a65e7ab5c99f4b0bc5c3a29602baa7bbba3172f8498fb466
|
|
BLAKE2b-256 checksum How to use checksums |
acac47657331e2ec187a19cdd45657364d7862e7308fc29249904ad1322c36b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Security for coipee 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.