class_docstr: Implements a Bag-of-Words (BoW) model to derive sentence embeddings.
  
  A weighting can be added to allow the generation of tf-idf vectors. The output vector has the size of the vocab.
class_docstr_tok: ["Implements","a","Bag-of-Words","(","BoW",")","model","to","derive","sentence","embeddings",".","A","weighting","can","be","added","to","allow","the","generation","of","tf-idf","vectors",".","The","output","vector","has","the","size","of","the","vocab","."]
code: def __init__(
      self,
      vocab: List[str],
      word_weights: Dict[str, float] = {},
      unknown_word_weight: float = 1,
      cumulative_term_frequency: bool = True,
  ):
      super(BoW, self).__init__()
      vocab = list(set(vocab))  # Ensure vocab is unique
      self.config_keys = [
          "vocab",
          "word_weights",
          "unknown_word_weight",
          "cumulative_term_frequency",
      ]
      self.vocab = vocab
      self.word_weights = word_weights
      self.unknown_word_weight = unknown_word_weight
      self.cumulative_term_frequency = cumulative_term_frequency
  
      # Maps wordIdx -> word weight
      self.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
          self.weights.append(weight)
  
      logger.info(
          "{} out of {} words without a weighting value. Set weight to {}".format(
              num_unknown_words, len(vocab), unknown_word_weight
          )
      )
  
      self.tokenizer = WhitespaceTokenizer(
          vocab, stop_words=set(), do_lower_case=False
      )
      self.sentence_embedding_dimension = len(vocab)
  
file_path: sentence-transformers/sentence_transformers/models/BoW.py
imports: import torch
  from torch import Tensor
  from torch import nn
  from typing import List, Dict
  import os
  import json
  import logging
  import numpy
  from .tokenizer import WhitespaceTokenizer
label_desc: Use image node_id 1 to create a new BoW object from inherited base classes: nn with example: obj = BoW(vocab, word_weights, unknown_word_weight, cumulative_term_frequency)