docstr: Predicts labels for current batch with CRF or Softmax.
  
  Args:
      sentences: List of sentences in batch
      mini_batch_size: batch size for test data
      return_probabilities_for_all_classes: Whether to return probabilities for all classes
      verbose: whether to use progress bar
      label_name: which label to predict
      return_loss: whether to return loss value
      embedding_storage_mode: determines where to store embeddings - can be "gpu", "cpu" or None.
      force_token_predictions: add labels per token instead of span labels, even if `self.predict_spans` is True
docstr_tok: ["Predicts","labels","for","current","batch","with","CRF","or","Softmax",".","Args",":","sentences",":","List","of","sentences","in","batch","mini_batch_size",":","batch","size","for","test","data","return_probabilities_for_all_classes",":","Whether","to","return","probabilities","for","all","classes","verbose",":","whether","to","use","progress","bar","label_name",":","which","label","to","predict","return_loss",":","whether","to","return","loss","value","embedding_storage_mode",":","determines","where","to","store","embeddings","-","can","be","``","gpu","''",",","``","cpu","''","or","None",".","force_token_predictions",":","add","labels","per","token","instead","of","span","labels",",","even","if","`","self.predict_spans","`","is","True"]
code: def predict(
      self,
      sentences: Union[List[Sentence], Sentence],
      mini_batch_size: int = 32,
      return_probabilities_for_all_classes: bool = False,
      verbose: bool = False,
      label_name: Optional[str] = None,
      return_loss=False,
      embedding_storage_mode="none",
      force_token_predictions: bool = False,
  ):
      """Predicts labels for current batch with CRF or Softmax.
  
      Args:
          sentences: List of sentences in batch
          mini_batch_size: batch size for test data
          return_probabilities_for_all_classes: Whether to return probabilities for all classes
          verbose: whether to use progress bar
          label_name: which label to predict
          return_loss: whether to return loss value
          embedding_storage_mode: determines where to store embeddings - can be "gpu", "cpu" or None.
          force_token_predictions: add labels per token instead of span labels, even if `self.predict_spans` is True
      """
      if label_name is None:
          label_name = self.tag_type
  
      with torch.no_grad():
          if not sentences:
              return sentences
  
          # make sure it's a list
          if not isinstance(sentences, list) and not isinstance(
              sentences, flair.data.Dataset
          ):
              sentences = [sentences]
  
          Sentence.set_context_for_sentences(
              cast(List[Sentence], sentences)
          )
  
          # filter empty sentences
          sentences = [
              sentence for sentence in sentences if len(sentence) > 0
          ]
  
          # reverse sort all sequences by their length
          reordered_sentences = sorted(sentences, key=len, reverse=True)
  
          if len(reordered_sentences) == 0:
              return sentences
  
          dataloader = DataLoader(
              dataset=FlairDatapointDataset(reordered_sentences),
              batch_size=mini_batch_size,
          )
          # progress bar for verbosity
          if verbose:
              dataloader = tqdm(dataloader, desc="Batch inference")
  
          overall_loss = torch.zeros(1, device=flair.device)
          label_count = 0
          for batch in dataloader:
              # stop if all sentences are empty
              if not batch:
                  continue
  
              # get features from forward propagation
              sentence_tensor, lengths = self._prepare_tensors(batch)
              features = self.forward(sentence_tensor, lengths)
  
              # remove previously predicted labels of this type
              for sentence in batch:
                  sentence.remove_labels(label_name)
  
              # if return_loss, get loss value
              if return_loss:
                  gold_labels = self._prepare_label_tensor(batch)
                  loss = self._calculate_loss(features, gold_labels)
                  overall_loss += loss[0]
                  label_count += loss[1]
  
              # make predictions
              if self.use_crf:
                  predictions, all_tags = self.viterbi_decoder.decode(
                      features,
                      return_probabilities_for_all_classes,
                      batch,
                  )
              else:
                  predictions, all_tags = self._standard_inference(
                      features,
                      batch,
                      return_probabilities_for_all_classes,
                  )
  
              # add predictions to Sentence
              for sentence, sentence_predictions in zip(
                  batch, predictions
              ):
                  # BIOES-labels need to be converted to spans
                  if self.predict_spans and not force_token_predictions:
                      sentence_tags = [
                          label[0] for label in sentence_predictions
                      ]
                      sentence_scores = [
                          label[1] for label in sentence_predictions
                      ]
                      predicted_spans = get_spans_from_bio(
                          sentence_tags, sentence_scores
                      )
                      for predicted_span in predicted_spans:
                          span: Span = sentence[
                              predicted_span[0][0] : predicted_span[0][
                                  -1
                              ]
                              + 1
                          ]
                          span.add_label(
                              label_name,
                              value=predicted_span[2],
                              score=predicted_span[1],
                          )
  
                  # token-labels can be added directly ("O" and legacy "_" predictions are skipped)
                  else:
                      for token, label in zip(
                          sentence.tokens, sentence_predictions
                      ):
                          if label[0] in ["O", "_"]:
                              continue
                          token.add_label(
                              typename=label_name,
                              value=label[0],
                              score=label[1],
                          )
  
              # all_tags will be empty if all_tag_prob is set to False, so the for loop will be avoided
              for sentence, sent_all_tags in zip(batch, all_tags):
                  for token, token_all_tags in zip(
                      sentence.tokens, sent_all_tags
                  ):
                      token.add_tags_proba_dist(
                          label_name, token_all_tags
                      )
  
              store_embeddings(
                  sentences, storage_mode=embedding_storage_mode
              )
  
          if return_loss:
              return overall_loss, label_count
          return None
  
imports: import logging
  import tempfile
  from pathlib import Path
  from typing import Any, Dict, List, Optional, Tuple, Union, cast
  from urllib.error import HTTPError
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
  from tqdm import tqdm
  import flair.nn
  from flair.data import Dictionary, Label, Sentence, Span, get_spans_from_bio
  from flair.datasets import DataLoader, FlairDatapointDataset
  from flair.embeddings import TokenEmbeddings
  from flair.file_utils import cached_path, unzip_file
  from flair.models.sequence_tagger_utils.crf import CRF
  from flair.models.sequence_tagger_utils.viterbi import ViterbiDecoder, ViterbiLoss
  from flair.training_utils import store_embeddings
label_desc: Use image node_id 14 for calling the SequenceTagger obj's underlying member method code with example usage: obj.predict(sentences, mini_batch_size, return_probabilities_for_all_classes, verbose, label_name, return_loss, embedding_storage_mode, force_token_predictions) and returns: None, sentences, sentences, overall_loss,  label_count