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

Extracting embeddings from layers #621

Closed
anjishnu opened this issue Sep 1, 2015 · 3 comments
Closed

Extracting embeddings from layers #621

anjishnu opened this issue Sep 1, 2015 · 3 comments

Comments

@anjishnu
Copy link
Contributor

anjishnu commented Sep 1, 2015

Embeddings obtained from training a discriminative NN towards a specific task can be extremely useful on related tasks (e.g. Transfer learning). We can extract a lot of potentially useful embeddings by looking at the weights of a layer of the model. By looking at the documentation http://keras.io/models/ it doesn't seem like Keras supports the abstraction of extracting weight values from individual layers. Seems like it would be relatively easy to implement.

@Smerity
Copy link
Contributor

Smerity commented Sep 1, 2015

From the skipgram word embeddings example:

# recover the embedding weights trained with skipgram:
weights = model.layers[0].get_weights()[0]

If instead you're looking to extract the hidden layer representation of a given input, refer to #41

@alyato
Copy link

alyato commented Nov 2, 2016

hi @Smerity ,i use the graph model,refer to #41
like this,

model = graph()
model.add_input(name='input0',input_shape=())
model.add_node(Convolution2D(),name='c1',input='input0')
.......

And i want to see the output of the c1,Then

getFeatureMap = theano.function(model.inputs['input0'].input,model.nodes['c1'].get_output(train=False),
allow_input_downcast=True)

But it show me that
TypeError: list indices must be integers, not str

Do you give me some advices? Thanks.

@philipperemy
Copy link

philipperemy commented May 17, 2017

More generally you can visualise the output/activations of every layer of your model. I wrote an example with MNIST to show how here:

https://github.com/philipperemy/keras-visualize-activations

So far it's the least painful I've seen.

fchollet pushed a commit that referenced this issue Sep 22, 2023
* original file from keras-io

* port to keras core

* chore: lint

* move string lookup to preprocessing - lint - test all backends

* Final code:
hubingallin pushed a commit to hubingallin/keras that referenced this issue Sep 22, 2023
* original file from keras-io

* port to keras core

* chore: lint

* move string lookup to preprocessing - lint - test all backends

* Final code:
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

No branches or pull requests

5 participants