class_docstr: Named Entity Recognition pipeline using any `ModelForTokenClassification`. See the [named entity recognition
  examples](../task_summary#named-entity-recognition) for more information.
  
  This token recognition pipeline can currently be loaded from [`pipeline`] using the following task identifier:
  `"ner"` (for predicting the classes of tokens in a sequence: person, organisation, location or miscellaneous).
  
  The models that this pipeline can use are models that have been fine-tuned on a token classification task. See the
  up-to-date list of available models on
  [huggingface.co/models](https://huggingface.co/models?filter=token-classification).
class_docstr_tok: ["Named","Entity","Recognition","pipeline","using","any","`","ModelForTokenClassification","`",".","See","the","[","named","entity","recognition","examples","]","(","..","\/task_summary","#","named-entity-recognition",")","for","more","information",".","This","token","recognition","pipeline","can","currently","be","loaded","from","[","`","pipeline","`","]","using","the","following","task","identifier",":","`","``","ner","''","`","(","for","predicting","the","classes","of","tokens","in","a","sequence",":","person",",","organisation",",","location","or","miscellaneous",")",".","The","models","that","this","pipeline","can","use","are","models","that","have","been","fine-tuned","on","a","token","classification","task",".","See","the","up-to-date","list","of","available","models","on","[","huggingface.co\/models","]","(","https",":","\/\/huggingface.co\/models","?","filter=token-classification",")","."]
docstr: Find and group together the adjacent tokens with the same entity predicted.
  
  Args:
      entities (`dict`): The entities predicted by the pipeline.
docstr_tok: ["Find","and","group","together","the","adjacent","tokens","with","the","same","entity","predicted",".","Args",":","entities","(","`","dict","`",")",":","The","entities","predicted","by","the","pipeline","."]
code: def group_entities(self, entities: List[dict]) -> List[dict]:
      """
      Find and group together the adjacent tokens with the same entity predicted.
  
      Args:
          entities (`dict`): The entities predicted by the pipeline.
      """
  
      entity_groups = []
      entity_group_disagg = []
  
      for entity in entities:
          if not entity_group_disagg:
              entity_group_disagg.append(entity)
              continue
  
          # If the current entity is similar and adjacent to the previous entity,
          # append it to the disaggregated entity group
          # The split is meant to account for the "B" and "I" prefixes
          # Shouldn't merge if both entities are B-type
          bi, tag = self.get_tag(entity["entity"])
          last_bi, last_tag = self.get_tag(
              entity_group_disagg[-1]["entity"]
          )
  
          if tag == last_tag and bi != "B":
              # Modify subword type to be previous_type
              entity_group_disagg.append(entity)
          else:
              # If the current entity is different from the previous entity
              # aggregate the disaggregated entity group
              entity_groups.append(
                  self.group_sub_entities(entity_group_disagg)
              )
              entity_group_disagg = [entity]
      if entity_group_disagg:
          # it's the last entity, add it to the entity groups
          entity_groups.append(
              self.group_sub_entities(entity_group_disagg)
          )
  
      return entity_groups
  
imports: import types
  import warnings
  from typing import List, Optional, Tuple, Union
  import numpy
  from ..models.bert.tokenization_bert import BasicTokenizer
  from ..utils import ExplicitEnum, add_end_docstrings, is_tf_available, is_torch_available
  from .base import PIPELINE_INIT_ARGS, ArgumentHandler, Dataset, Pipeline
label_desc: Use image node_id 13 for calling the TokenClassificationPipeline obj's underlying member method code with example usage: obj.group_entities(entities) and returns: entity_groups