class_docstr: Bert embedding class.
  
  Parameters
  ----------
  name : str, optional
      BERT model name, default: ``'bert-base-uncased'``.
  max_seq_len : int, optional
      Maximal sequence length, default: ``500``.
  doc_stride : int, optional
      Chunking stride, default: ``250``.
  fix_emb : boolean, optional
      Specify whether to fix pretrained BERT embeddings, default: ``True``.
  lower_case : boolean, optional
      Specify whether to use lower case, default: ``True``.
class_docstr_tok: ["Bert","embedding","class",".","Parameters","--","--","--","--","--","name",":","str",",","optional","BERT","model","name",",","default",":","``","'bert-base-uncased","'","``",".","max_seq_len",":","int",",","optional","Maximal","sequence","length",",","default",":","``","500","``",".","doc_stride",":","int",",","optional","Chunking","stride",",","default",":","``","250","``",".","fix_emb",":","boolean",",","optional","Specify","whether","to","fix","pretrained","BERT","embeddings",",","default",":","``","True","``",".","lower_case",":","boolean",",","optional","Specify","whether","to","use","lower","case",",","default",":","``","True","``","."]
docstr: Compute BERT embeddings for each word in text.
  
  Parameters
  ----------
  raw_text_data : list
      The raw text input data. Example: [['what', 'is', 'bert'], ['how', 'to', 'use']].
  
  Returns
  -------
  torch.Tensor
      BERT embedding matrix.
docstr_tok: ["Compute","BERT","embeddings","for","each","word","in","text",".","Parameters","--","--","--","--","--","raw_text_data",":","list","The","raw","text","input","data",".","Example",":","[","[","'what","'",",","'is","'",",","'bert","'","]",",","[","'how","'",",","'to","'",",","'use","'","]","]",".","Returns","--","--","--","-","torch.Tensor","BERT","embedding","matrix","."]
code: def forward(self, raw_text_data):
      """Compute BERT embeddings for each word in text.
  
      Parameters
      ----------
      raw_text_data : list
          The raw text input data. Example: [['what', 'is', 'bert'], ['how', 'to', 'use']].
  
      Returns
      -------
      torch.Tensor
          BERT embedding matrix.
      """
      bert_features = []
      max_d_len = 0
      for text in raw_text_data:
          bert_features.append(
              convert_text_to_bert_features(
                  text,
                  self.bert_tokenizer,
                  self.bert_max_seq_len,
                  self.bert_doc_stride,
              )
          )
          max_d_len = max(max_d_len, len(text))
  
      max_bert_d_num_chunks = max(
          [len(ex_bert_d) for ex_bert_d in bert_features]
      )
      max_bert_d_len = max(
          [
              len(bert_d.input_ids)
              for ex_bert_d in bert_features
              for bert_d in ex_bert_d
          ]
      )
      bert_xd = torch.LongTensor(
          len(raw_text_data), max_bert_d_num_chunks, max_bert_d_len
      ).fill_(0)
      bert_xd_mask = torch.LongTensor(
          len(raw_text_data), max_bert_d_num_chunks, max_bert_d_len
      ).fill_(0)
      bert_token_to_orig_map = []
      for i, ex_bert_d in enumerate(bert_features):  # Example level
          ex_token_to_orig_map = []
          for j, bert_d in enumerate(ex_bert_d):  # Chunk level
              bert_xd[i, j, : len(bert_d.input_ids)].copy_(
                  torch.LongTensor(bert_d.input_ids)
              )
              bert_xd_mask[i, j, : len(bert_d.input_mask)].copy_(
                  torch.LongTensor(bert_d.input_mask)
              )
              ex_token_to_orig_map.append(
                  bert_d.token_to_orig_map_matrix
              )
          bert_token_to_orig_map.append(ex_token_to_orig_map)
      bert_token_to_orig_map = pad_4d_vals(
          bert_token_to_orig_map,
          len(raw_text_data),
          max_bert_d_num_chunks,
          max_bert_d_len,
          max_d_len,
      )
      bert_token_to_orig_map = torch.Tensor(bert_token_to_orig_map).to(
          self.bert_model.device
      )
  
      bert_xd = bert_xd.to(self.bert_model.device)
      bert_xd_mask = bert_xd_mask.to(self.bert_model.device)
  
      encoder_outputs = self.bert_model(
          bert_xd.view(-1, bert_xd.size(-1)),
          token_type_ids=None,
          attention_mask=bert_xd_mask.view(-1, bert_xd_mask.size(-1)),
          output_hidden_states=True,
          return_dict=True,
      )
  
      all_encoder_layers = encoder_outputs["hidden_states"][
          1:
      ]  # The first one is the input embedding
      all_encoder_layers = torch.stack(
          [x.view(bert_xd.shape + (-1,)) for x in all_encoder_layers], 0
      )
      bert_xd_f = extract_bert_hidden_states(
          all_encoder_layers, bert_token_to_orig_map, weighted_avg=True
      )
  
      weights_bert_layers = torch.softmax(
          self.logits_bert_layers, dim=-1
      )
      bert_xd_f = torch.mm(
          weights_bert_layers, bert_xd_f.view(bert_xd_f.size(0), -1)
      ).view(bert_xd_f.shape[1:])
  
      return bert_xd_f
  
imports: import torch
  from torch import nn
  from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
  from ...data.data import from_batch
  from ..utils.bert_utils import convert_text_to_bert_features, extract_bert_hidden_states
  from ..utils.generic_utils import dropout_fn
  from ..utils.padding_utils import pad_4d_vals
  from ..utils.vocab_utils import Vocab
label_desc: Use image node_id 2 for calling the BertEmbedding obj's underlying member method code with example usage: obj.forward(raw_text_data) and returns: bert_xd_f