Skip to content

Get activations of a specific layer of the multifit model #72

@francis967

Description

@francis967

Hello everybody,
Anyone knows how to get the activations of an intermediate layer when I make a prediction, despite what I have tried so far, it gives me errors.To give you a little context:

The first thing I do is extract the model layer(for example the first embeddings layer):
self.specific_layer = list(self.classifier.model.modules())[0][0].module.encoder

The second thing I do is put a hook on the layer I want to get the activations from :
def hook_function(module, grad_in, grad_out): self.gradients = grad_out[0]
self.specific_layer.register_backward_hook(hook_function)

Then I vectorize the text input using SentencePiece and give it as input to the model like this, similar to how I've seen it done in other fastai models:
model_output = self.classifier.model(self.inputs)

But when i try to run the above code line it gives me this error:
File "/home/francis/.virtualenvs/my_project/lib/python3.7/site-packages/fastai/text/learner.py", line 261, in forward bs,sl = input.size() AttributeError: 'list' object has no attribute 'size'
Does anyone know what the problem might be?, or if there is a better way to get the activations of an intermediate layer in a multifit model.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions