def predict(self, sentences: Union[(List[Sentence], Sentence)], mini_batch_size=32, return_probabilities_for_all_classes: bool=False, verbose: bool=False, label_name: Optional[str]=None, return_loss=False, embedding_storage_mode='none', label_threshold: float=0.5, multi_label: Optional[bool]=None):
    "\n        Predict sequence tags for Named Entity Recognition task\n        :param sentences: a Sentence or a List of Sentence\n        :param mini_batch_size: size of the minibatch, usually bigger is more rapid but consume more memory,\n        up to a point when it has no more effect.\n        :param all_tag_prob: True to compute the score for each tag on each token,\n        otherwise only the score of the best tag is returned\n        :param verbose: set to True to display a progress bar\n        :param return_loss: set to True to return loss\n        :param label_name: set this to change the name of the label type that is predicted\n        :param embedding_storage_mode: default is 'none' which is always best. Only set to 'cpu' or 'gpu' if\n        you wish to not only predict, but also keep the generated embeddings in CPU or GPU memory respectively.\n        'gpu' to store embeddings in GPU memory.\n        "
    if (label_name is None):
        label_name = self.get_current_label_type()
    if (multi_label is None):
        multi_label = self.is_current_task_multi_label()
    if (not sentences):
        return sentences
    if isinstance(sentences, Sentence):
        sentences = [sentences]
    previous_sentence = None
    for sentence in sentences:
        if sentence.is_context_set():
            continue
        sentence._previous_sentence = previous_sentence
        sentence._next_sentence = None
        if previous_sentence:
            previous_sentence._next_sentence = sentence
        previous_sentence = sentence
    reordered_sentences = sorted(sentences, key=(lambda s: len(s)), reverse=True)
    dataloader = DataLoader(dataset=FlairDatapointDataset(reordered_sentences), batch_size=mini_batch_size)
    if verbose:
        progressbar = tqdm(dataloader)
        progressbar.set_description('Batch inference')
        dataloader = progressbar
    overall_loss = 0
    overall_count = 0
    batch_no = 0
    with torch.no_grad():
        for batch in dataloader:
            batch_no += 1
            batch = self._filter_empty_sentences(batch)
            if (not batch):
                continue
            for sentence in batch:
                sentence.remove_labels(label_name)
                all_labels = [label.decode('utf-8') for label in self.get_current_label_dictionary().idx2item]
                best_label = None
                for label in all_labels:
                    tars_sentence = self._get_tars_formatted_sentence(label, sentence)
                    loss_and_count = self.tars_model.predict(tars_sentence, label_name=label_name, return_loss=True, return_probabilities_for_all_classes=(True if (label_threshold < 0.5) else False))
                    overall_loss += loss_and_count[0].item()
                    overall_count += loss_and_count[1]
                    for predicted_tars_label in tars_sentence.get_labels(label_name):
                        if ((predicted_tars_label.value == self.LABEL_MATCH) and (predicted_tars_label.score > label_threshold)):
                            sentence.add_label(label_name, label, predicted_tars_label.score)
                if (not multi_label):
                    if (len(sentence.get_labels(label_name)) > 0):
                        label_scores = torch.tensor([label.score for label in sentence.get_labels(label_name)], dtype=torch.float)
                        best_label = sentence.get_labels(label_name)[torch.argmax(label_scores)]
                        sentence.remove_labels(label_name)
                        sentence.add_label(typename=label_name, value=best_label.value, score=best_label.score)
            store_embeddings(batch, storage_mode=embedding_storage_mode)
    if return_loss:
        return (overall_loss, overall_count)
Predict sequence tags for Named Entity Recognition task
:param sentences: a Sentence or a List of Sentence
:param mini_batch_size: size of the minibatch, usually bigger is more rapid but consume more memory,
up to a point when it has no more effect.
:param all_tag_prob: True to compute the score for each tag on each token,
otherwise only the score of the best tag is returned
:param verbose: set to True to display a progress bar
:param return_loss: set to True to return loss
:param label_name: set this to change the name of the label type that is predicted
:param embedding_storage_mode: default is 'none' which is always best. Only set to 'cpu' or 'gpu' if
you wish to not only predict, but also keep the generated embeddings in CPU or GPU memory respectively.
'gpu' to store embeddings in GPU memory.
def predict(self, sentences: Union[(List[Sentence], Sentence)], mini_batch_size=32, return_probabilities_for_all_classes: bool=False, verbose: bool=False, label_name: Optional[str]=None, return_loss=False, embedding_storage_mode='none', label_threshold: float=0.5, multi_label: Optional[bool]=None):
    "\n        Predict sequence tags for Named Entity Recognition task\n        :param sentences: a Sentence or a List of Sentence\n        :param mini_batch_size: size of the minibatch, usually bigger is more rapid but consume more memory,\n        up to a point when it has no more effect.\n        :param all_tag_prob: True to compute the score for each tag on each token,\n        otherwise only the score of the best tag is returned\n        :param verbose: set to True to display a progress bar\n        :param return_loss: set to True to return loss\n        :param label_name: set this to change the name of the label type that is predicted\n        :param embedding_storage_mode: default is 'none' which is always best. Only set to 'cpu' or 'gpu' if\n        you wish to not only predict, but also keep the generated embeddings in CPU or GPU memory respectively.\n        'gpu' to store embeddings in GPU memory.\n        "
    if (label_name is None):
        label_name = self.get_current_label_type()
    if (multi_label is None):
        multi_label = self.is_current_task_multi_label()
    if (not sentences):
        return sentences
    if isinstance(sentences, Sentence):
        sentences = [sentences]
    previous_sentence = None
    for sentence in sentences:
        if sentence.is_context_set():
            continue
        sentence._previous_sentence = previous_sentence
        sentence._next_sentence = None
        if previous_sentence:
            previous_sentence._next_sentence = sentence
        previous_sentence = sentence
    reordered_sentences = sorted(sentences, key=(lambda s: len(s)), reverse=True)
    dataloader = DataLoader(dataset=FlairDatapointDataset(reordered_sentences), batch_size=mini_batch_size)
    if verbose:
        progressbar = tqdm(dataloader)
        progressbar.set_description('Batch inference')
        dataloader = progressbar
    overall_loss = 0
    overall_count = 0
    batch_no = 0
    with torch.no_grad():
        for batch in dataloader:
            batch_no += 1
            batch = self._filter_empty_sentences(batch)
            if (not batch):
                continue
            for sentence in batch:
                sentence.remove_labels(label_name)
                all_labels = [label.decode('utf-8') for label in self.get_current_label_dictionary().idx2item]
                best_label = None
                for label in all_labels:
                    tars_sentence = self._get_tars_formatted_sentence(label, sentence)
                    loss_and_count = self.tars_model.predict(tars_sentence, label_name=label_name, return_loss=True, return_probabilities_for_all_classes=(True if (label_threshold < 0.5) else False))
                    overall_loss += loss_and_count[0].item()
                    overall_count += loss_and_count[1]
                    for predicted_tars_label in tars_sentence.get_labels(label_name):
                        if ((predicted_tars_label.value == self.LABEL_MATCH) and (predicted_tars_label.score > label_threshold)):
                            sentence.add_label(label_name, label, predicted_tars_label.score)
                if (not multi_label):
                    if (len(sentence.get_labels(label_name)) > 0):
                        label_scores = torch.tensor([label.score for label in sentence.get_labels(label_name)], dtype=torch.float)
                        best_label = sentence.get_labels(label_name)[torch.argmax(label_scores)]
                        sentence.remove_labels(label_name)
                        sentence.add_label(typename=label_name, value=best_label.value, score=best_label.score)
            store_embeddings(batch, storage_mode=embedding_storage_mode)
    if return_loss:
        return (overall_loss, overall_count)