class_docstr: predicts  classes for string-representation of sentence
class_docstr_tok: ["predicts","classes","for","string-representation","of","sentence"]
docstr: ```
  Makes predictions for a string-representation of a sentence
  Args:
    sentences(list|str): either a single sentence as a string or a list of sentences
    return_proba(bool): If return_proba is True, returns probability distribution for each token
    merge_tokens(bool):  If True, tokens will be merged together by the entity
                         to which they are associated:
                         ('Paul', 'B-PER'), ('Newman', 'I-PER') becomes ('Paul Newman', 'PER')
    custom_tokenizer(Callable): If specified, sentence will be tokenized based on custom tokenizer
    return_offsets(bool): If True, will return the chracter offsets in the results [experimental]
  
  Returns:
    list: If sentences is a string representation of single sentence:
               list containing a tuple for each token in sentence
          IF sentences is a list of sentences:
               list  of lists:  Each inner list represents a sentence and contains a tuple for each token in sentence
          If return_proba and return_offsets are both True, then tuples are of the form:  (token, label, probability, character offsets)
  ```
docstr_tok: ["``","`","Makes","predictions","for","a","string-representation","of","a","sentence","Args",":","sentences","(","list|str",")",":","either","a","single","sentence","as","a","string","or","a","list","of","sentences","return_proba","(","bool",")",":","If","return_proba","is","True",",","returns","probability","distribution","for","each","token","merge_tokens","(","bool",")",":","If","True",",","tokens","will","be","merged","together","by","the","entity","to","which","they","are","associated",":","(","'Paul","'",",","'","B-PER","'",")",",","(","'Newman","'",",","'","I-PER","'",")","becomes","(","'Paul","Newman","'",",","'PER","'",")","custom_tokenizer","(","Callable",")",":","If","specified",",","sentence","will","be","tokenized","based","on","custom","tokenizer","return_offsets","(","bool",")",":","If","True",",","will","return","the","chracter","offsets","in","the","results","[","experimental","]","Returns",":","list",":","If","sentences","is","a","string","representation","of","single","sentence",":","list","containing","a","tuple","for","each","token","in","sentence","IF","sentences","is","a","list","of","sentences",":","list","of","lists",":","Each","inner","list","represents","a","sentence","and","contains","a","tuple","for","each","token","in","sentence","If","return_proba","and","return_offsets","are","both","True",",","then","tuples","are","of","the","form",":","(","token",",","label",",","probability",",","character","offsets",")","``","`"]
code: def predict(
      self,
      sentences,
      return_proba=False,
      merge_tokens=False,
      custom_tokenizer=None,
      return_offsets=False,
  ):
      """
      ```
      Makes predictions for a string-representation of a sentence
      Args:
        sentences(list|str): either a single sentence as a string or a list of sentences
        return_proba(bool): If return_proba is True, returns probability distribution for each token
        merge_tokens(bool):  If True, tokens will be merged together by the entity
                             to which they are associated:
                             ('Paul', 'B-PER'), ('Newman', 'I-PER') becomes ('Paul Newman', 'PER')
        custom_tokenizer(Callable): If specified, sentence will be tokenized based on custom tokenizer
        return_offsets(bool): If True, will return the chracter offsets in the results [experimental]
  
      Returns:
        list: If sentences is a string representation of single sentence:
                   list containing a tuple for each token in sentence
              IF sentences is a list of sentences:
                   list  of lists:  Each inner list represents a sentence and contains a tuple for each token in sentence
              If return_proba and return_offsets are both True, then tuples are of the form:  (token, label, probability, character offsets)
      ```
      """
      is_array = not isinstance(sentences, str)
      if not isinstance(sentences, (str, list)):
          raise ValueError(
              "Param sentence must be either string-representation of a sentence or a list of sentence strings."
          )
      # if return_proba and merge_tokens:
      #     raise ValueError(
      #         "return_proba and merge_tokens are mutually exclusive with one another."
      #     )
      if isinstance(sentences, str):
          sentences = [sentences]
      lang = TU.detect_lang(sentences)
  
      # batchify
      num_chunks = math.ceil(len(sentences) / self.batch_size)
      batches = U.list2chunks(sentences, n=num_chunks)
  
      # process batches
      results = []
      for batch in batches:
          nerseq = self.preproc.preprocess(
              batch, lang=lang, custom_tokenizer=custom_tokenizer
          )
          if not nerseq.prepare_called:
              nerseq.prepare()
          nerseq.batch_size = len(batch)
          x_true, _ = nerseq[0]
          lengths = nerseq.get_lengths(0)
          y_pred = self.model.predict_on_batch(x_true)
          y_labels = self.preproc.p.inverse_transform(y_pred, lengths)
          # TODO: clean this up
          if return_proba:
              try:
                  probs = np.max(y_pred, axis=2)
              except:
                  probs = (
                      y_pred[0].numpy().tolist()
                  )  # TODO: remove after confirmation (#316)
              for i, (x, y, prob) in enumerate(
                  zip(nerseq.x, y_labels, probs)
              ):
                  if return_offsets:
                      offsets = TU.extract_offsets(
                          sentences[i], tokens=[entry[0] for entry in x]
                      )
                      result = [
                          (
                              x[i],
                              y[i],
                              prob[i],
                              (offsets[i]["start"], offsets[i]["end"]),
                          )
                          for i in range(len(x))
                      ]
                  else:
                      result = [
                          (x[i], y[i], prob[i]) for i in range(len(x))
                      ]
                  if merge_tokens:
                      result = self.merge_tokens(result, lang, True)
                  results.append(result)
          else:
              for i, (x, y) in enumerate(zip(nerseq.x, y_labels)):
                  if return_offsets:
                      offsets = TU.extract_offsets(
                          sentences[i], tokens=[entry[0] for entry in x]
                      )
                      result = list(
                          zip(
                              x,
                              y,
                              [(o["start"], o["end"]) for o in offsets],
                          )
                      )
                  else:
                      result = list(zip(x, y))
                  if merge_tokens:
                      result = self.merge_tokens(result, lang, False)
                  results.append(result)
      if not is_array:
          results = results[0]
      return results
  
file_path: ktrain/ktrain/text/ner/predictor.py
imports: from ...None import utils
  from ...imports import *
  from ...predictor import Predictor
  from ..None import textutils
  from .preprocessor import NERPreprocessor
label_desc: Use image node_id 3 for calling the NERPredictor obj's underlying member method code with example usage: obj.predict(sentences, return_proba, merge_tokens, custom_tokenizer, return_offsets) and returns: results