Compare commits

...

4 Commits

Author SHA1 Message Date
James Ravenscroft 66e526258e save WIP on rationale post 2021-02-21 14:08:38 +00:00
James Ravenscroft fbf5e10897 Update blog post
continuous-integration/drone/push Build is passing Details
2021-01-03 14:53:09 +00:00
James Ravenscroft c45c30dc5c working on rationale post
continuous-integration/drone/push Build is passing Details
2021-01-02 18:22:23 +00:00
James Ravenscroft 99b8dddf77 Limit deployments to main
continuous-integration/drone/push Build is passing Details
2021-01-02 17:27:29 +00:00
9 changed files with 100 additions and 0 deletions

View File

@ -4,6 +4,9 @@ name: update_website
steps: steps:
- name: hugo_build - name: hugo_build
image: alombarte/hugo image: alombarte/hugo
when:
branch:
- main
commands: commands:
- git submodule init - git submodule init
- git submodule update - git submodule update
@ -11,6 +14,9 @@ steps:
- hugo - hugo
- name: hugo_publish - name: hugo_publish
image: alpine:3.12.3 image: alpine:3.12.3
when:
branch:
- main
environment: environment:
FTP_USERNAME: FTP_USERNAME:
from_secret: FTP_USERNAME from_secret: FTP_USERNAME

View File

@ -0,0 +1 @@
<mxfile host="Electron" modified="2021-01-29T10:47:22.688Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/14.1.8 Chrome/87.0.4280.88 Electron/11.1.1 Safari/537.36" etag="qz4HoTyBwUZzFsaK1xTF" version="14.1.8" type="device"><diagram id="F5Ue9vwdzeswKv2T4yi_" name="Page-1">7VhbU+IwFP41nXEfYErSFnjkIrrriO7izOLTTm3TNmNpummA4q/fpE3pFUFFZWdXHcn5kpwk53znMihwtIgvqBl618RGvgJUO1bgWAGgowGgiD/V3qRIHxop4FJsy0U5MMNPSIKqRJfYRlFpISPEZzgsgxYJAmSxEmZSStblZQ7xy6eGpotqwMwy/Tr6E9vMS9Ee6Ob4JcKul53cMfrpzMLMFsuXRJ5pk3UBgucKHFFCWDpaxCPkC+Nldkn3TXbMbi9GUcAO2dCa9hcr9fsUrie9qyCaxiG5akktK9NfygcrwPC5vqHXERb0sRskuPF7KS46tPhpiOYyH7nic57te6AZlCH8SkJZGQwz4GskXOohisR5wYZ5OHD58AGx5CA+Zwb8Y4ot4pti8Ui4DKiDKb+W+o14YvaOmivOClOBEy5NTEusuHEc8f4oUSz+WQyTIDGa9Yjsdrv97KXDHEv8xzYZKRiKExOxhc+BDh9GXKW4NxzruXRHQg60uF/gcO1hhmahuBgcr3mscIysEHX8hBMetm3ELT2kZBnYSLhM7HKw74+IT2hyLnR08SsOYJQ8osKMkfyIHSRgBTz92b6hyJbM9Yjy5xQgyZ4LRBaI0Q1fEpdDUkYy0KS8zuMCGBLzCjHRk5gpQ9Hdas7ZygeSsC8gL2ggb8VTKLAHIgtwyeLsibBV9ttOsyC7lBfqRim8Wm94dIZR5JsMr8rZpMkS8oRbgvlNtjYH3YrRu/22XlYSkSW1kNxXjP+KKgj2qmImdRGrqUqcs336Qf5yujffA3R/PkW/SMv4cXl9P5s0JBsUWGdPX2peawqWgtPMKExTvYNjESoJ6WdyeyeT01ICtOOQ36har4H9vXcif6Mxj0B+FGM2L4zvRdZp61IaxzIJJcJGCjtNmdJwv/dPJLAMrexPXa046tCw6sIKMaoef+eggjsruI1X1aomAqPEkayMi4lWlITMgC8AWhjXa/ymUBxTTbWa2XDm7mtY2zqVnwRVdTQSvqgefksinPj7+Ts0VvLSFfbW8qzpka0OHIosgXlLOJATC16sxfbGol4p4NXMdEoFvUZdDWQVoRCE3YYg7Oq74+1NWU2rsdlFwdn8rygRtQL72SVC35kaXtjcPx2nlf/fax/MJc3Yz6VO5yPJ1P2cfoObkG7mRaGwS4j5tkR6e58iU1BatvdH14n0M7B/pH5GqzRGmv6x/UzvX+GZfiDPTqtv1is8017LM0Pfo+jVPONi/q1aujz/bhKe/wE=</diagram></mxfile>

View File

@ -0,0 +1 @@
<mxfile host="Electron" modified="2021-01-03T11:17:53.284Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/14.1.5 Chrome/87.0.4280.88 Electron/11.1.1 Safari/537.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eVaniJKiq47HwRf3wGxLj1N/P36G1jleucLCS5y2PbHTgSCQOzBvCoZxY8lIttreW9Fr5rmemdy7nb8ppDepqIK8HpSA0W4LQ1PfH25uymtZg8/l/UiAaxfXUBULfmxhe2NjfvU8b/7X67DdxSTMOc6nX+0wymafpNri96HZRFkq7hFhsS6UP6FJkRsqq+KFwO1U3Awfv1M1otbZI0z+3m+l/WZ7pR/LspF2zXuOZ9lqeGfoBRa/mGReLb9Sy5cX3kvDsHw==</diagram></mxfile>

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -0,0 +1,92 @@
---
title: Explain Yourself! Self-Rationalizing NLP Models
author: James
type: post
draft: false
resources:
- name: feature
src: images/feature.jpg
date: 2021-01-02T16:47:02+00:00
url: /2021/01/02/rationalizing-nlp-classifications/
description: We examine a recent technique for enabling existing NLP models to provide human-readable rationales of why they made a decision.
categories:
- PhD
- Academia
- Open Source
tags:
- machine-learning
- python
- ai
- nlp
---
## Introduction
The ability to understand and rationalise about automated decisions is becoming particularly important as more and more businesses adopt AI into their core processes. This requirement is particularly pertinent in light of legislation like GDPR requiring subjects of automated decisions to be given the right to an explanation as to why that decision was made. There have been a number of breakthroughs in explainable models in the last few years as academic teams in the machine learning space focus their attention on the *why* rather than the *how* of machine learning architecture.
## Recent Progress in Model Explainability
Significant breakthroughs in model explainability were seen in the likes of [LIME](https://towardsdatascience.com/understanding-model-predictions-with-lime-a582fdff3a3b) and [SHAP](https://towardsdatascience.com/explain-your-model-with-the-shap-values-bc36aac4de3d) where local surrogate models, which are explainable but only for the small number of data samples under observation, are used to approximate the importance/contribution of features to a particular decision. These approaches are powerful when input features are meaningful in their own right (e.g. bag-of-words representations where a feature may be the presence or absense of a specific word) but are less helpful when input features are too abstract or are the output of some other black box (e.g. multi-dimensional word vectors or RGB values from pixels).
[Transformer](https://ai.googleblog.com/2017/08/transformer-novel-neural-network.html)-based models like [BERT](https://github.com/google-research/bert) which use the concept of neural attention to learn contextual relationships between words can also be interrogated by [visualising attention patterns inside the model](https://towardsdatascience.com/deconstructing-bert-part-2-visualizing-the-inner-workings-of-attention-60a16d86b5c1)). However, these visualisations are still quite complex (especially for transformer-based models which typically have multiple parallel attention mechanisms to examine) and do not provide concise or intuitive rationalisation for model behaviour.
So how can we generate a human-readable, intuitive justification or rationalization of our model's behaviour and how can we do it without further data labelling? In the remainder of this post we will explore a couple of solutions.
## Solution 1: Rationalization of Neural Predictions (Lei, Barzilay and Jaakkola, 2016)
In 2016, [Lei, Barzilay and Jaakkola](https://people.csail.mit.edu/taolei/papers/emnlp16_rationale.pdf) wrote about a new architecture for rationale extraction from NLP models. The aim was to generate a new model that could extract a "short and coherent" justification for why the model made a particular prediction.
***NB: I've simplified the mathematical notation from the original paper here in order to communicate the concepts more easily.***
The idea is actually quite simple. Firstly, let's assume we're starting with a classification problem where we want to take document **X** and train a classifier function **F(x)** to predict label **y** based on the text in the document (e.g. imagine that X is a movie review and y is positive or negative sentiment).
{{<figure src="images/simple_classifier.png" caption="A simple text classifier that tries to learn to predict y based on text in X">}}
In order to extract rationales, Lei, Barzilay and Jaakkola propose introducing **G(X)** - a generator component - to our model. The generator aims to generate - you probably guessed it - a "short and coherent" rationale **R** for the input documents. The brilliant part is that if we plug our generator into our existing architecture in the right way, we don't need to explicitely train it.
This can be achieved by inserting the generator **G** between **X** and our original classifier **F(X)** (referred to in the paper as the encoder or **enc**) and having the classifier learn to predict **y** from the generated rationale **R**. Then we can randomly sample rationales from **G** and encourage it to generate rationales that help **F** to correctly predict **y** during back-propagation.
**G** is constrained to encourage it to make short rationales (otherwise, it could propose **R=X** which wouldn't help us interpret anything). It is also discouraged from selecting distant groupings of words (this speaks to the 'coherent' part - we don't want a rationale that's just a random selection of words).
{{<figure src="images/simple_classifier_with_generator.png" caption="An updated model that generates a rationale, R, from document X and predicts y based on R.">}}
In order for this model to work, it must be possible for the generator **G** to be able to disentangle key information from the input document **X** in such a way that it's possible for **F(R)** to predict the true output label **y** from it (e.g. "is there anything better" as captured in the figure above might be a concise way to summarise a very positive movie review).
This architecture provides an excellent first pass at our rationale extraction task and Lei, Barzilay and Jaakkola show that it works well on the multi-aspect sentiment problem set out in their paper. However, there are a number of improvements that can be made that [we explore below](#solution-2-re-thinking-cooperative-rationalization-yu-chang-zhang-and-jaakola-2019)
Since we are now going to focus on the improved solution, I have not provided any code for this one. However, you can find the author's [original code here](https://github.com/yala/text_nn/) and a more modern [PyTorch implementation of their work here](https://github.com/yala/text_nn/) - both are fairly well written and clear. The latter is probably more understandable these days given the former is implemented in the now-obsolete [theano](https://groups.google.com/g/theano-users/c/7Poq8BZutbY/m/rNCIfvAEAwAJ%3E%60_?pli=1) framework.
## Solution 2: Re-thinking Cooperative Rationalization (Yu, Chang, Zhang and Jaakola, 2019)
In a follow up paper in 2019, [Yu, Chang, Zhang and Jaakola](http://people.csail.mit.edu/tommi/papers/YCZJ_EMNLP2019.pdf) - Jaakola being one of the authors from the previous paper - propose an improved rationale extraction approach that offers significant performance improvements over the earlier Lei et al paper.
The new framework attempts to control for a number of shortcomings:
1. The earlier framework does not allow the generator **G(X)** any direct visibility onto the desired outcome **y&#771;** (predicted **y**) which may lead to a poor solution.
2. The encoder (**F(R) &#8594; y&#771;**) does not have any direct visibility of the text excluded from the rationale and thus may not be performing optimally.
3. Whilst most classification tasks have clues that are typically short phrases, some tasks require much more complicated context-dependent combinations of words and features that cannot be adequately captured by a rationale leading again leading back to point 2.
4. Due to prior focus only on **R** (point 2.), there is no control over information *not* included in the rationale which means that the generator may condense summaries down to collections of pertinent feature words (e.g. positive or negative adjectives in our sentiment analysis example) and omit contextually relevant information (we might want to know what was good or bad).
The proposed solution is a re-jig of the architecture so that the encoder once again predicts **y** directly from the full input document **X**, the rationale generator **G** has access to this predicted value **y&#771;** (again where **y&#771;** denotes the *predicted* value for **y** according to our model ). This new coupling of the encoder and generator is referred to as a single component known as the *introspective generator* in the paper.
{{<figure src="images/yu_2019_figure_1.png" caption="In this figure taken from [Yu, Chang, Zhang and Jaakola 2019](http://people.csail.mit.edu/tommi/papers/YCZJ_EMNLP2019.pdf), the original rationale extraction framework from above is represented by (a) and the new approach is represented by (c)">}}
We also add a couple of new downstream predictor components:
* **P(y|R)** which is basically a clone of **F(R) &#8594; y&#771;** that's reconfigured to accept a rationale from our new *introspective* generator and predict the probability of **y** given **R**.
* **P(y|R<sup>c</sup>)** which is known as the *complement* predictor and tries to predict the likelihood of **y** given **R**'s complement, **R<sup>c</sup>**, that is, all of the words that are *not* included in the rationale.
The authors refer to this configuration as a three player co-operative game if you count the introspective generator and the two predictors as the players.
## Implementing Solution 2
The design of the three player game solution described above makes it incredibly convenient to retrofit to an existing classifier. We're going to start by taking an ALBERT-based
<script type="text/javascript"
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>