Hi,
After update of R (3.5-mac)+ update of packages, I get an error from the following
**# Run explain() on explainer
explanation <- lime::explain(
x_test_tbl[1:10, ],
explainer = explainer,
n_labels = 1,
n_features = 4,
kernel_width = 0.5
)
Error in py_call_impl(callable, dots$args, dots$keywords) :
ValueError: No data provided for "dense_1_input". Need data for each key in: ['dense_1_input']
Detailed traceback:
File "/Users/turgut_a/.virtualenvs/r-reticulate/lib/python2.7/site-packages/keras/engine/training.py", line 1152, in predict
x, _, _ = self._standardize_user_data(x)
File "/Users/turgut_a/.virtualenvs/r-reticulate/lib/python2.7/site-packages/keras/engine/training.py", line 754, in _standardize_user_data
exception_prefix='input')
File "/Users/turgut_a/.virtualenvs/r-reticulate/lib/python2.7/site-packages/keras/engine/training_utils.py", line 76, in standardize_input_data
'for each key in: ' + str(names))
the code was taken from here
In fact, in previous version of R, everything was working perfectly and there was no any error.
There was a change in S3 dispatching in R 3.5 which I suspect as the culprit (as lime makes use of S3 for binding to models). @thomasp85 what do you think?
The new dispatching has wrecked havoc enough places that I might just expect it to be the culprit... sigh — I better upgrade R now so I can fix it...
Does the problem persist if you explicitly load reticulate?
@jjallaire it definitely looked like a dispatch problem, but was in fact that for some reason keras under R v3.5 doesn't accept data.frame data as x in predict() (In fact I think that is the correct behaviour - don't know why it worked in the previous versions of R)
I've updated lime to reflect this and it should work now with an installation from GitHub
Weird about the dispatch behavior. Very glad we got to the bottom of it!
After update of R (3.5.1 on Mac OS) it gives a new type of error. @jjallaire @thomasp85
Error in py_get_attr_impl(x, name, silent) :
AttributeError: 'Dropout' object has no attribute 'activation'
That looks like you are running a much older version of the core Keras library. What is the output of keras:::keras_version()
keras:::keras_version()
Using TensorFlow backend.
[1] ‘2.2.2’
I'm not sure what is happening then as this is one of the most most elementary things in the Keras library (all of our tests would fail if this didn't actually work).
I was having the same error on Win 10 Pro 64bit, MRO 3.5.0, keras 2.2.2 and tensorflow 1.9
It seems the class names have changed since the article was written -- class(model_keras) returns different values on my machine compared to what's on the web page.
If the method function names are modified accordingly, the code works on my machine (the dropout error goes away).
Output of class(model_keras) in the article:
## [1] "keras.models.Sequential"
## [2] "keras.engine.training.Model"
## [3] "keras.engine.topology.Container"
## [4] "keras.engine.topology.Layer"
## [5] "python.builtin.object"
On my machine I get:
[1] "keras.engine.sequential.Sequential" "keras.engine.training.Model" "keras.engine.network.Network" "keras.engine.base_layer.Layer"
[5] "python.builtin.object"
So the next two chunks should be:
```
model_type.keras.engine.sequential.Sequential <- function(x, ...) {
return("classification")
}
predict_model.keras.engine.sequential.Sequential <- function(x, newdata, type, ...) {
pred <- predict_proba(object = x, x = as.matrix(newdata))
return(data.frame(Yes = pred, No = 1 - pred))
}
````
Hope this helps.
hi there,
i'm having a similar problem with a multinomial text classifier, taking 1000 inputs in [0:10000] and with 11 outcome classes.
I've set up lime as shown with:
# set up lime::model_type() for keras:
model_type.keras.engine.sequential.Sequential <- function(x, ...) {
"classification"
}
# set up lime::predict_model() for keras:
predict_model.keras.engine.sequential.Sequential <- function (x, newdata, type, ...) {
class <- predict_classes (object = x, x = as.matrix(newdata))
data.frame(class = class)
}
# test to check it's working fine:
predict_model (x = my_model_mm1,
newdata = temp_test,
type = 'raw') %>%
tibble::as_tibble()
# the predict_model output looks as expected: a vector of the predicted classes.
# Run lime() on training set
explainer <- lime::lime(
x = temp_train,
model = my_model_mm1,
bin_continuous = FALSE)
# Run explain() on explainer
explanation <- lime::explain(
temp_test[1,],
explainer = explainer,
n_labels = 11,
n_features = 10,
kernel_width = 0.5)
This throws an error:
Error in py_call_impl(callable, dots$args, dots$keywords) : InvalidArgumentError: indices[31,1] = -61 is not in [0, 10000) [[{{node embedding_89/embedding_lookup}} = ResourceGather[Tindices=DT_INT32, dtype=DT_FLOAT, validate_indices=true, _device="/job:localhost/replica:0/task:0/device:CPU:0"](embedding_89/embeddings, embedding_89/Cast)]]
note that the indices and associated negative values change with each run and i definitely have all my inputs in range: both temp_train and temp_test are dataframes with 1000 columns and all values between 0 and 10000.
any idea what the problem might be...?
@ChristelSwift hi. This was difficult due to embedding layers in keras.
maybe this will help #552
@henry090 from the error text i thought it was pointing to some issue with my test dataset, but are you suggesting the error is in my explainer definition instead? Do you know where i could find an example of lime used for a text classification set up like this one: https://keras.rstudio.com/articles/tutorial_basic_text_classification.html ?
Do you know where i could find an example of lime used for a text classification set up like this one: https://keras.rstudio.com/articles/tutorial_basic_text_classification.html ?
It does not exist. But @ thomasp85 explained text class-n with xgboost library.
are you suggesting the error is in my explainer definition instead?
You should write a preprocess function within lime. https://cran.r-project.org/web/packages/lime/vignettes/Understanding_lime.html
# Example
get_matrix <- function(text) {
it <- itoken(text, progressbar = FALSE)
create_dtm(it, vectorizer = hash_vectorizer())
}
explainer <- lime(sentence_to_explain, model = xgb_model,
preprocess = get_matrix)
@ChristelSwift #744
i am getting this error even when im running it on google cloud compute virtual machine engine. does this impact the performance and weights assigned in my model as the model still runs but gives extemely poor results . Also , in order to address class imbalance in my keras ANN model in introduced the class_weights option is there any other way to handle that situation ?
Most helpful comment
I was having the same error on Win 10 Pro 64bit, MRO 3.5.0, keras 2.2.2 and tensorflow 1.9
It seems the class names have changed since the article was written --
class(model_keras)returns different values on my machine compared to what's on the web page.If the method function names are modified accordingly, the code works on my machine (the dropout error goes away).
Output of
class(model_keras)in the article:On my machine I get:
So the next two chunks should be:
```
Setup lime::model_type() function for keras
model_type.keras.engine.sequential.Sequential <- function(x, ...) {
return("classification")
}
Setup lime::predict_model() function for keras
predict_model.keras.engine.sequential.Sequential <- function(x, newdata, type, ...) {
pred <- predict_proba(object = x, x = as.matrix(newdata))
return(data.frame(Yes = pred, No = 1 - pred))
}
````
Hope this helps.