code: def forward(
      self,
      word,
      word_mask,
      wordchars,
      wordchars_mask,
      upos,
      xpos,
      ufeats,
      pretrained,
      word_orig_idx,
      sentlens,
      wordlens,
      text,
  ):
      def pack(x):
          return pack_padded_sequence(x, sentlens, batch_first=True)
  
      inputs = []
      if self.args["word_emb_dim"] > 0:
          word_emb = self.word_emb(word)
          word_emb = pack(word_emb)
          inputs += [word_emb]
  
      if self.args["pretrain"]:
          pretrained_emb = self.pretrained_emb(pretrained)
          pretrained_emb = self.trans_pretrained(pretrained_emb)
          pretrained_emb = pack(pretrained_emb)
          inputs += [pretrained_emb]
  
      def pad(x):
          return pad_packed_sequence(
              PackedSequence(x, inputs[0].batch_sizes), batch_first=True
          )[0]
  
      if self.args["char"] and self.args["char_emb_dim"] > 0:
          if self.args.get("charlm", None):
              all_forward_chars = (
                  self.charmodel_forward.build_char_representation(text)
              )
              assert isinstance(all_forward_chars, list)
              if self.charmodel_forward_transform is not None:
                  all_forward_chars = [
                      self.charmodel_forward_transform(x)
                      for x in all_forward_chars
                  ]
              all_forward_chars = pack(
                  pad_sequence(all_forward_chars, batch_first=True)
              )
  
              all_backward_chars = (
                  self.charmodel_backward.build_char_representation(
                      text
                  )
              )
              if self.charmodel_backward_transform is not None:
                  all_backward_chars = [
                      self.charmodel_backward_transform(x)
                      for x in all_backward_chars
                  ]
              all_backward_chars = pack(
                  pad_sequence(all_backward_chars, batch_first=True)
              )
  
              inputs += [all_forward_chars, all_backward_chars]
          else:
              char_reps = self.charmodel(
                  wordchars,
                  wordchars_mask,
                  word_orig_idx,
                  sentlens,
                  wordlens,
              )
              char_reps = PackedSequence(
                  self.trans_char(self.drop(char_reps.data)),
                  char_reps.batch_sizes,
              )
              inputs += [char_reps]
  
      if self.bert_model is not None:
          device = next(self.parameters()).device
          processed_bert = extract_bert_embeddings(
              self.args["bert_model"],
              self.bert_tokenizer,
              self.bert_model,
              text,
              device,
              keep_endpoints=False,
              num_layers=self.bert_layer_mix.in_features
              if self.bert_layer_mix is not None
              else None,
              detach=not self.args.get("bert_finetune", False),
          )
  
          if self.bert_layer_mix is not None:
              # add the average so that the default behavior is to
              # take an average of the N layers, and anything else
              # other than that needs to be learned
              # TODO: refactor this
              processed_bert = [
                  self.bert_layer_mix(feature).squeeze(2)
                  + feature.sum(axis=2)
                  / self.bert_layer_mix.in_features
                  for feature in processed_bert
              ]
  
          processed_bert = pad_sequence(
              processed_bert, batch_first=True
          )
          inputs += [pack(processed_bert)]
  
      lstm_inputs = torch.cat([x.data for x in inputs], 1)
      lstm_inputs = self.worddrop(lstm_inputs, self.drop_replacement)
      lstm_inputs = self.drop(lstm_inputs)
      lstm_inputs = PackedSequence(lstm_inputs, inputs[0].batch_sizes)
  
      lstm_outputs, _ = self.taggerlstm(
          lstm_inputs,
          sentlens,
          hx=(
              self.taggerlstm_h_init.expand(
                  2 * self.args["num_layers"],
                  word.size(0),
                  self.args["hidden_dim"],
              ).contiguous(),
              self.taggerlstm_c_init.expand(
                  2 * self.args["num_layers"],
                  word.size(0),
                  self.args["hidden_dim"],
              ).contiguous(),
          ),
      )
      lstm_outputs = lstm_outputs.data
  
      upos_hid = F.relu(self.upos_hid(self.drop(lstm_outputs)))
      upos_pred = self.upos_clf(self.drop(upos_hid))
  
      preds = [pad(upos_pred).max(2)[1]]
  
      if upos is not None:
          upos = pack(upos).data
          loss = self.crit(
              upos_pred.view(-1, upos_pred.size(-1)), upos.view(-1)
          )
      else:
          loss = 0.0
  
      if self.share_hid:
          xpos_hid = upos_hid
          ufeats_hid = upos_hid
  
          clffunc = lambda clf, hid: clf(self.drop(hid))
      else:
          xpos_hid = F.relu(self.xpos_hid(self.drop(lstm_outputs)))
          ufeats_hid = F.relu(self.ufeats_hid(self.drop(lstm_outputs)))
  
          if self.training and upos is not None:
              upos_emb = self.upos_emb(upos)
          else:
              upos_emb = self.upos_emb(upos_pred.max(1)[1])
  
          clffunc = lambda clf, hid: clf(
              self.drop(hid), self.drop(upos_emb)
          )
  
      if xpos is not None:
          xpos = pack(xpos).data
      if isinstance(self.vocab["xpos"], CompositeVocab):
          xpos_preds = []
          for i in range(len(self.vocab["xpos"])):
              xpos_pred = clffunc(self.xpos_clf[i], xpos_hid)
              if xpos is not None:
                  loss += self.crit(
                      xpos_pred.view(-1, xpos_pred.size(-1)),
                      xpos[:, i].view(-1),
                  )
              xpos_preds.append(pad(xpos_pred).max(2, keepdim=True)[1])
          preds.append(torch.cat(xpos_preds, 2))
      else:
          xpos_pred = clffunc(self.xpos_clf, xpos_hid)
          if xpos is not None:
              loss += self.crit(
                  xpos_pred.view(-1, xpos_pred.size(-1)), xpos.view(-1)
              )
          preds.append(pad(xpos_pred).max(2)[1])
  
      ufeats_preds = []
      if ufeats is not None:
          ufeats = pack(ufeats).data
      for i in range(len(self.vocab["feats"])):
          ufeats_pred = clffunc(self.ufeats_clf[i], ufeats_hid)
          if ufeats is not None:
              loss += self.crit(
                  ufeats_pred.view(-1, ufeats_pred.size(-1)),
                  ufeats[:, i].view(-1),
              )
          ufeats_preds.append(pad(ufeats_pred).max(2, keepdim=True)[1])
      preds.append(torch.cat(ufeats_preds, 2))
  
      return loss, preds
  
file_path: stanza/stanza/models/pos/model.py
imports: import logging
  import os
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn.utils.rnn import pad_packed_sequence, pack_padded_sequence, pack_sequence, pad_sequence, PackedSequence
  from stanza.models.common.bert_embedding import extract_bert_embeddings
  from stanza.models.common.biaffine import BiaffineScorer
  from stanza.models.common.foundation_cache import load_bert, load_charlm
  from stanza.models.common.hlstm import HighwayLSTM
  from stanza.models.common.dropout import WordDropout
  from stanza.models.common.vocab import CompositeVocab
  from stanza.models.common.char_model import CharacterModel
label_desc: Use image node_id 3 for calling the Tagger obj's underlying member method code with example usage: obj.forward(word, word_mask, wordchars, wordchars_mask, upos, xpos, ufeats, pretrained, word_orig_idx, sentlens, wordlens, text) and returns: loss,  preds, pack_padded_sequence, pad_packed_sequence