Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added kwargs tests and code to raise warning for extra kwarg #693

Merged
merged 11 commits into from
Jan 24, 2024

Conversation

cpranav93
Copy link
Contributor

No description provided.

@cpranav93
Copy link
Contributor Author

#693 resolves this issue. It is still in a draft stage but the idea is as follows:

  • From the list of kwargs passed to the init call, progressively remove kwargs that are being used by: the init function for the explainer, and then the explain function.
  • If any kwargs are leftover, these are assumed to be extra and a warning is currently raised to let the user know that extra kwargs are being passed.

Whether a warning or an error should be passed is to be decided based on whether additional kwargs get passed out of DIANNA to external functions like lime/shap.

@cpranav93
Copy link
Contributor Author

Update:
extra kwargs not accepted by the function are not passed to the function. Therefore we could opt to raise an error if we choose.

I have now implemented the warnings for each method type and written tests for the same (except tests for tabular). This PR is ready for review

@cpranav93 cpranav93 marked this pull request as ready for review January 22, 2024 13:33
Copy link
Contributor

@SarahAlidoost SarahAlidoost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpranav93 thanks for the fixes. The implementation works fine. However, I found that there is a function get_kwargs_applicable_to_function. I think the warning should be implemented in this function in misc script rather than individual warnings in each method in init script. Here is a suggestion for that function:

function_kwargs = {
        key: value
        for key, value in kwargs.items()
        if key in inspect.getfullargspec(function).args
    }

    # check if function is a bound method
    if hasattr(function, '__self__'):
        not_applicable = kwargs.copy()
        for key in function_kwargs:
            not_applicable.pop(key)
        if not_applicable:
            msg = f'Please note the following kwargs are not being used: {not_applicable}'
            warnings.warn(msg)

The test_kwargs that you implemented still works with this suggestion. I might miss some points regarding the development. If so, please let me know 😊

@cpranav93
Copy link
Contributor Author

cpranav93 commented Jan 24, 2024

@SarahAlidoost, thanks for the review. Regarding your last point, the issue is that the kwargs are being used by two different functions so the warning should only be raised after the second function's kwargs are also popped. If implemented in the "get_kwargs_applicable_to_function" function, then it would check it after every function and not after both have been called.

Alternatively, we could pop the kwargs and return the reduced list from the misc function and only raise the warning in the individual methods. Does that sound like a better alternative? I am open to suggestions.

Copy link
Contributor

@SarahAlidoost SarahAlidoost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpranav93 thanks for addressing the comments and explanations. I see the point regarding kwargs. Considering the current implementations of the modules, I agree that your fixes work fine. I approved this PR.

@cpranav93 cpranav93 merged commit dbf1e93 into main Jan 24, 2024
17 checks passed
@cpranav93 cpranav93 deleted the kwargs-tests branch January 24, 2024 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants