class_docstr: This model can weight word embeddings, for example, with idf-values.
class_docstr_tok: ["This","model","can","weight","word","embeddings",",","for","example",",","with","idf-values","."]
code: def forward(self, features: Dict[str, Tensor]):
      attention_mask = features["attention_mask"]
      token_embeddings = features["token_embeddings"]
  
      # Compute a weight value for each token
      token_weights_raw = self.emb_layer(features["input_ids"]).squeeze(
          -1
      )
      token_weights = token_weights_raw * attention_mask.float()
      token_weights_sum = torch.sum(token_weights, 1)
  
      # Multiply embedding by token weight value
      token_weights_expanded = token_weights.unsqueeze(-1).expand(
          token_embeddings.size()
      )
      token_embeddings = token_embeddings * token_weights_expanded
  
      features.update(
          {
              "token_embeddings": token_embeddings,
              "token_weights_sum": token_weights_sum,
          }
      )
      return features
  
file_path: sentence-transformers/sentence_transformers/models/WordWeights.py
imports: import torch
  from torch import Tensor
  from torch import nn
  from typing import List, Dict
  import os
  import json
  import logging
label_desc: Use image node_id 2 for calling the WordWeights obj's underlying member method code with example usage: obj.forward(features) and returns: features