解释一个问答变压器模型
在这里,我们演示如何解释一个问答模型的输出,该模型预测上下文文本的哪个范围包含给定问题的答案。
[1]:
import numpy as np
import torch
import transformers
import shap
# load the model
pmodel = transformers.pipeline("question-answering")
tokenized_qs = None # variable to store the tokenized data
# define two predictions, one that outputs the logits for the range start,
# and the other for the range end
def f(questions, tokenized_qs, start):
outs = []
for q in questions:
idx = np.argwhere(
np.array(tokenized_qs["input_ids"]) == pmodel.tokenizer.sep_token_id
)[0, 0] # this code assumes that there is only one sentence in data
d = tokenized_qs.copy()
d["input_ids"][:idx] = q[:idx]
d["input_ids"][idx + 1 :] = q[idx + 1 :]
out = pmodel.model.forward(**{k: torch.tensor(d[k]).reshape(1, -1) for k in d})
logits = out.start_logits if start else out.end_logits
outs.append(logits.reshape(-1).detach().numpy())
return outs
def tokenize_data(data):
for q in data:
question, context = q.split("[SEP]")
tokenized_data = pmodel.tokenizer(question, context)
return tokenized_data # this code assumes that there is only one sentence in data
def f_start(questions):
return f(questions, tokenized_qs, True)
def f_end(questions):
return f(questions, tokenized_qs, False)
# attach a dynamic output_names property to the models so we can plot the tokens at each output position
def out_names(inputs):
question, context = inputs.split("[SEP]")
d = pmodel.tokenizer(question, context)
return [pmodel.tokenizer.decode([id]) for id in d["input_ids"]]
f_start.output_names = out_names
f_end.output_names = out_names
解释起始位置
这里我们解释模型的起始范围预测。注意,由于模型输出依赖于模型输入的长度,因此我们传递模型的原生分词器进行掩码处理非常重要,这样当我们隐藏文本的部分内容时,我们可以保留相同数量的标记,从而为每个输出位置保留相同的含义。
[2]:
data = [
"What is on the table?[SEP]When I got home today I saw my cat on the table, and my frog on the floor.",
] # this code assumes that there is only one sentence in data
tokenized_qs = tokenize_data(data)
explainer_start = shap.Explainer(
f_start, shap.maskers.Text(tokenizer=pmodel.tokenizer, output_type="ids")
)
shap_values_start = explainer_start(data)
shap.plots.text(shap_values_start)
Partition explainer: 2it [00:32, 32.86s/it]
[0]
outputs
[CLS]
What
is
on
the
table
?
[SEP]
When
I
got
home
today
I
saw
my
cat
on
the
table
,
and
my
frog
on
the
floor
.
[SEP]
inputs
0.0
0.498
What
-0.459
is
0.214
on
0.022
the
-0.374
table
-0.937
?
0.0
[SEP]
-0.059
When
-0.049
I
0.026
got
0.032
home
0.013
today
-0.0
I
-0.137
saw
-0.078
my
-0.254
cat
-0.25
on
-0.05
the
-0.037
table
-0.126
,
-0.182
and
-0.094
my
-0.086
frog
-0.233 / 3
on the floor
-0.108
.
0.0
inputs
0.0
0.498
What
-0.459
is
0.214
on
0.022
the
-0.374
table
-0.937
?
0.0
[SEP]
-0.059
When
-0.049
I
0.026
got
0.032
home
0.013
today
-0.0
I
-0.137
saw
-0.078
my
-0.254
cat
-0.25
on
-0.05
the
-0.037
table
-0.126
,
-0.182
and
-0.094
my
-0.086
frog
-0.233 / 3
on the floor
-0.108
.
0.0
inputs
0.0
1.481
What
-0.906
is
-0.26
on
-0.508
the
-0.669
table
-2.177
?
0.0
[SEP]
-0.043
When
-0.033
I
0.076
got
0.082
home
0.164
today
0.139
I
-0.146
saw
-0.009
my
-0.236
cat
-0.237
on
-0.02
the
-0.027
table
-0.044
,
-0.338
and
-0.226
my
-0.282
frog
-0.185 / 3
on the floor
-0.047
.
0.0
inputs
0.0
1.481
What
-0.906
is
-0.26
on
-0.508
the
-0.669
table
-2.177
?
0.0
[SEP]
-0.043
When
-0.033
I
0.076
got
0.082
home
0.164
today
0.139
I
-0.146
saw
-0.009
my
-0.236
cat
-0.237
on
-0.02
the
-0.027
table
-0.044
,
-0.338
and
-0.226
my
-0.282
frog
-0.185 / 3
on the floor
-0.047
.
0.0
inputs
0.0
0.282
What
-0.845
is
0.186
on
-0.412
the
-0.405
table
-1.745
?
0.0
[SEP]
-0.026
When
-0.016
I
0.106
got
0.109
home
0.213
today
0.187
I
-0.068
saw
0.065
my
-0.246
cat
-0.253
on
0.002
the
-0.013
table
-0.046
,
-0.442
and
-0.211
my
-0.26
frog
-0.265 / 3
on the floor
-0.136
.
0.0
inputs
0.0
0.282
What
-0.845
is
0.186
on
-0.412
the
-0.405
table
-1.745
?
0.0
[SEP]
-0.026
When
-0.016
I
0.106
got
0.109
home
0.213
today
0.187
I
-0.068
saw
0.065
my
-0.246
cat
-0.253
on
0.002
the
-0.013
table
-0.046
,
-0.442
and
-0.211
my
-0.26
frog
-0.265 / 3
on the floor
-0.136
.
0.0
inputs
0.0
0.462
What
0.153
is
0.352
on
-0.81
the
-0.447
table
-2.052
?
0.0
[SEP]
-0.01
When
-0.0
I
0.136
got
0.142
home
0.18
today
0.158
I
-0.098
saw
0.022
my
-0.358
cat
-0.402
on
-0.183
the
-0.245
table
-0.035
,
-0.354
and
-0.24
my
-0.269
frog
-0.343 / 3
on the floor
-0.184
.
0.0
inputs
0.0
0.462
What
0.153
is
0.352
on
-0.81
the
-0.447
table
-2.052
?
0.0
[SEP]
-0.01
When
-0.0
I
0.136
got
0.142
home
0.18
today
0.158
I
-0.098
saw
0.022
my
-0.358
cat
-0.402
on
-0.183
the
-0.245
table
-0.035
,
-0.354
and
-0.24
my
-0.269
frog
-0.343 / 3
on the floor
-0.184
.
0.0
inputs
0.0
0.545
What
-0.584
is
0.457
on
0.117
the
-0.773
table
-2.561
?
0.0
[SEP]
-0.036
When
-0.023
I
0.137
got
0.142
home
0.165
today
0.144
I
-0.141
saw
-0.019
my
-0.27
cat
-0.291
on
-0.23
the
-0.287
table
-0.011
,
-0.32
and
-0.265
my
-0.266
frog
-0.232 / 3
on the floor
-0.063
.
0.0
inputs
0.0
0.545
What
-0.584
is
0.457
on
0.117
the
-0.773
table
-2.561
?
0.0
[SEP]
-0.036
When
-0.023
I
0.137
got
0.142
home
0.165
today
0.144
I
-0.141
saw
-0.019
my
-0.27
cat
-0.291
on
-0.23
the
-0.287
table
-0.011
,
-0.32
and
-0.265
my
-0.266
frog
-0.232 / 3
on the floor
-0.063
.
0.0
inputs
0.0
0.441
What
-0.508
is
-0.307
on
0.383
the
0.25
table
-2.004
?
0.0
[SEP]
-0.067
When
-0.056
I
0.082
got
0.091
home
0.14
today
0.117
I
-0.176
saw
-0.045
my
-0.185
cat
-0.199
on
-0.135
the
-0.206
table
-0.009
,
-0.315
and
-0.259
my
-0.257
frog
-0.289 / 3
on the floor
-0.121
.
0.0
inputs
0.0
0.441
What
-0.508
is
-0.307
on
0.383
the
0.25
table
-2.004
?
0.0
[SEP]
-0.067
When
-0.056
I
0.082
got
0.091
home
0.14
today
0.117
I
-0.176
saw
-0.045
my
-0.185
cat
-0.199
on
-0.135
the
-0.206
table
-0.009
,
-0.315
and
-0.259
my
-0.257
frog
-0.289 / 3
on the floor
-0.121
.
0.0
inputs
0.0
0.612
What
-0.902
is
-0.073
on
-0.194
the
-0.913
table
3.542
?
0.0
[SEP]
-0.095
When
-0.09
I
0.072
got
0.083
home
0.061
today
0.041
I
-0.151
saw
-0.046
my
-0.268
cat
-0.275
on
0.014
the
0.043
table
-0.127
,
-0.431
and
-0.229
my
-0.222
frog
-0.329 / 3
on the floor
-0.127
.
0.0
inputs
0.0
0.612
What
-0.902
is
-0.073
on
-0.194
the
-0.913
table
3.542
?
0.0
[SEP]
-0.095
When
-0.09
I
0.072
got
0.083
home
0.061
today
0.041
I
-0.151
saw
-0.046
my
-0.268
cat
-0.275
on
0.014
the
0.043
table
-0.127
,
-0.431
and
-0.229
my
-0.222
frog
-0.329 / 3
on the floor
-0.127
.
0.0
inputs
0.0
1.155
What
-0.141
is
0.108
on
0.293
the
-0.469
table
-0.653
?
0.0
[SEP]
-0.027
When
-0.011
I
0.072
got
0.094
home
0.064
today
0.046
I
-0.187
saw
-0.074
my
-0.224
cat
-0.214
on
0.156
the
0.187
table
-0.01
,
-0.085
and
-0.058
my
-0.122
frog
-0.02 / 3
on the floor
0.068
.
0.0
inputs
0.0
1.155
What
-0.141
is
0.108
on
0.293
the
-0.469
table
-0.653
?
0.0
[SEP]
-0.027
When
-0.011
I
0.072
got
0.094
home
0.064
today
0.046
I
-0.187
saw
-0.074
my
-0.224
cat
-0.214
on
0.156
the
0.187
table
-0.01
,
-0.085
and
-0.058
my
-0.122
frog
-0.02 / 3
on the floor
0.068
.
0.0
inputs
0.0
0.905
What
0.193
is
-0.006
on
0.464
the
0.012
table
0.71
?
0.0
[SEP]
-0.366
When
-0.443
I
-0.502
got
-0.454
home
-0.37
today
-0.354
I
-0.146
saw
-0.096
my
-0.396
cat
-0.351
on
0.405
the
0.485
table
-0.148
,
-0.286
and
-0.133
my
-0.16
frog
0.13 / 3
on the floor
0.149
.
0.0
inputs
0.0
0.905
What
0.193
is
-0.006
on
0.464
the
0.012
table
0.71
?
0.0
[SEP]
-0.366
When
-0.443
I
-0.502
got
-0.454
home
-0.37
today
-0.354
I
-0.146
saw
-0.096
my
-0.396
cat
-0.351
on
0.405
the
0.485
table
-0.148
,
-0.286
and
-0.133
my
-0.16
frog
0.13 / 3
on the floor
0.149
.
0.0
inputs
0.0
0.78
What
0.145
is
0.048
on
0.458
the
-0.114
table
-0.289
?
0.0
[SEP]
0.128
When
0.047
I
-0.309
got
-0.273
home
-0.579
today
-0.55
I
-0.079
saw
-0.008
my
-0.304
cat
-0.269
on
0.327
the
0.401
table
-0.081
,
-0.266
and
-0.076
my
-0.125
frog
0.057 / 3
on the floor
0.081
.
0.0
inputs
0.0
0.78
What
0.145
is
0.048
on
0.458
the
-0.114
table
-0.289
?
0.0
[SEP]
0.128
When
0.047
I
-0.309
got
-0.273
home
-0.579
today
-0.55
I
-0.079
saw
-0.008
my
-0.304
cat
-0.269
on
0.327
the
0.401
table
-0.081
,
-0.266
and
-0.076
my
-0.125
frog
0.057 / 3
on the floor
0.081
.
0.0
inputs
0.0
0.711
What
0.021
is
0.116
on
0.372
the
-0.16
table
-0.2
?
0.0
[SEP]
-0.666
When
-0.716
I
-0.439
got
-0.402
home
-0.681
today
-0.646
I
-0.035
saw
0.02
my
-0.321
cat
-0.268
on
0.358
the
0.43
table
-0.099
,
-0.299
and
-0.076
my
-0.096
frog
0.092 / 3
on the floor
0.107
.
0.0
inputs
0.0
0.711
What
0.021
is
0.116
on
0.372
the
-0.16
table
-0.2
?
0.0
[SEP]
-0.666
When
-0.716
I
-0.439
got
-0.402
home
-0.681
today
-0.646
I
-0.035
saw
0.02
my
-0.321
cat
-0.268
on
0.358
the
0.43
table
-0.099
,
-0.299
and
-0.076
my
-0.096
frog
0.092 / 3
on the floor
0.107
.
0.0
inputs
0.0
0.652
What
-0.084
is
0.176
on
0.351
the
-0.2
table
-0.237
?
0.0
[SEP]
-0.236
When
-0.166
I
-0.558
got
-0.474
home
-0.872
today
-0.834
I
-0.089
saw
-0.023
my
-0.294
cat
-0.242
on
0.335
the
0.409
table
-0.094
,
-0.309
and
-0.074
my
-0.1
frog
0.083 / 3
on the floor
0.097
.
0.0
inputs
0.0
0.652
What
-0.084
is
0.176
on
0.351
the
-0.2
table
-0.237
?
0.0
[SEP]
-0.236
When
-0.166
I
-0.558
got
-0.474
home
-0.872
today
-0.834
I
-0.089
saw
-0.023
my
-0.294
cat
-0.242
on
0.335
the
0.409
table
-0.094
,
-0.309
and
-0.074
my
-0.1
frog
0.083 / 3
on the floor
0.097
.
0.0
inputs
0.0
0.74
What
-0.071
is
0.18
on
0.301
the
-0.336
table
-0.371
?
0.0
[SEP]
-0.051
When
0.024
I
0.159
got
0.063
home
-0.734
today
-0.749
I
-0.438
saw
-0.39
my
-0.256
cat
-0.196
on
0.334
the
0.43
table
-0.09
,
-0.295
and
-0.069
my
-0.108
frog
0.072 / 3
on the floor
0.078
.
0.0
inputs
0.0
0.74
What
-0.071
is
0.18
on
0.301
the
-0.336
table
-0.371
?
0.0
[SEP]
-0.051
When
0.024
I
0.159
got
0.063
home
-0.734
today
-0.749
I
-0.438
saw
-0.39
my
-0.256
cat
-0.196
on
0.334
the
0.43
table
-0.09
,
-0.295
and
-0.069
my
-0.108
frog
0.072 / 3
on the floor
0.078
.
0.0
inputs
0.0
1.001
What
0.188
is
-0.058
on
0.318
the
-0.229
table
-0.556
?
0.0
[SEP]
0.061
When
0.111
I
0.64
got
0.598
home
0.026
today
0.118
I
-0.883
saw
-0.964
my
-0.193
cat
-0.147
on
0.311
the
0.426
table
-0.058
,
-0.219
and
-0.124
my
-0.156
frog
-0.012 / 3
on the floor
0.03
.
0.0
inputs
0.0
1.001
What
0.188
is
-0.058
on
0.318
the
-0.229
table
-0.556
?
0.0
[SEP]
0.061
When
0.111
I
0.64
got
0.598
home
0.026
today
0.118
I
-0.883
saw
-0.964
my
-0.193
cat
-0.147
on
0.311
the
0.426
table
-0.058
,
-0.219
and
-0.124
my
-0.156
frog
-0.012 / 3
on the floor
0.03
.
0.0
inputs
0.0
1.034
What
0.103
is
0.008
on
0.274
the
-0.221
table
-0.361
?
0.0
[SEP]
0.042
When
0.065
I
0.533
got
0.523
home
-0.572
today
-0.976
I
-0.696
saw
-0.761
my
-0.188
cat
-0.114
on
0.271
the
0.382
table
-0.089
,
-0.362
and
-0.15
my
-0.182
frog
0.078 / 3
on the floor
0.104
.
0.0
inputs
0.0
1.034
What
0.103
is
0.008
on
0.274
the
-0.221
table
-0.361
?
0.0
[SEP]
0.042
When
0.065
I
0.533
got
0.523
home
-0.572
today
-0.976
I
-0.696
saw
-0.761
my
-0.188
cat
-0.114
on
0.271
the
0.382
table
-0.089
,
-0.362
and
-0.15
my
-0.182
frog
0.078 / 3
on the floor
0.104
.
0.0
inputs
0.0
1.598
What
-0.373
is
0.316
on
0.34
the
0.729
table
0.391
?
0.0
[SEP]
0.171
When
0.168
I
0.435
got
0.445
home
0.481
today
0.391
I
0.396
saw
0.553
my
0.31
cat
0.347
on
0.226
the
0.4
table
-0.057
,
-0.206
and
-0.072
my
-0.14
frog
0.214 / 3
on the floor
0.205
.
0.0
inputs
0.0
1.598
What
-0.373
is
0.316
on
0.34
the
0.729
table
0.391
?
0.0
[SEP]
0.171
When
0.168
I
0.435
got
0.445
home
0.481
today
0.391
I
0.396
saw
0.553
my
0.31
cat
0.347
on
0.226
the
0.4
table
-0.057
,
-0.206
and
-0.072
my
-0.14
frog
0.214 / 3
on the floor
0.205
.
0.0
inputs
0.0
1.125
What
-0.534
is
0.506
on
0.446
the
0.669
table
0.515
?
0.0
[SEP]
0.089
When
0.09
I
0.217
got
0.237
home
0.521
today
0.495
I
0.108
saw
0.285
my
1.1
cat
0.873
on
-0.134
the
0.164
table
-0.026
,
-0.134
and
0.003
my
-0.105
frog
0.207 / 3
on the floor
0.163
.
0.0
inputs
0.0
1.125
What
-0.534
is
0.506
on
0.446
the
0.669
table
0.515
?
0.0
[SEP]
0.089
When
0.09
I
0.217
got
0.237
home
0.521
today
0.495
I
0.108
saw
0.285
my
1.1
cat
0.873
on
-0.134
the
0.164
table
-0.026
,
-0.134
and
0.003
my
-0.105
frog
0.207 / 3
on the floor
0.163
.
0.0
inputs
0.0
0.989
What
-0.005
is
0.321
on
0.269
the
-0.26
table
0.063
?
0.0
[SEP]
0.042
When
0.054
I
0.144
got
0.141
home
0.222
today
0.181
I
-0.221
saw
-0.137
my
-0.793
cat
-0.661
on
-0.727
the
-0.545
table
-0.41
,
-0.282
and
-0.164
my
-0.208
frog
0.056 / 3
on the floor
0.088
.
0.0
inputs
0.0
0.989
What
-0.005
is
0.321
on
0.269
the
-0.26
table
0.063
?
0.0
[SEP]
0.042
When
0.054
I
0.144
got
0.141
home
0.222
today
0.181
I
-0.221
saw
-0.137
my
-0.793
cat
-0.661
on
-0.727
the
-0.545
table
-0.41
,
-0.282
and
-0.164
my
-0.208
frog
0.056 / 3
on the floor
0.088
.
0.0
inputs
0.0
0.908
What
0.063
is
0.613
on
0.117
the
-0.624
table
-0.131
?
0.0
[SEP]
0.034
When
0.05
I
0.166
got
0.169
home
0.264
today
0.234
I
-0.184
saw
-0.088
my
-0.872
cat
-1.065
on
-0.654
the
-0.768
table
-0.755
,
-0.218
and
-0.178
my
-0.237
frog
0.123 / 3
on the floor
0.155
.
0.0
inputs
0.0
0.908
What
0.063
is
0.613
on
0.117
the
-0.624
table
-0.131
?
0.0
[SEP]
0.034
When
0.05
I
0.166
got
0.169
home
0.264
today
0.234
I
-0.184
saw
-0.088
my
-0.872
cat
-1.065
on
-0.654
the
-0.768
table
-0.755
,
-0.218
and
-0.178
my
-0.237
frog
0.123 / 3
on the floor
0.155
.
0.0
inputs
0.0
0.744
What
-0.075
is
0.448
on
0.325
the
-0.393
table
0.043
?
0.0
[SEP]
0.015
When
0.026
I
0.102
got
0.109
home
0.194
today
0.173
I
-0.16
saw
-0.038
my
-0.804
cat
-1.023
on
-0.118
the
-0.281
table
-0.777
,
-0.494
and
-0.147
my
-0.196
frog
0.143 / 3
on the floor
0.142
.
0.0
inputs
0.0
0.744
What
-0.075
is
0.448
on
0.325
the
-0.393
table
0.043
?
0.0
[SEP]
0.015
When
0.026
I
0.102
got
0.109
home
0.194
today
0.173
I
-0.16
saw
-0.038
my
-0.804
cat
-1.023
on
-0.118
the
-0.281
table
-0.777
,
-0.494
and
-0.147
my
-0.196
frog
0.143 / 3
on the floor
0.142
.
0.0
inputs
0.0
0.895
What
-0.047
is
0.272
on
0.194
the
0.018
table
0.022
?
0.0
[SEP]
0.019
When
0.028
I
0.148
got
0.156
home
0.167
today
0.14
I
-0.158
saw
-0.083
my
-0.472
cat
-0.49
on
-0.041
the
0.026
table
-2.996
,
-1.142
and
-0.233
my
-0.215
frog
0.063 / 3
on the floor
0.144
.
0.0
inputs
0.0
0.895
What
-0.047
is
0.272
on
0.194
the
0.018
table
0.022
?
0.0
[SEP]
0.019
When
0.028
I
0.148
got
0.156
home
0.167
today
0.14
I
-0.158
saw
-0.083
my
-0.472
cat
-0.49
on
-0.041
the
0.026
table
-2.996
,
-1.142
and
-0.233
my
-0.215
frog
0.063 / 3
on the floor
0.144
.
0.0
inputs
0.0
1.233
What
0.025
is
0.2
on
0.107
the
-0.189
table
0.113
?
0.0
[SEP]
0.095
When
0.103
I
0.22
got
0.213
home
0.17
today
0.183
I
-0.057
saw
-0.081
my
-0.425
cat
-0.41
on
0.227
the
0.42
table
0.368
,
-3.409
and
-0.45
my
-0.307
frog
-0.188 / 3
on the floor
-0.009
.
0.0
inputs
0.0
1.233
What
0.025
is
0.2
on
0.107
the
-0.189
table
0.113
?
0.0
[SEP]
0.095
When
0.103
I
0.22
got
0.213
home
0.17
today
0.183
I
-0.057
saw
-0.081
my
-0.425
cat
-0.41
on
0.227
the
0.42
table
0.368
,
-3.409
and
-0.45
my
-0.307
frog
-0.188 / 3
on the floor
-0.009
.
0.0
inputs
0.0
1.235
What
-0.24
is
0.124
on
-0.09
the
-0.719
table
0.438
?
0.0
[SEP]
0.067
When
0.087
I
0.312
got
0.282
home
0.175
today
0.204
I
-0.051
saw
-0.11
my
-0.156
cat
-0.098
on
0.195
the
0.238
table
-0.13
,
1.735
and
0.41
my
0.677
frog
-0.027 / 3
on the floor
0.188
.
0.0
inputs
0.0
1.235
What
-0.24
is
0.124
on
-0.09
the
-0.719
table
0.438
?
0.0
[SEP]
0.067
When
0.087
I
0.312
got
0.282
home
0.175
today
0.204
I
-0.051
saw
-0.11
my
-0.156
cat
-0.098
on
0.195
the
0.238
table
-0.13
,
1.735
and
0.41
my
0.677
frog
-0.027 / 3
on the floor
0.188
.
0.0
inputs
0.0
0.971
What
-0.307
is
0.256
on
-0.021
the
-0.886
table
0.579
?
0.0
[SEP]
0.122
When
0.163
I
0.335
got
0.31
home
0.226
today
0.253
I
0.003
saw
-0.028
my
-0.131
cat
-0.078
on
0.005
the
-0.005
table
0.032
,
0.03
and
1.392
my
1.712
frog
-0.116 / 3
on the floor
0.199
.
0.0
inputs
0.0
0.971
What
-0.307
is
0.256
on
-0.021
the
-0.886
table
0.579
?
0.0
[SEP]
0.122
When
0.163
I
0.335
got
0.31
home
0.226
today
0.253
I
0.003
saw
-0.028
my
-0.131
cat
-0.078
on
0.005
the
-0.005
table
0.032
,
0.03
and
1.392
my
1.712
frog
-0.116 / 3
on the floor
0.199
.
0.0
inputs
0.0
0.838
What
0.505
is
0.316
on
0.108
the
-0.827
table
0.255
?
0.0
[SEP]
0.075
When
0.098
I
0.274
got
0.254
home
0.205
today
0.224
I
0.067
saw
0.03
my
-0.333
cat
-0.325
on
0.003
the
0.019
table
-0.203
,
-0.249
and
-0.446
my
-0.53
frog
-0.3 / 3
on the floor
0.135
.
0.0
inputs
0.0
0.838
What
0.505
is
0.316
on
0.108
the
-0.827
table
0.255
?
0.0
[SEP]
0.075
When
0.098
I
0.274
got
0.254
home
0.205
today
0.224
I
0.067
saw
0.03
my
-0.333
cat
-0.325
on
0.003
the
0.019
table
-0.203
,
-0.249
and
-0.446
my
-0.53
frog
-0.3 / 3
on the floor
0.135
.
0.0
inputs
0.0
0.911
What
0.514
is
0.499
on
-0.044
the
-0.882
table
0.21
?
0.0
[SEP]
0.048
When
0.073
I
0.243
got
0.226
home
0.176
today
0.199
I
0.053
saw
0.01
my
-0.219
cat
-0.181
on
-0.107
the
-0.091
table
-0.001
,
-0.301
and
-0.206
my
-0.364
frog
-0.558 / 3
on the floor
-0.118
.
0.0
inputs
0.0
0.911
What
0.514
is
0.499
on
-0.044
the
-0.882
table
0.21
?
0.0
[SEP]
0.048
When
0.073
I
0.243
got
0.226
home
0.176
today
0.199
I
0.053
saw
0.01
my
-0.219
cat
-0.181
on
-0.107
the
-0.091
table
-0.001
,
-0.301
and
-0.206
my
-0.364
frog
-0.558 / 3
on the floor
-0.118
.
0.0
inputs
0.0
0.819
What
0.245
is
0.273
on
-0.003
the
-0.431
table
0.246
?
0.0
[SEP]
-0.017
When
-0.001
I
0.143
got
0.137
home
0.077
today
0.095
I
-0.036
saw
-0.064
my
-0.21
cat
-0.191
on
-0.054
the
-0.025
table
-0.122
,
-0.308
and
-0.17
my
-0.274
frog
-0.052 / 3
on the floor
0.23
.
0.0
inputs
0.0
0.819
What
0.245
is
0.273
on
-0.003
the
-0.431
table
0.246
?
0.0
[SEP]
-0.017
When
-0.001
I
0.143
got
0.137
home
0.077
today
0.095
I
-0.036
saw
-0.064
my
-0.21
cat
-0.191
on
-0.054
the
-0.025
table
-0.122
,
-0.308
and
-0.17
my
-0.274
frog
-0.052 / 3
on the floor
0.23
.
0.0
inputs
0.0
0.753
What
-0.243
is
-0.058
on
-0.052
the
-0.61
table
0.038
?
0.0
[SEP]
-0.035
When
-0.029
I
0.153
got
0.149
home
0.109
today
0.103
I
-0.027
saw
-0.017
my
-0.214
cat
-0.208
on
-0.039
the
0.015
table
-0.32
,
-0.345
and
-0.126
my
-0.078
frog
0.161 / 3
on the floor
0.78
.
0.0
inputs
0.0
0.753
What
-0.243
is
-0.058
on
-0.052
the
-0.61
table
0.038
?
0.0
[SEP]
-0.035
When
-0.029
I
0.153
got
0.149
home
0.109
today
0.103
I
-0.027
saw
-0.017
my
-0.214
cat
-0.208
on
-0.039
the
0.015
table
-0.32
,
-0.345
and
-0.126
my
-0.078
frog
0.161 / 3
on the floor
0.78
.
0.0
inputs
0.0
1.155
What
-0.141
is
0.108
on
0.293
the
-0.469
table
-0.653
?
0.0
[SEP]
-0.027
When
-0.011
I
0.072
got
0.094
home
0.064
today
0.046
I
-0.187
saw
-0.074
my
-0.224
cat
-0.214
on
0.156
the
0.187
table
-0.01
,
-0.085
and
-0.058
my
-0.122
frog
-0.02 / 3
on the floor
0.068
.
0.0
inputs
0.0
1.155
What
-0.141
is
0.108
on
0.293
the
-0.469
table
-0.653
?
0.0
[SEP]
-0.027
When
-0.011
I
0.072
got
0.094
home
0.064
today
0.046
I
-0.187
saw
-0.074
my
-0.224
cat
-0.214
on
0.156
the
0.187
table
-0.01
,
-0.085
and
-0.058
my
-0.122
frog
-0.02 / 3
on the floor
0.068
.
0.0
解释结束位置
这个过程与上面相同,但现在我们解释结束标记。
[3]:
explainer_end = shap.Explainer(f_end, pmodel.tokenizer)
shap_values_end = explainer_end(data)
shap.plots.text(shap_values_end)
[0]
outputs
[CLS]
What
is
on
the
table
?
[SEP]
When
I
got
home
today
I
saw
my
cat
on
the
table
,
and
my
frog
on
the
floor
.
[SEP]
inputs
0.129
0.424
What
-0.093
is
0.069
on
0.231
the
-0.126
table
-0.635
?
0.0
[SEP]
0.215 / 2
When I
0.233 / 2
got home
0.21 / 4
today I saw my
-0.292 / 2
cat on
-0.068 / 2
the table
-0.119
,
-0.217
and
-0.221 / 2
my frog
-0.159 / 3
on the floor
-0.018
.
0.0
inputs
0.129
0.424
What
-0.093
is
0.069
on
0.231
the
-0.126
table
-0.635
?
0.0
[SEP]
0.215 / 2
When I
0.233 / 2
got home
0.21 / 4
today I saw my
-0.292 / 2
cat on
-0.068 / 2
the table
-0.119
,
-0.217
and
-0.221 / 2
my frog
-0.159 / 3
on the floor
-0.018
.
0.0
inputs
0.207
0.528
What
0.834
is
0.027
on
0.456
the
0.173
table
-1.203
?
0.0
[SEP]
0.3 / 2
When I
0.341 / 2
got home
0.729 / 4
today I saw my
-0.048 / 2
cat on
0.121 / 2
the table
-0.022
,
-0.319
and
-0.328 / 2
my frog
0.09 / 3
on the floor
0.145
.
0.0
inputs
0.207
0.528
What
0.834
is
0.027
on
0.456
the
0.173
table
-1.203
?
0.0
[SEP]
0.3 / 2
When I
0.341 / 2
got home
0.729 / 4
today I saw my
-0.048 / 2
cat on
0.121 / 2
the table
-0.022
,
-0.319
and
-0.328 / 2
my frog
0.09 / 3
on the floor
0.145
.
0.0
inputs
0.082
0.218
What
-1.307
is
0.333
on
0.608
the
-0.02
table
-1.25
?
0.0
[SEP]
0.292 / 2
When I
0.347 / 2
got home
0.659 / 4
today I saw my
-0.166 / 2
cat on
0.079 / 2
the table
0.01
,
-0.385
and
-0.39 / 2
my frog
-0.038 / 3
on the floor
0.036
.
0.0
inputs
0.082
0.218
What
-1.307
is
0.333
on
0.608
the
-0.02
table
-1.25
?
0.0
[SEP]
0.292 / 2
When I
0.347 / 2
got home
0.659 / 4
today I saw my
-0.166 / 2
cat on
0.079 / 2
the table
0.01
,
-0.385
and
-0.39 / 2
my frog
-0.038 / 3
on the floor
0.036
.
0.0
inputs
0.099
0.288
What
-0.265
is
-0.295
on
-0.833
the
-0.442
table
-1.202
?
0.0
[SEP]
0.259 / 2
When I
0.333 / 2
got home
0.578 / 4
today I saw my
-0.387 / 2
cat on
-0.304 / 2
the table
-0.004
,
-0.424
and
-0.435 / 2
my frog
-0.188 / 3
on the floor
-0.059
.
0.0
inputs
0.099
0.288
What
-0.265
is
-0.295
on
-0.833
the
-0.442
table
-1.202
?
0.0
[SEP]
0.259 / 2
When I
0.333 / 2
got home
0.578 / 4
today I saw my
-0.387 / 2
cat on
-0.304 / 2
the table
-0.004
,
-0.424
and
-0.435 / 2
my frog
-0.188 / 3
on the floor
-0.059
.
0.0
inputs
0.116
0.32
What
-0.485
is
-0.085
on
-0.918
the
-1.042
table
-1.037
?
0.0
[SEP]
0.219 / 2
When I
0.305 / 2
got home
0.478 / 4
today I saw my
-0.319 / 2
cat on
-0.302 / 2
the table
-0.067
,
-0.484
and
-0.499 / 2
my frog
-0.224 / 3
on the floor
-0.061
.
0.0
inputs
0.116
0.32
What
-0.485
is
-0.085
on
-0.918
the
-1.042
table
-1.037
?
0.0
[SEP]
0.219 / 2
When I
0.305 / 2
got home
0.478 / 4
today I saw my
-0.319 / 2
cat on
-0.302 / 2
the table
-0.067
,
-0.484
and
-0.499 / 2
my frog
-0.224 / 3
on the floor
-0.061
.
0.0
inputs
0.131
0.306
What
-0.566
is
-0.201
on
-0.521
the
0.85
table
-1.723
?
0.0
[SEP]
0.325 / 2
When I
0.389 / 2
got home
0.6 / 4
today I saw my
-0.265 / 2
cat on
-0.416 / 2
the table
-0.074
,
-0.397
and
-0.413 / 2
my frog
-0.318 / 3
on the floor
-0.098
.
0.0
inputs
0.131
0.306
What
-0.566
is
-0.201
on
-0.521
the
0.85
table
-1.723
?
0.0
[SEP]
0.325 / 2
When I
0.389 / 2
got home
0.6 / 4
today I saw my
-0.265 / 2
cat on
-0.416 / 2
the table
-0.074
,
-0.397
and
-0.413 / 2
my frog
-0.318 / 3
on the floor
-0.098
.
0.0
inputs
0.109
0.35
What
-0.735
is
-0.215
on
-0.59
the
-1.159
table
1.133
?
0.0
[SEP]
-0.036 / 2
When I
0.002 / 2
got home
-0.125 / 4
today I saw my
-0.402 / 2
cat on
-0.328 / 2
the table
-0.267
,
-0.477
and
-0.484 / 2
my frog
-0.388 / 3
on the floor
-0.107
.
0.0
inputs
0.109
0.35
What
-0.735
is
-0.215
on
-0.59
the
-1.159
table
1.133
?
0.0
[SEP]
-0.036 / 2
When I
0.002 / 2
got home
-0.125 / 4
today I saw my
-0.402 / 2
cat on
-0.328 / 2
the table
-0.267
,
-0.477
and
-0.484 / 2
my frog
-0.388 / 3
on the floor
-0.107
.
0.0
inputs
0.322
0.95
What
0.246
is
-0.095
on
0.389
the
-0.156
table
-0.878
?
0.0
[SEP]
0.198 / 2
When I
0.162 / 2
got home
-0.235 / 4
today I saw my
-0.451 / 2
cat on
0.213 / 2
the table
-0.12
,
-0.368
and
-0.38 / 2
my frog
0.013 / 3
on the floor
0.112
.
0.0
inputs
0.322
0.95
What
0.246
is
-0.095
on
0.389
the
-0.156
table
-0.878
?
0.0
[SEP]
0.198 / 2
When I
0.162 / 2
got home
-0.235 / 4
today I saw my
-0.451 / 2
cat on
0.213 / 2
the table
-0.12
,
-0.368
and
-0.38 / 2
my frog
0.013 / 3
on the floor
0.112
.
0.0
inputs
0.186
0.494
What
0.286
is
-0.018
on
0.378
the
0.192
table
-0.518
?
0.0
[SEP]
-1.257 / 2
When I
-1.011 / 2
got home
-1.252 / 4
today I saw my
-0.226 / 2
cat on
0.439 / 2
the table
-0.094
,
-0.204
and
-0.202 / 2
my frog
0.237 / 3
on the floor
0.256
.
0.0
inputs
0.186
0.494
What
0.286
is
-0.018
on
0.378
the
0.192
table
-0.518
?
0.0
[SEP]
-1.257 / 2
When I
-1.011 / 2
got home
-1.252 / 4
today I saw my
-0.226 / 2
cat on
0.439 / 2
the table
-0.094
,
-0.204
and
-0.202 / 2
my frog
0.237 / 3
on the floor
0.256
.
0.0
inputs
0.184
0.487
What
0.252
is
0.006
on
0.451
the
0.026
table
-0.108
?
0.0
[SEP]
-0.905 / 2
When I
-0.563 / 2
got home
-1.16 / 4
today I saw my
-0.241 / 2
cat on
0.565 / 2
the table
-0.019
,
-0.176
and
-0.169 / 2
my frog
0.212 / 3
on the floor
0.223
.
0.0
inputs
0.184
0.487
What
0.252
is
0.006
on
0.451
the
0.026
table
-0.108
?
0.0
[SEP]
-0.905 / 2
When I
-0.563 / 2
got home
-1.16 / 4
today I saw my
-0.241 / 2
cat on
0.565 / 2
the table
-0.019
,
-0.176
and
-0.169 / 2
my frog
0.212 / 3
on the floor
0.223
.
0.0
inputs
0.193
0.503
What
0.303
is
0.083
on
0.428
the
0.002
table
-0.341
?
0.0
[SEP]
-2.325 / 2
When I
-2.368 / 2
got home
-0.787 / 4
today I saw my
-0.229 / 2
cat on
0.651 / 2
the table
0.0
,
-0.192
and
-0.189 / 2
my frog
0.238 / 3
on the floor
0.244
.
0.0
inputs
0.193
0.503
What
0.303
is
0.083
on
0.428
the
0.002
table
-0.341
?
0.0
[SEP]
-2.325 / 2
When I
-2.368 / 2
got home
-0.787 / 4
today I saw my
-0.229 / 2
cat on
0.651 / 2
the table
0.0
,
-0.192
and
-0.189 / 2
my frog
0.238 / 3
on the floor
0.244
.
0.0
inputs
0.167
0.424
What
0.386
is
0.023
on
0.462
the
0.002
table
-0.681
?
0.0
[SEP]
-0.282 / 2
When I
-0.187 / 2
got home
-0.723 / 4
today I saw my
-0.365 / 2
cat on
0.642 / 2
the table
0.014
,
-0.18
and
-0.181 / 2
my frog
0.232 / 3
on the floor
0.219
.
0.0
inputs
0.167
0.424
What
0.386
is
0.023
on
0.462
the
0.002
table
-0.681
?
0.0
[SEP]
-0.282 / 2
When I
-0.187 / 2
got home
-0.723 / 4
today I saw my
-0.365 / 2
cat on
0.642 / 2
the table
0.014
,
-0.18
and
-0.181 / 2
my frog
0.232 / 3
on the floor
0.219
.
0.0
inputs
0.197
0.516
What
0.392
is
0.007
on
0.44
the
-0.066
table
-0.611
?
0.0
[SEP]
-0.403 / 2
When I
-0.508 / 2
got home
0.436 / 4
today I saw my
-0.298 / 2
cat on
0.65 / 2
the table
-0.023
,
-0.134
and
-0.139 / 2
my frog
0.254 / 3
on the floor
0.237
.
0.0
inputs
0.197
0.516
What
0.392
is
0.007
on
0.44
the
-0.066
table
-0.611
?
0.0
[SEP]
-0.403 / 2
When I
-0.508 / 2
got home
0.436 / 4
today I saw my
-0.298 / 2
cat on
0.65 / 2
the table
-0.023
,
-0.134
and
-0.139 / 2
my frog
0.254 / 3
on the floor
0.237
.
0.0
inputs
0.217
0.556
What
0.199
is
-0.041
on
0.405
the
-0.067
table
-0.167
?
0.0
[SEP]
-0.273 / 2
When I
-0.271 / 2
got home
-1.916 / 4
today I saw my
-0.406 / 2
cat on
0.548 / 2
the table
-0.119
,
-0.207
and
-0.216 / 2
my frog
0.253 / 3
on the floor
0.256
.
0.0
inputs
0.217
0.556
What
0.199
is
-0.041
on
0.405
the
-0.067
table
-0.167
?
0.0
[SEP]
-0.273 / 2
When I
-0.271 / 2
got home
-1.916 / 4
today I saw my
-0.406 / 2
cat on
0.548 / 2
the table
-0.119
,
-0.207
and
-0.216 / 2
my frog
0.253 / 3
on the floor
0.256
.
0.0
inputs
0.236
0.651
What
0.282
is
0.051
on
0.372
the
-0.057
table
-0.126
?
0.0
[SEP]
0.054 / 2
When I
0.096 / 2
got home
-4.062 / 4
today I saw my
-0.678 / 2
cat on
0.43 / 2
the table
-0.219
,
-0.262
and
-0.276 / 2
my frog
0.259 / 3
on the floor
0.268
.
0.0
inputs
0.236
0.651
What
0.282
is
0.051
on
0.372
the
-0.057
table
-0.126
?
0.0
[SEP]
0.054 / 2
When I
0.096 / 2
got home
-4.062 / 4
today I saw my
-0.678 / 2
cat on
0.43 / 2
the table
-0.219
,
-0.262
and
-0.276 / 2
my frog
0.259 / 3
on the floor
0.268
.
0.0
inputs
0.307
0.883
What
0.03
is
0.044
on
0.308
the
0.507
table
0.513
?
0.0
[SEP]
0.266 / 2
When I
0.292 / 2
got home
-2.109 / 4
today I saw my
-1.145 / 2
cat on
1.007 / 2
the table
-0.177
,
-0.087
and
-0.102 / 2
my frog
0.36 / 3
on the floor
0.337
.
0.0
inputs
0.307
0.883
What
0.03
is
0.044
on
0.308
the
0.507
table
0.513
?
0.0
[SEP]
0.266 / 2
When I
0.292 / 2
got home
-2.109 / 4
today I saw my
-1.145 / 2
cat on
1.007 / 2
the table
-0.177
,
-0.087
and
-0.102 / 2
my frog
0.36 / 3
on the floor
0.337
.
0.0
inputs
0.269
0.839
What
-0.108
is
0.332
on
0.62
the
1.181
table
0.693
?
0.0
[SEP]
0.359 / 2
When I
0.388 / 2
got home
-0.12 / 4
today I saw my
2.35 / 2
cat on
2.624 / 2
the table
-0.069
,
-0.157
and
-0.17 / 2
my frog
0.38 / 3
on the floor
0.319
.
0.0
inputs
0.269
0.839
What
-0.108
is
0.332
on
0.62
the
1.181
table
0.693
?
0.0
[SEP]
0.359 / 2
When I
0.388 / 2
got home
-0.12 / 4
today I saw my
2.35 / 2
cat on
2.624 / 2
the table
-0.069
,
-0.157
and
-0.17 / 2
my frog
0.38 / 3
on the floor
0.319
.
0.0
inputs
0.276
0.871
What
0.007
is
0.205
on
0.377
the
0.865
table
0.289
?
0.0
[SEP]
0.382 / 2
When I
0.416 / 2
got home
-0.515 / 4
today I saw my
-2.21 / 2
cat on
-1.431 / 2
the table
-0.377
,
-0.339
and
-0.343 / 2
my frog
0.29 / 3
on the floor
0.298
.
0.0
inputs
0.276
0.871
What
0.007
is
0.205
on
0.377
the
0.865
table
0.289
?
0.0
[SEP]
0.382 / 2
When I
0.416 / 2
got home
-0.515 / 4
today I saw my
-2.21 / 2
cat on
-1.431 / 2
the table
-0.377
,
-0.339
and
-0.343 / 2
my frog
0.29 / 3
on the floor
0.298
.
0.0
inputs
0.223
0.6
What
0.147
is
0.272
on
0.364
the
0.448
table
0.257
?
0.0
[SEP]
0.348 / 2
When I
0.385 / 2
got home
-0.035 / 4
today I saw my
-1.634 / 2
cat on
-2.821 / 2
the table
-0.277
,
-0.382
and
-0.369 / 2
my frog
0.33 / 3
on the floor
0.324
.
0.0
inputs
0.223
0.6
What
0.147
is
0.272
on
0.364
the
0.448
table
0.257
?
0.0
[SEP]
0.348 / 2
When I
0.385 / 2
got home
-0.035 / 4
today I saw my
-1.634 / 2
cat on
-2.821 / 2
the table
-0.277
,
-0.382
and
-0.369 / 2
my frog
0.33 / 3
on the floor
0.324
.
0.0
inputs
0.241
0.671
What
0.216
is
0.353
on
0.403
the
0.222
table
0.013
?
0.0
[SEP]
0.286 / 2
When I
0.319 / 2
got home
0.282 / 4
today I saw my
-0.558 / 2
cat on
-0.025 / 2
the table
1.914
,
-0.52
and
-0.487 / 2
my frog
0.102 / 3
on the floor
0.14
.
0.0
inputs
0.241
0.671
What
0.216
is
0.353
on
0.403
the
0.222
table
0.013
?
0.0
[SEP]
0.286 / 2
When I
0.319 / 2
got home
0.282 / 4
today I saw my
-0.558 / 2
cat on
-0.025 / 2
the table
1.914
,
-0.52
and
-0.487 / 2
my frog
0.102 / 3
on the floor
0.14
.
0.0
inputs
0.268
0.804
What
0.152
is
0.265
on
0.349
the
0.311
table
0.203
?
0.0
[SEP]
0.326 / 2
When I
0.373 / 2
got home
0.264 / 4
today I saw my
-0.667 / 2
cat on
-0.695 / 2
the table
-0.718
,
0.59
and
0.522 / 2
my frog
0.118 / 3
on the floor
0.216
.
0.0
inputs
0.268
0.804
What
0.152
is
0.265
on
0.349
the
0.311
table
0.203
?
0.0
[SEP]
0.326 / 2
When I
0.373 / 2
got home
0.264 / 4
today I saw my
-0.667 / 2
cat on
-0.695 / 2
the table
-0.718
,
0.59
and
0.522 / 2
my frog
0.118 / 3
on the floor
0.216
.
0.0
inputs
0.249
0.736
What
0.173
is
0.193
on
0.226
the
0.062
table
0.306
?
0.0
[SEP]
0.427 / 2
When I
0.475 / 2
got home
0.683 / 4
today I saw my
-0.62 / 2
cat on
-0.146 / 2
the table
-1.279
,
-2.106
and
-2.076 / 2
my frog
0.004 / 3
on the floor
0.09
.
0.0
inputs
0.249
0.736
What
0.173
is
0.193
on
0.226
the
0.062
table
0.306
?
0.0
[SEP]
0.427 / 2
When I
0.475 / 2
got home
0.683 / 4
today I saw my
-0.62 / 2
cat on
-0.146 / 2
the table
-1.279
,
-2.106
and
-2.076 / 2
my frog
0.004 / 3
on the floor
0.09
.
0.0
inputs
0.251
0.759
What
-0.092
is
-0.066
on
0.011
the
-0.234
table
0.694
?
0.0
[SEP]
0.414 / 2
When I
0.467 / 2
got home
0.47 / 4
today I saw my
-0.35 / 2
cat on
-0.142 / 2
the table
-0.569
,
-1.265
and
-1.363 / 2
my frog
0.233 / 3
on the floor
0.336
.
0.0
inputs
0.251
0.759
What
-0.092
is
-0.066
on
0.011
the
-0.234
table
0.694
?
0.0
[SEP]
0.414 / 2
When I
0.467 / 2
got home
0.47 / 4
today I saw my
-0.35 / 2
cat on
-0.142 / 2
the table
-0.569
,
-1.265
and
-1.363 / 2
my frog
0.233 / 3
on the floor
0.336
.
0.0
inputs
0.239
0.875
What
-0.024
is
0.115
on
0.038
the
-0.602
table
0.741
?
0.0
[SEP]
0.537 / 2
When I
0.603 / 2
got home
0.626 / 4
today I saw my
-0.187 / 2
cat on
-0.23 / 2
the table
0.027
,
1.01
and
1.028 / 2
my frog
1.128 / 3
on the floor
1.129
.
0.0
inputs
0.239
0.875
What
-0.024
is
0.115
on
0.038
the
-0.602
table
0.741
?
0.0
[SEP]
0.537 / 2
When I
0.603 / 2
got home
0.626 / 4
today I saw my
-0.187 / 2
cat on
-0.23 / 2
the table
0.027
,
1.01
and
1.028 / 2
my frog
1.128 / 3
on the floor
1.129
.
0.0
inputs
0.217
0.801
What
0.149
is
0.16
on
0.126
the
-0.236
table
0.44
?
0.0
[SEP]
0.475 / 2
When I
0.543 / 2
got home
0.757 / 4
today I saw my
-0.381 / 2
cat on
-0.018 / 2
the table
0.012
,
-0.116
and
-0.129 / 2
my frog
-2.53 / 3
on the floor
-1.769
.
0.0
inputs
0.217
0.801
What
0.149
is
0.16
on
0.126
the
-0.236
table
0.44
?
0.0
[SEP]
0.475 / 2
When I
0.543 / 2
got home
0.757 / 4
today I saw my
-0.381 / 2
cat on
-0.018 / 2
the table
0.012
,
-0.116
and
-0.129 / 2
my frog
-2.53 / 3
on the floor
-1.769
.
0.0
inputs
0.195
0.602
What
0.243
is
0.201
on
0.093
the
-0.286
table
0.387
?
0.0
[SEP]
0.369 / 2
When I
0.433 / 2
got home
0.675 / 4
today I saw my
-0.189 / 2
cat on
0.104 / 2
the table
-0.089
,
-0.002
and
-0.006 / 2
my frog
-3.018 / 3
on the floor
-2.132
.
0.0
inputs
0.195
0.602
What
0.243
is
0.201
on
0.093
the
-0.286
table
0.387
?
0.0
[SEP]
0.369 / 2
When I
0.433 / 2
got home
0.675 / 4
today I saw my
-0.189 / 2
cat on
0.104 / 2
the table
-0.089
,
-0.002
and
-0.006 / 2
my frog
-3.018 / 3
on the floor
-2.132
.
0.0
inputs
0.204
0.816
What
0.485
is
0.249
on
0.133
the
-0.374
table
0.357
?
0.0
[SEP]
0.462 / 2
When I
0.537 / 2
got home
0.866 / 4
today I saw my
-0.276 / 2
cat on
0.147 / 2
the table
-0.24
,
0.027
and
-0.0 / 2
my frog
-0.036 / 3
on the floor
0.379
.
0.0
inputs
0.204
0.816
What
0.485
is
0.249
on
0.133
the
-0.374
table
0.357
?
0.0
[SEP]
0.462 / 2
When I
0.537 / 2
got home
0.866 / 4
today I saw my
-0.276 / 2
cat on
0.147 / 2
the table
-0.24
,
0.027
and
-0.0 / 2
my frog
-0.036 / 3
on the floor
0.379
.
0.0
inputs
0.295
0.943
What
0.027
is
-0.019
on
-0.004
the
-0.758
table
0.006
?
0.0
[SEP]
0.256 / 2
When I
0.302 / 2
got home
0.4 / 4
today I saw my
-0.436 / 2
cat on
0.083 / 2
the table
-0.444
,
-0.284
and
-0.305 / 2
my frog
0.898 / 3
on the floor
1.874
.
0.0
inputs
0.295
0.943
What
0.027
is
-0.019
on
-0.004
the
-0.758
table
0.006
?
0.0
[SEP]
0.256 / 2
When I
0.302 / 2
got home
0.4 / 4
today I saw my
-0.436 / 2
cat on
0.083 / 2
the table
-0.444
,
-0.284
and
-0.305 / 2
my frog
0.898 / 3
on the floor
1.874
.
0.0
inputs
0.322
0.95
What
0.246
is
-0.095
on
0.389
the
-0.156
table
-0.878
?
0.0
[SEP]
0.198 / 2
When I
0.162 / 2
got home
-0.235 / 4
today I saw my
-0.451 / 2
cat on
0.213 / 2
the table
-0.12
,
-0.368
and
-0.38 / 2
my frog
0.013 / 3
on the floor
0.112
.
0.0
inputs
0.322
0.95
What
0.246
is
-0.095
on
0.389
the
-0.156
table
-0.878
?
0.0
[SEP]
0.198 / 2
When I
0.162 / 2
got home
-0.235 / 4
today I saw my
-0.451 / 2
cat on
0.213 / 2
the table
-0.12
,
-0.368
and
-0.38 / 2
my frog
0.013 / 3
on the floor
0.112
.
0.0
解释一个匹配函数
在上面的例子中,我们直接解释了来自模型的输出logits。这要求我们确保只以保持长度的方法扰动输入,以免改变输出logits的含义。一个不那么详细但更灵活的方法是,只需评分模型是否产生了特定的答案。
[4]:
def make_answer_scorer(answers):
def f(questions):
out = []
for q in questions:
question, context = q.split("[SEP]")
results = pmodel(question, context, topk=20)
values = []
for answer in answers:
value = 0
for result in results:
if result["answer"] == answer:
value = result["score"]
break
values.append(value)
out.append(values)
return out
f.output_names = answers
return f
f_answers = make_answer_scorer(["my cat", "cat", "my frog"])
explainer_answers = shap.Explainer(f_answers, pmodel.tokenizer)
shap_values_answers = explainer_answers(data)
shap.plots.text(shap_values_answers)
[0]
outputs
my cat
cat
my frog
inputs
0.001
0.056
What
-0.013
is
0.002
on
0.049
the
0.14
table
0.013
?
0.0
[SEP]
0.013 / 4
When I got home
0.008 / 2
today I
0.015
saw
0.097
my
0.042
cat
0.026
on
0.013
the
0.049
table
0.003
,
-0.008
and
-0.042 / 2
my frog
0.034 / 3
on the floor
0.0
.
0.0
inputs
0.001
0.056
What
-0.013
is
0.002
on
0.049
the
0.14
table
0.013
?
0.0
[SEP]
0.013 / 4
When I got home
0.008 / 2
today I
0.015
saw
0.097
my
0.042
cat
0.026
on
0.013
the
0.049
table
0.003
,
-0.008
and
-0.042 / 2
my frog
0.034 / 3
on the floor
0.0
.
0.0
inputs
0.0
-0.055
What
-0.041
is
0.053
on
0.063
the
0.111
table
0.042
?
0.0
[SEP]
-0.008 / 2
When I
-0.023 / 2
got home
0.045 / 2
today I
-0.011
saw
0.019
my
0.043
cat
0.041
on
0.027
the
0.048
table
0.018
,
-0.008
and
-0.036 / 2
my frog
0.026 / 3
on the floor
-0.005
.
0.0
inputs
0.0
-0.055
What
-0.041
is
0.053
on
0.063
the
0.111
table
0.042
?
0.0
[SEP]
-0.008 / 2
When I
-0.023 / 2
got home
0.045 / 2
today I
-0.011
saw
0.019
my
0.043
cat
0.041
on
0.027
the
0.048
table
0.018
,
-0.008
and
-0.036 / 2
my frog
0.026 / 3
on the floor
-0.005
.
0.0
inputs
0.004
0.004
What
-0.016
is
-0.026
on
-0.02
the
-0.081
table
0.011
?
0.0
[SEP]
0.002 / 4
When I got home
-0.002 / 2
today I
-0.0
saw
-0.003
my
0.003
cat
0.007
on
-0.005
the
-0.035
table
0.018
,
0.036
and
0.048 / 2
my frog
0.031 / 3
on the floor
0.021
.
0.006
inputs
0.004
0.004
What
-0.016
is
-0.026
on
-0.02
the
-0.081
table
0.011
?
0.0
[SEP]
0.002 / 4
When I got home
-0.002 / 2
today I
-0.0
saw
-0.003
my
0.003
cat
0.007
on
-0.005
the
-0.035
table
0.018
,
0.036
and
0.048 / 2
my frog
0.031 / 3
on the floor
0.021
.
0.006
有更多有用示例的想法吗?我们鼓励提交增加此文档笔记本的拉取请求!