class_docstr: Loads or creates a SentenceTransformer model that can be used to map sentences / text to embeddings.
  
  :param model_name_or_path: If it is a filepath on disc, it loads the model from that path. If it is not a path,
      it first tries to download a pre-trained SentenceTransformer model. If that fails, tries to construct a model
      from the Hugging Face Hub with that name.
  :param modules: A list of torch Modules that should be called sequentially, can be used to create custom
      SentenceTransformer models from scratch.
  :param device: Device (like "cuda", "cpu", "mps") that should be used for computation. If None, checks if a GPU
      can be used.
  :param cache_folder: Path to store models. Can also be set by the SENTENCE_TRANSFORMERS_HOME environment variable.
  :param trust_remote_code: Whether or not to allow for custom models defined on the Hub in their own modeling files.
      This option should only be set to True for repositories you trust and in which you have read the code, as it
      will execute code present on the Hub on your local machine.
  :param token: Hugging Face authentication token to download private models.
class_docstr_tok: ["Loads","or","creates","a","SentenceTransformer","model","that","can","be","used","to","map","sentences","\/","text","to","embeddings",".",":","param","model_name_or_path",":","If","it","is","a","filepath","on","disc",",","it","loads","the","model","from","that","path",".","If","it","is","not","a","path",",","it","first","tries","to","download","a","pre-trained","SentenceTransformer","model",".","If","that","fails",",","tries","to","construct","a","model","from","the","Hugging","Face","Hub","with","that","name",".",":","param","modules",":","A","list","of","torch","Modules","that","should","be","called","sequentially",",","can","be","used","to","create","custom","SentenceTransformer","models","from","scratch",".",":","param","device",":","Device","(","like","``","cuda","''",",","``","cpu","''",",","``","mps","''",")","that","should","be","used","for","computation",".","If","None",",","checks","if","a","GPU","can","be","used",".",":","param","cache_folder",":","Path","to","store","models",".","Can","also","be","set","by","the","SENTENCE_TRANSFORMERS_HOME","environment","variable",".",":","param","trust_remote_code",":","Whether","or","not","to","allow","for","custom","models","defined","on","the","Hub","in","their","own","modeling","files",".","This","option","should","only","be","set","to","True","for","repositories","you","trust","and","in","which","you","have","read","the","code",",","as","it","will","execute","code","present","on","the","Hub","on","your","local","machine",".",":","param","token",":","Hugging","Face","authentication","token","to","download","private","models","."]
docstr: Computes sentence embeddings.
  
  :param sentences: the sentences to embed.
  :param batch_size: the batch size used for the computation.
  :param show_progress_bar: Whether to output a progress bar when encode sentences.
  :param output_value: The type of embeddings to return: "sentence_embedding" to get sentence embeddings,
      "token_embeddings" to get wordpiece token embeddings, and `None`, to get all output values. Defaults
      to "sentence_embedding".
  :param convert_to_numpy: Whether the output should be a list of numpy vectors. If False, it is a list of PyTorch tensors.
  :param convert_to_tensor: Whether the output should be one large tensor. Overwrites `convert_to_numpy`.
  :param device: Which `torch.device` to use for the computation.
  :param normalize_embeddings: Whether to normalize returned vectors to have length 1. In that case,
      the faster dot-product (util.dot_score) instead of cosine similarity can be used.
  
  :return: By default, a list of tensors is returned. If convert_to_tensor, a stacked tensor is returned.
      If convert_to_numpy, a numpy matrix is returned.
code: def encode(
      self,
      sentences: Union[str, List[str]],
      batch_size: int = 32,
      show_progress_bar: bool = None,
      output_value: str = "sentence_embedding",
      convert_to_numpy: bool = True,
      convert_to_tensor: bool = False,
      device: str = None,
      normalize_embeddings: bool = False,
  ) -> Union[List[Tensor], ndarray, Tensor]:
      """
      Computes sentence embeddings.
  
      :param sentences: the sentences to embed.
      :param batch_size: the batch size used for the computation.
      :param show_progress_bar: Whether to output a progress bar when encode sentences.
      :param output_value: The type of embeddings to return: "sentence_embedding" to get sentence embeddings,
          "token_embeddings" to get wordpiece token embeddings, and `None`, to get all output values. Defaults
          to "sentence_embedding".
      :param convert_to_numpy: Whether the output should be a list of numpy vectors. If False, it is a list of PyTorch tensors.
      :param convert_to_tensor: Whether the output should be one large tensor. Overwrites `convert_to_numpy`.
      :param device: Which `torch.device` to use for the computation.
      :param normalize_embeddings: Whether to normalize returned vectors to have length 1. In that case,
          the faster dot-product (util.dot_score) instead of cosine similarity can be used.
  
      :return: By default, a list of tensors is returned. If convert_to_tensor, a stacked tensor is returned.
          If convert_to_numpy, a numpy matrix is returned.
      """
      self.eval()
      if show_progress_bar is None:
          show_progress_bar = (
              logger.getEffectiveLevel() == logging.INFO
              or logger.getEffectiveLevel() == logging.DEBUG
          )
  
      if convert_to_tensor:
          convert_to_numpy = False
  
      if output_value != "sentence_embedding":
          convert_to_tensor = False
          convert_to_numpy = False
  
      input_was_string = False
      if isinstance(sentences, str) or not hasattr(
          sentences, "__len__"
      ):  # Cast an individual sentence to a list with length 1
          sentences = [sentences]
          input_was_string = True
  
      if device is None:
          device = self.device
  
      self.to(device)
  
      all_embeddings = []
      length_sorted_idx = np.argsort(
          [-self._text_length(sen) for sen in sentences]
      )
      sentences_sorted = [sentences[idx] for idx in length_sorted_idx]
  
      for start_index in trange(
          0,
          len(sentences),
          batch_size,
          desc="Batches",
          disable=not show_progress_bar,
      ):
          sentences_batch = sentences_sorted[
              start_index : start_index + batch_size
          ]
          features = self.tokenize(sentences_batch)
          features = batch_to_device(features, device)
  
          with torch.no_grad():
              out_features = self.forward(features)
  
              if output_value == "token_embeddings":
                  embeddings = []
                  for token_emb, attention in zip(
                      out_features[output_value],
                      out_features["attention_mask"],
                  ):
                      last_mask_id = len(attention) - 1
                      while (
                          last_mask_id > 0
                          and attention[last_mask_id].item() == 0
                      ):
                          last_mask_id -= 1
  
                      embeddings.append(token_emb[0 : last_mask_id + 1])
              elif output_value is None:  # Return all outputs
                  embeddings = []
                  for sent_idx in range(
                      len(out_features["sentence_embedding"])
                  ):
                      row = {
                          name: out_features[name][sent_idx]
                          for name in out_features
                      }
                      embeddings.append(row)
              else:  # Sentence embeddings
                  embeddings = out_features[output_value]
                  embeddings = embeddings.detach()
                  if normalize_embeddings:
                      embeddings = torch.nn.functional.normalize(
                          embeddings, p=2, dim=1
                      )
  
                  # fixes for #522 and #487 to avoid oom problems on gpu with large datasets
                  if convert_to_numpy:
                      embeddings = embeddings.cpu()
  
              all_embeddings.extend(embeddings)
  
      all_embeddings = [
          all_embeddings[idx] for idx in np.argsort(length_sorted_idx)
      ]
  
      if convert_to_tensor:
          if len(all_embeddings):
              all_embeddings = torch.stack(all_embeddings)
          else:
              all_embeddings = torch.Tensor()
      elif convert_to_numpy:
          all_embeddings = np.asarray(
              [emb.numpy() for emb in all_embeddings]
          )
  
      if input_was_string:
          all_embeddings = all_embeddings[0]
  
      return all_embeddings
  
imports: import json
  import logging
  import os
  import shutil
  from collections import OrderedDict
  import warnings
  from typing import List, Dict, Tuple, Iterable, Type, Union, Callable, Optional, Literal, TYPE_CHECKING
  import numpy
  from numpy import ndarray
  import transformers
  from huggingface_hub import HfApi
  import torch
  from torch import nn, Tensor, device
  from torch.optim import Optimizer
  from torch.utils.data import DataLoader
  import torch.multiprocessing
  from tqdm.autonotebook import trange
  import math
  import queue
  import tempfile
  from .None import __MODEL_HUB_ORGANIZATION__
  from .evaluation import SentenceEvaluator
  from .util import import_from_string, batch_to_device, fullname, is_sentence_transformer_model, load_dir_path, load_file_path, save_to_hub_args_decorator
  from .models import Transformer, Pooling
  from .model_card_templates import ModelCardTemplate
  from .None import __version__
label_desc: Use image node_id 2 for calling the SentenceTransformer obj's underlying member method code with example usage: obj.encode(sentences, batch_size, show_progress_bar, output_value, convert_to_numpy, convert_to_tensor, device, normalize_embeddings) and returns: all_embeddings