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","."]
docstr: :param vocab:
      Vocabulary of the tokenizer
  :param word_weights:
      Mapping of tokens to a float weight value. Words embeddings are multiplied by  this float value. Tokens in word_weights must not be equal to the vocab (can contain more or less values)
  :param unknown_word_weight:
      Weight for words in vocab, that do not appear in the word_weights lookup. These can be for example rare words in the vocab, where no weight exists.
docstr_tok: [":","param","vocab",":","Vocabulary","of","the","tokenizer",":","param","word_weights",":","Mapping","of","tokens","to","a","float","weight","value",".","Words","embeddings","are","multiplied","by","this","float","value",".","Tokens","in","word_weights","must","not","be","equal","to","the","vocab","(","can","contain","more","or","less","values",")",":","param","unknown_word_weight",":","Weight","for","words","in","vocab",",","that","do","not","appear","in","the","word_weights","lookup",".","These","can","be","for","example","rare","words","in","the","vocab",",","where","no","weight","exists","."]
code: def __init__(
      self,
      vocab: List[str],
      word_weights: Dict[str, float],
      unknown_word_weight: float = 1,
  ):
      """
  
      :param vocab:
          Vocabulary of the tokenizer
      :param word_weights:
          Mapping of tokens to a float weight value. Words embeddings are multiplied by  this float value. Tokens in word_weights must not be equal to the vocab (can contain more or less values)
      :param unknown_word_weight:
          Weight for words in vocab, that do not appear in the word_weights lookup. These can be for example rare words in the vocab, where no weight exists.
      """
      super(WordWeights, self).__init__()
      self.config_keys = [
          "vocab",
          "word_weights",
          "unknown_word_weight",
      ]
      self.vocab = vocab
      self.word_weights = word_weights
      self.unknown_word_weight = unknown_word_weight
  
      weights = []
      num_unknown_words = 0
      for word in vocab:
          weight = unknown_word_weight
          if word in word_weights:
              weight = word_weights[word]
          elif word.lower() in word_weights:
              weight = word_weights[word.lower()]
          else:
              num_unknown_words += 1
          weights.append(weight)
  
      logger.info(
          "{} of {} words without a weighting value. Set weight to {}".format(
              num_unknown_words, len(vocab), unknown_word_weight
          )
      )
  
      self.emb_layer = nn.Embedding(len(vocab), 1)
      self.emb_layer.load_state_dict(
          {"weight": torch.FloatTensor(weights).unsqueeze(1)}
      )
  
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 1 to create a new WordWeights object from inherited base classes: nn with example: obj = WordWeights(vocab, word_weights, unknown_word_weight)