class_docstr: Label Attention Module for label-specific representations
  The module can be used right after the Partitioned Attention, or it can be experimented with for the transition stack
class_docstr_tok: ["Label","Attention","Module","for","label-specific","representations","The","module","can","be","used","right","after","the","Partitioned","Attention",",","or","it","can","be","experimented","with","for","the","transition","stack"]
code: def forward(self, word_embeddings, tagged_word_lists):
      if self.input_projection:
          if self.d_positional > 0:
              word_embeddings = [
                  torch.cat(
                      (
                          self.input_projection(
                              sentence[:, : -self.d_positional]
                          ),
                          sentence[:, -self.d_positional :],
                      ),
                      dim=1,
                  )
                  for sentence in word_embeddings
              ]
          else:
              word_embeddings = [
                  self.input_projection(sentence)
                  for sentence in word_embeddings
              ]
      # Extract Labeled Representation
      packed_len = sum(
          sentence.shape[0] for sentence in word_embeddings
      )
      batch_idxs = np.zeros(packed_len, dtype=int)
  
      batch_size = len(word_embeddings)
      i = 0
  
      sentence_lengths = [0] * batch_size
      for sentence_idx, sentence in enumerate(word_embeddings):
          sentence_lengths[sentence_idx] = len(sentence)
          for word in sentence:
              batch_idxs[i] = sentence_idx
              i += 1
  
      batch_indices = batch_idxs
      batch_idxs = BatchIndices(batch_idxs, word_embeddings[0].device)
  
      new_embeds = []
      for sentence_idx, batch in enumerate(word_embeddings):
          for word_idx, embed in enumerate(batch):
              if word_idx < sentence_lengths[sentence_idx]:
                  new_embeds.append(embed)
  
      new_word_embeddings = torch.stack(new_embeds)
  
      labeled_representations, _ = self.label_attention(
          new_word_embeddings, batch_idxs
      )
      labeled_representations = self.lal_ff(
          labeled_representations, batch_idxs
      )
      final_labeled_representations = [[] for i in range(batch_size)]
  
      for idx, embed in enumerate(labeled_representations):
          final_labeled_representations[batch_indices[idx]].append(
              embed
          )
  
      for idx, representation in enumerate(
          final_labeled_representations
      ):
          final_labeled_representations[idx] = torch.stack(
              representation
          )
  
      return final_labeled_representations
  
imports: import numpy
  import functools
  import sys
  import torch
  from torch.autograd import Variable
  import torch.nn
  import torch.nn.init
label_desc: Use image node_id 2 for calling the LabelAttentionModule obj's underlying member method code with example usage: obj.forward(word_embeddings, tagged_word_lists) and returns: final_labeled_representations