class_docstr: Token embeddings are weighted mean of their different hidden layer representations
class_docstr_tok: ["Token","embeddings","are","weighted","mean","of","their","different","hidden","layer","representations"]
code: def forward(self, features: Dict[str, Tensor]):
      ft_all_layers = features["all_layer_embeddings"]
  
      all_layer_embedding = torch.stack(ft_all_layers)
      all_layer_embedding = all_layer_embedding[
          self.layer_start :, :, :, :
      ]  # Start from 4th layers output
  
      weight_factor = (
          self.layer_weights.unsqueeze(-1)
          .unsqueeze(-1)
          .unsqueeze(-1)
          .expand(all_layer_embedding.size())
      )
      weighted_average = (weight_factor * all_layer_embedding).sum(
          dim=0
      ) / self.layer_weights.sum()
  
      features.update({"token_embeddings": weighted_average})
      return features
  
file_path: sentence-transformers/sentence_transformers/models/WeightedLayerPooling.py
imports: import torch
  from torch import Tensor
  from torch import nn
  from typing import Dict
  import os
  import json
label_desc: Use image node_id 2 for calling the WeightedLayerPooling obj's underlying member method code with example usage: obj.forward(features) and returns: features