You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We could consider using a RandomGenerator object to pass around in our code. See this blog about the motivation. ChatGPT summary: Using a RandomGenerator object avoids the pitfalls of global state and enhances reproducibility, flexibility, and compatibility with modern NumPy features.
I tried this but it will be quite a lot of places where we'd have to change code. Could be worth it. Example:
def explain(
self,
model_or_function: Union[str, callable],
input_tabular: np.array,
labels: Optional[Iterable[int]] = None,
mask_type: Optional[Union[str, callable]] = 'most_frequent',
batch_size: Optional[int] = 100,
rng: Optional[np.random.Generator] = None, # ADD THIS LINE -------------------
) -> np.array:
"""Run the RISE explainer.
Args:
model_or_function: The function that runs the model to be explained
or the path to a ONNX model on disk.
input_tabular: Data to be explained.
labels: Indices of classes to be explained.
mask_type: Imputation strategy for masked features
batch_size: Number of samples to process by the model per batch
rng: random number generator # ADD THIS LINE -------------------
Returns:
explanation: An Explanation object containing the LIME explanations for each class.
"""
rng = np.random.default_rng(rng) # ADD THIS LINE -------------------
# run the explanation.
runner = utils.get_function(model_or_function)
masks = np.stack(
list(
generate_tabular_masks(input_tabular.shape,
number_of_masks=self.n_masks, p_keep=self.p_keep,
rng=rng))) # PASS RNG ON ------------------
self.masks = masks if self.keep_masks else None
masked = mask_data_tabular(input_tabular,
The text was updated successfully, but these errors were encountered:
We could consider using a RandomGenerator object to pass around in our code. See this blog about the motivation. ChatGPT summary: Using a RandomGenerator object avoids the pitfalls of global state and enhances reproducibility, flexibility, and compatibility with modern NumPy features.
I tried this but it will be quite a lot of places where we'd have to change code. Could be worth it. Example:
The text was updated successfully, but these errors were encountered: