docstr: Add embeddings to all sentences in the given list of sentences.
  
  If embeddings are already added, update only if embeddings are non-static.
docstr_tok: ["Add","embeddings","to","all","sentences","in","the","given","list","of","sentences",".","If","embeddings","are","already","added",",","update","only","if","embeddings","are","non-static","."]
code: def _add_embeddings_internal(self, sentences: List[Sentence]):
      """Add embeddings to all sentences in the given list of sentences.
  
      If embeddings are already added, update only if embeddings are non-static.
      """
      # TODO: remove in future versions
      if not hasattr(self, "locked_dropout"):
          self.locked_dropout = None
      if not hasattr(self, "word_dropout"):
          self.word_dropout = None
  
      self.zero_grad()  # is it necessary?
  
      # embed words in the sentence
      self.embeddings.embed(sentences)
  
      lengths: List[int] = [
          len(sentence.tokens) for sentence in sentences
      ]
      padding_length: int = max(max(lengths), self.min_sequence_length)
  
      pre_allocated_zero_tensor = torch.zeros(
          self.embeddings.embedding_length * padding_length,
          dtype=self.convs[0].weight.dtype,
          device=flair.device,
      )
  
      all_embs: List[torch.Tensor] = []
      for sentence in sentences:
          all_embs += [
              emb
              for token in sentence
              for emb in token.get_each_embedding()
          ]
          nb_padding_tokens = padding_length - len(sentence)
  
          if nb_padding_tokens > 0:
              t = pre_allocated_zero_tensor[
                  : self.embeddings.embedding_length * nb_padding_tokens
              ]
              all_embs.append(t)
  
      sentence_tensor = torch.cat(all_embs).view(
          [
              len(sentences),
              padding_length,
              self.embeddings.embedding_length,
          ]
      )
  
      # before-RNN dropout
      if self.dropout:
          sentence_tensor = self.dropout(sentence_tensor)
      if self.locked_dropout:
          sentence_tensor = self.locked_dropout(sentence_tensor)
      if self.word_dropout:
          sentence_tensor = self.word_dropout(sentence_tensor)
  
      # reproject if set
      if self.word_reprojection_map is not None:
          sentence_tensor = self.word_reprojection_map(sentence_tensor)
  
      # push CNN
      x = sentence_tensor
      x = x.permute(0, 2, 1)
  
      rep = [
          self.pool(torch.nn.functional.relu(conv(x)))
          for conv in self.convs
      ]
      outputs = torch.cat(rep, 1)
  
      outputs = outputs.reshape(outputs.size(0), -1)
  
      # after-CNN dropout
      if self.dropout:
          outputs = self.dropout(outputs)
      if self.locked_dropout:
          outputs = self.locked_dropout(outputs)
  
      # extract embeddings from CNN
      for sentence_no, _length in enumerate(lengths):
          embedding = outputs[sentence_no]
  
          if self.static_embeddings:
              embedding = embedding.detach()
  
          sentence = sentences[sentence_no]
          sentence.set_embedding(self.name, embedding)
  
imports: import logging
  from typing import Any, Dict, List, Optional, Union, cast
  import torch
  from sklearn.feature_extraction.text import TfidfVectorizer
  from torch.nn import RNNBase
  from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
  import flair
  from flair.data import Sentence
  from flair.embeddings.base import DocumentEmbeddings, load_embeddings, register_embeddings
  from flair.embeddings.token import FlairEmbeddings, StackedEmbeddings, TokenEmbeddings
  from flair.embeddings.transformer import TransformerEmbeddings, TransformerOnnxDocumentEmbeddings
  from flair.nn import LockedDropout, WordDropout
label_desc: Use image node_id 3 for calling the DocumentCNNEmbeddings obj's underlying member method code with example usage: obj._add_embeddings_internal(sentences) without return types