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",")","."]
code: def aggregate_word(
      self,
      entities: List[dict],
      aggregation_strategy: AggregationStrategy,
  ) -> dict:
      word = self.tokenizer.convert_tokens_to_string(
          [entity["word"] for entity in entities]
      )
      if aggregation_strategy == AggregationStrategy.FIRST:
          scores = entities[0]["scores"]
          idx = scores.argmax()
          score = scores[idx]
          entity = self.model.config.id2label[idx]
      elif aggregation_strategy == AggregationStrategy.MAX:
          max_entity = max(
              entities, key=lambda entity: entity["scores"].max()
          )
          scores = max_entity["scores"]
          idx = scores.argmax()
          score = scores[idx]
          entity = self.model.config.id2label[idx]
      elif aggregation_strategy == AggregationStrategy.AVERAGE:
          scores = np.stack([entity["scores"] for entity in entities])
          average_scores = np.nanmean(scores, axis=0)
          entity_idx = average_scores.argmax()
          entity = self.model.config.id2label[entity_idx]
          score = average_scores[entity_idx]
      else:
          raise ValueError("Invalid aggregation_strategy")
      new_entity = {
          "entity": entity,
          "score": score,
          "word": word,
          "start": entities[0]["start"],
          "end": entities[-1]["end"],
      }
      return new_entity
  
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 9 for calling the TokenClassificationPipeline obj's underlying member method code with example usage: obj.aggregate_word(entities, aggregation_strategy) and returns: new_entity