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

Does neural-tangents work for custom layer? #165

Open
Shuhul24 opened this issue Sep 3, 2022 · 1 comment
Open

Does neural-tangents work for custom layer? #165

Shuhul24 opened this issue Sep 3, 2022 · 1 comment
Labels
question Further information is requested

Comments

@Shuhul24
Copy link

Shuhul24 commented Sep 3, 2022

I have built a custom layer (KerasLayer) using class in python (say class NewLayer). Can I use something like stax.NewLayer for manipulating neural-tangents on this custom layer?

@romanngg
Copy link
Contributor

romanngg commented Sep 4, 2022

I'm afraid not, you would need to write your own stax layer, defining init_fn, apply_fn, and kernel_fn, e.g. as

To what extent you'll be able to reuse your existing code will depend on the specifics.

We have tools allowing to implement some layers easier than from scratch, such as pointwise nonlinearities https://neural-tangents.readthedocs.io/en/latest/_autosummary/neural_tangents.stax.Elementwise.html. If your layer is an affine non-parametric transformation (similar to https://neural-tangents.readthedocs.io/en/latest/stax.html#linear-nonparametric), it is also easy to automatically translate in into a stax layer (something I just didn't get to doing yet). In general, if you could tell us what your layer does, we may be able to help implementing it.

Finally, note that empirical kernels (https://neural-tangents.readthedocs.io/en/latest/empirical.html) work with any JAX functions, and don't require them to be written in stax.

@romanngg romanngg added the question Further information is requested label Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants