public class LIMEText extends LIMEBase implements TextExplainer<Regressor>
TextFeatureExtractor
to explain the prediction for a given piece of text.
LIME uses a naive sampling procedure which blanks out words and trains the linear model on a set of binary features, each of which is the presence of a word+position combination. Words are not permuted, and new words are not added (so it's only explaining when the absence of a word would change the prediction).
See:
Ribeiro MT, Singh S, Guestrin C. "Why should I trust you?: Explaining the predictions of any classifier" Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining 2016.
DISTANCE_DELTA, evaluator, explanationTrainer, innerModel, kernelWidth, numSamples, numTrainingExamples, regressionFactory, rng, WIDTH_CONSTANT
Constructor and Description |
---|
LIMEText(SplittableRandom rng,
Model<Label> innerModel,
SparseTrainer<Regressor> explanationTrainer,
int numSamples,
TextFeatureExtractor<Label> extractor,
Tokenizer tokenizer)
Constructs a LIME explainer for a model which uses text data.
|
Modifier and Type | Method and Description |
---|---|
LIMEExplanation |
explain(String inputText)
|
protected String |
nameFeature(String name,
int idx)
Generate the feature name by combining the word and index.
|
protected List<Example<Regressor>> |
sampleData(String inputText,
List<Token> tokens)
Samples a new dataset from the input text.
|
explain, explainWithSamples, kernelDist, measureDistance, samplePoint, trainExplainer, transformOutput
public LIMEText(SplittableRandom rng, Model<Label> innerModel, SparseTrainer<Regressor> explanationTrainer, int numSamples, TextFeatureExtractor<Label> extractor, Tokenizer tokenizer)
rng
- The rng to use for sampling.innerModel
- The model to explain.explanationTrainer
- The sparse trainer to use to generate explanations.numSamples
- The number of samples to generate for each explanation.extractor
- The TextFeatureExtractor
used to generate text features from a string.tokenizer
- The tokenizer used to tokenize the examples.public LIMEExplanation explain(String inputText)
TextExplainer
Example
, and
generates an explanation of the contained Model
's prediction.explain
in interface TextExplainer<Regressor>
inputText
- The text to explain.protected String nameFeature(String name, int idx)
name
- The word.idx
- The index.protected List<Example<Regressor>> sampleData(String inputText, List<Token> tokens)
inputText
- The input text.tokens
- The tokenized representation of the input text.Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.