# Extract feature vector/latent factors from Embedding layer in Pytorch

**URL:** <https://discuss.pytorch.org/t/extract-feature-vector-latent-factors-from-embedding-layer-in-pytorch/94712>\
**Category:** Uncategorized\
**Created:** [August 31, 2020, 3:07pm UTC](https://discuss.pytorch.org/t/extract-feature-vector-latent-factors-from-embedding-layer-in-pytorch/94712 "2020-08-31T15:07:44Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [September 1, 2020, 8:10am UTC](https://discuss.pytorch.org/t/extract-feature-vector-latent-factors-from-embedding-layer-in-pytorch/94712/2 "2020-09-01T08:10:41Z")

</div>

Some partial answers:

1. Depending what you mean by “feature vectors”, you might either access the `.weight` attribute or use forward hooks to get the activation output of this layer as described [here](https://discuss.pytorch.org/t/how-can-l-load-my-best-model-as-a-feature-extractor-evaluator/17254/6).

2. Yes, you could store the features and train another model with it. Based on this use case, you would refer to the output activations as features. Otherwise, if you are referring to the `.weight` parameter, you would only have a single sample and training wouldn’t make sense.

3. The embeddings would be trained as part of the complete model for your current use case, e.g. a classification. I’m not sure how you would like to train only the embeddings.

4. I don’t know what the best approach would be for missing tokens.

---

_[View the full topic](https://discuss.pytorch.org/t/extract-feature-vector-latent-factors-from-embedding-layer-in-pytorch/94712)._
