Home

Awesome

<img src="https://ar.pegg.io/img/ecco-logo-w800.png" width="400" style="background-color: white" /> <br /> <br /> <!--- BADGES: START --->

GitHub - License PyPI - Latest Package Version PyPI - Supported Python Versions Conda - Platform Conda (channel only) Docs - GitHub.io

<!--- BADGES: END --->

Ecco is a python library for exploring and explaining Natural Language Processing models using interactive visualizations.

Ecco provides multiple interfaces to aid the explanation and intuition of Transformer-based language models. Read: Interfaces for Explaining Transformer Language Models.

Ecco runs inside Jupyter notebooks. It is built on top of pytorch and transformers.

Ecco is not concerned with training or fine-tuning models. Only exploring and understanding existing pre-trained models. The library is currently an alpha release of a research project. You're welcome to contribute to make it better!

Documentation: ecco.readthedocs.io

Features

Installation

You can install ecco either with pip or with conda.

with pip

pip install ecco

with conda

conda install -c conda-forge ecco

Examples:

You can run all these examples from this [notebook] | [colab].

What is the sentiment of this film review?

<img src="https://ar.pegg.io/img/ecco/ecco-sentiment-1.png" width="500px" />

Use a large language model (T5 in this case) to detect text sentiment. In addition to the sentiment, see the tokens the model broke the text into (which can help debug some edge cases).

Which words in this review lead the model to classify its sentiment as "negative"?

<img src="https://ar.pegg.io/img/ecco/ecco-attrib-ig-1.png" width="500px" />

Feature attribution using Integrated Gradients helps you explore model decisions. In this case, switching "weakness" to "inclination" allows the model to correctly switch the prediction to positive.

Explore the world knowledge of GPT models by posing fill-in-the blank questions.

<img src="https://ar.pegg.io/img/ecco/gpt2-heathrow-1.png" width="500px" alt="Asking GPT2 where heathrow airport is" />

Does GPT2 know where Heathrow Airport is? Yes. It does.

What other cities/words did the model consider in addition to London?

<img src="https://ar.pegg.io/img/ecco/gpt-candidate-logits.png" width="500px" alt="The model also considered Birmingham and Manchester"/>

Visualize the candidate output tokens and their probability scores.

Which input words lead it to think of London?

<img src="https://ar.pegg.io/img/ecco/heathrow-attribution.png" width="400px" alt="Asking GPT2 where heathrow airport is"/>

At which layers did the model gather confidence that London is the right answer?

<img src="https://ar.pegg.io/img/ecco/token-evolution.png" width="200px" alt="The order of the token in each layer, layer 11 makes it number 1"/>

The model chose London by making the highest probability token (ranking it #1) after the last layer in the model. How much did each layer contribute to increasing the ranking of London? This is a logit lens visualizations that helps explore the activity of different model layers.

What are the patterns in BERT neuron activation when it processes a piece of text?

<img src="https://ar.pegg.io/img/ecco/neuron-bert.png" width="500px" alt="Colored line graphs on the left, a piece of text on the right. The line graphs indicate the activation of BERT neuron groups in response to the text"/>

A group of neurons in BERT tend to fire in response to commas and other punctuation. Other groups of neurons tend to fire in response to pronouns. Use this visualization to factorize neuron activity in individual FFNN layers or in the entire model.

Read the paper:

Ecco: An Open Source Library for the Explainability of Transformer Language Models Association for Computational Linguistics (ACL) System Demonstrations, 2021

Tutorials

How-to Guides

API Reference

The API reference and the architecture page explain Ecco's components and how they work together.

Gallery & Examples

<div class="container gallery" markdown="1"> <p><strong>Predicted Tokens:</strong> View the model's prediction for the next token (with probability scores). See how the predictions evolved through the model's layers. [<a href="https://github.com/jalammar/ecco/blob/main/notebooks/Ecco_Output_Token_Scores.ipynb">Notebook</a>] [<a href="https://colab.research.google.com/github/jalammar/ecco/blob/main/notebooks/Ecco_Output_Token_Scores.ipynb">Colab</a>]</p> <img src="docs/img/layer_predictions_ex_london.png" width="400" /> <hr /> <p><strong>Rankings across layers:</strong> After the model picks an output token, Look back at how each layer ranked that token. [<a href="https://github.com/jalammar/ecco/blob/main/notebooks/Ecco_Evolution_of_Selected_Token.ipynb">Notebook</a>] [<a href="https://colab.research.google.com/github/jalammar/ecco/blob/main/notebooks/Ecco_Evolution_of_Selected_Token.ipynb">Colab</a>]</p> <img src="docs/img/rankings_ex_eu_1_widethumb.png" width="400"/> <hr /> <p><strong>Layer Predictions:</strong>Compare the rankings of multiple tokens as candidates for a certain position in the sequence. [<a href="https://github.com/jalammar/ecco/blob/main/notebooks/Ecco_Comparing_Token_Rankings.ipynb">Notebook</a>] [<a href="https://colab.research.google.com/github/jalammar/ecco/blob/main/notebooks/Ecco_Comparing_Token_Rankings.ipynb">Colab</a>]</p> <img src="docs/img/rankings_watch_ex_is_are_widethumb.png" width="400" /> <hr /> <p><strong>Primary Attributions:</strong> How much did each input token contribute to producing the output token? [<a href="https://github.com/jalammar/ecco/blob/main/notebooks/Ecco_Primary_Attributions.ipynb">Notebook</a>] [<a href="https://colab.research.google.com/github/jalammar/ecco/blob/main/notebooks/Ecco_Primary_Attributions.ipynb">Colab</a>] </p> <img src="docs/img/saliency_ex_1_thumbwide.png" width="400"/> <hr /> <p><strong>Detailed Primary Attributions:</strong> See more precise input attributions values using the detailed view. [<a href="https://github.com/jalammar/ecco/blob/main/notebooks/Ecco_Primary_Attributions.ipynb">Notebook</a>] [<a href="https://colab.research.google.com/github/jalammar/ecco/blob/main/notebooks/Ecco_Primary_Attributions.ipynb">Colab</a>] </p> <img src="docs/img/saliency_ex_2_thumbwide.png" width="400"/> <hr /> <p><strong>Neuron Activation Analysis:</strong> Examine underlying patterns in neuron activations using non-negative matrix factorization. [<a href="https://github.com/jalammar/ecco/blob/main/notebooks/Ecco_Neuron_Factors.ipynb">Notebook</a>] [<a href="https://colab.research.google.com/github/jalammar/ecco/blob/main/notebooks/Ecco_Neuron_Factors.ipynb">Colab</a>]</p> <img src="docs/img/nmf_ex_1_widethumb.png" width="400"/> </div>

Getting Help

Having trouble?

Bibtex for citations:

@inproceedings{alammar-2021-ecco,
    title = "Ecco: An Open Source Library for the Explainability of Transformer Language Models",
    author = "Alammar, J",
    booktitle = "Proceedings of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing: System Demonstrations",
    year = "2021",
    publisher = "Association for Computational Linguistics",
}