class_docstr: ## BERT Embeddings
  
  For a given chunk of text $N$ this class generates BERT embeddings $        ext{B\small{ERT}}(N)$.
  $   ext{B\small{ERT}}(N)$ is the average of BERT embeddings of all the tokens in $N$.
docstr: ### Get $       ext{B\small{ERT}}(N)$ for a list of chunks.
code: def __call__(self, chunks: List[str]):
      """
      ### Get $\text{B\small{ERT}}(N)$ for a list of chunks.
      """
  
      # We don't need to compute gradients
      with torch.no_grad():
          # Trim the chunks
          trimmed_chunks = [self._trim_chunk(c) for c in chunks]
  
          # Tokenize the chunks with BERT tokenizer
          tokens = self.tokenizer(
              trimmed_chunks,
              return_tensors="pt",
              add_special_tokens=False,
              padding=True,
          )
  
          # Move token ids, attention mask and token types to the device
          input_ids = tokens["input_ids"].to(self.device)
          attention_mask = tokens["attention_mask"].to(self.device)
          token_type_ids = tokens["token_type_ids"].to(self.device)
          # Evaluate the model
          output = self.model(
              input_ids=input_ids,
              attention_mask=attention_mask,
              token_type_ids=token_type_ids,
          )
  
          # Get the token embeddings
          state = output["last_hidden_state"]
          # Calculate the average token embeddings.
          # Note that the attention mask is `0` if the token is empty padded.
          # We get empty tokens because the chunks are of different lengths.
          emb = (state * attention_mask[:, :, None]).sum(
              dim=1
          ) / attention_mask[:, :, None].sum(dim=1)
  
          #
          return emb
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/transformers/retro/bert_embeddings.py
imports: from typing import List
  import torch
  from transformers import BertTokenizer, BertModel
  from labml import lab, monit
label_desc: Use image node_id 3 for calling the BERTChunkEmbeddings obj's underlying member method code with example usage: obj.__call__(chunks) and returns: emb