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'):
    "\n        Predicts the class labels for the given sentences. The labels are directly added to the sentences.\n        :param sentences: list of sentences\n        :param mini_batch_size: mini batch size to use\n        :param return_probabilities_for_all_classes : return probabilities for all classes instead of only best predicted\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.label_type if (self.label_type is not None) else 'label')
    with torch.no_grad():
        if (not sentences):
            return sentences
        if isinstance(sentences, DataPoint):
            sentences = [sentences]
        if isinstance(sentences[0], DataPoint):
            sentences = [sentence for sentence in sentences if (len(sentence) > 0)]
        if (len(sentences) == 0):
            return sentences
        rev_order_len_index = sorted(range(len(sentences)), key=(lambda k: len(sentences[k])), reverse=True)
        reordered_sentences: List[Union[(DataPoint, str)]] = [sentences[index] for index in rev_order_len_index]
        dataloader = DataLoader(dataset=SentenceDataset(reordered_sentences), batch_size=mini_batch_size)
        if verbose:
            dataloader = tqdm(dataloader)
        overall_loss = 0
        batch_no = 0
        label_count = 0
        for batch in dataloader:
            batch_no += 1
            if verbose:
                dataloader.set_description(f'Inferencing on batch {batch_no}')
            if (not batch):
                continue
            (scores, gold_labels, data_points, label_candidates) = self.forward_pass(batch, return_label_candidates=True)
            for sentence in data_points:
                sentence.remove_labels(label_name)
            if return_loss:
                overall_loss += self._calculate_loss(scores, gold_labels)[0]
                label_count += len(label_candidates)
            if (len(label_candidates) > 0):
                if self.multi_label:
                    sigmoided = torch.sigmoid(scores)
                    n_labels = sigmoided.size(1)
                    for (s_idx, (data_point, label_candidate)) in enumerate(zip(data_points, label_candidates)):
                        for l_idx in range(n_labels):
                            label_value = self.label_dictionary.get_item_for_index(l_idx)
                            if (label_value == 'O'):
                                continue
                            label_threshold = self._get_label_threshold(label_value)
                            label_score = sigmoided[(s_idx, l_idx)].item()
                            if ((label_score > label_threshold) or return_probabilities_for_all_classes):
                                label = label_candidate.spawn(value=label_value, score=label_score)
                                data_point.add_complex_label(label_name, label)
                else:
                    softmax = torch.nn.functional.softmax(scores, dim=(- 1))
                    if return_probabilities_for_all_classes:
                        n_labels = softmax.size(1)
                        for (s_idx, (data_point, label_candidate)) in enumerate(zip(data_points, label_candidates)):
                            for l_idx in range(n_labels):
                                label_value = self.label_dictionary.get_item_for_index(l_idx)
                                if (label_value == 'O'):
                                    continue
                                label_score = softmax[(s_idx, l_idx)].item()
                                label = label_candidate.spawn(value=label_value, score=label_score)
                                data_point.add_complex_label(label_name, label)
                    else:
                        (conf, idx) = torch.max(softmax, dim=(- 1))
                        for (data_point, label_candidate, c, i) in zip(data_points, label_candidates, conf, idx):
                            label_value = self.label_dictionary.get_item_for_index(i.item())
                            if (label_value == 'O'):
                                continue
                            label = label_candidate.spawn(value=label_value, score=c.item())
                            data_point.add_complex_label(label_name, label)
            store_embeddings(batch, storage_mode=embedding_storage_mode)
        if return_loss:
            return (overall_loss, label_count)
Predicts the class labels for the given sentences. The labels are directly added to the sentences.
:param sentences: list of sentences
:param mini_batch_size: mini batch size to use
:param return_probabilities_for_all_classes : return probabilities for all classes instead of only best predicted
: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: int=32, return_probabilities_for_all_classes: bool=False, verbose: bool=False, label_name: Optional[str]=None, return_loss=False, embedding_storage_mode='none'):
    "\n        Predicts the class labels for the given sentences. The labels are directly added to the sentences.\n        :param sentences: list of sentences\n        :param mini_batch_size: mini batch size to use\n        :param return_probabilities_for_all_classes : return probabilities for all classes instead of only best predicted\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.label_type if (self.label_type is not None) else 'label')
    with torch.no_grad():
        if (not sentences):
            return sentences
        if isinstance(sentences, DataPoint):
            sentences = [sentences]
        if isinstance(sentences[0], DataPoint):
            sentences = [sentence for sentence in sentences if (len(sentence) > 0)]
        if (len(sentences) == 0):
            return sentences
        rev_order_len_index = sorted(range(len(sentences)), key=(lambda k: len(sentences[k])), reverse=True)
        reordered_sentences: List[Union[(DataPoint, str)]] = [sentences[index] for index in rev_order_len_index]
        dataloader = DataLoader(dataset=SentenceDataset(reordered_sentences), batch_size=mini_batch_size)
        if verbose:
            dataloader = tqdm(dataloader)
        overall_loss = 0
        batch_no = 0
        label_count = 0
        for batch in dataloader:
            batch_no += 1
            if verbose:
                dataloader.set_description(f'Inferencing on batch {batch_no}')
            if (not batch):
                continue
            (scores, gold_labels, data_points, label_candidates) = self.forward_pass(batch, return_label_candidates=True)
            for sentence in data_points:
                sentence.remove_labels(label_name)
            if return_loss:
                overall_loss += self._calculate_loss(scores, gold_labels)[0]
                label_count += len(label_candidates)
            if (len(label_candidates) > 0):
                if self.multi_label:
                    sigmoided = torch.sigmoid(scores)
                    n_labels = sigmoided.size(1)
                    for (s_idx, (data_point, label_candidate)) in enumerate(zip(data_points, label_candidates)):
                        for l_idx in range(n_labels):
                            label_value = self.label_dictionary.get_item_for_index(l_idx)
                            if (label_value == 'O'):
                                continue
                            label_threshold = self._get_label_threshold(label_value)
                            label_score = sigmoided[(s_idx, l_idx)].item()
                            if ((label_score > label_threshold) or return_probabilities_for_all_classes):
                                label = label_candidate.spawn(value=label_value, score=label_score)
                                data_point.add_complex_label(label_name, label)
                else:
                    softmax = torch.nn.functional.softmax(scores, dim=(- 1))
                    if return_probabilities_for_all_classes:
                        n_labels = softmax.size(1)
                        for (s_idx, (data_point, label_candidate)) in enumerate(zip(data_points, label_candidates)):
                            for l_idx in range(n_labels):
                                label_value = self.label_dictionary.get_item_for_index(l_idx)
                                if (label_value == 'O'):
                                    continue
                                label_score = softmax[(s_idx, l_idx)].item()
                                label = label_candidate.spawn(value=label_value, score=label_score)
                                data_point.add_complex_label(label_name, label)
                    else:
                        (conf, idx) = torch.max(softmax, dim=(- 1))
                        for (data_point, label_candidate, c, i) in zip(data_points, label_candidates, conf, idx):
                            label_value = self.label_dictionary.get_item_for_index(i.item())
                            if (label_value == 'O'):
                                continue
                            label = label_candidate.spawn(value=label_value, score=c.item())
                            data_point.add_complex_label(label_name, label)
            store_embeddings(batch, storage_mode=embedding_storage_mode)
        if return_loss:
            return (overall_loss, label_count)