Search code examples
pythonwarningspipelinehuggingface-transformers

HuggingFace Pipeline: UserWarning: `grouped_entities` is deprecated and will be removed in version v5.0.0. How to improve about this warning?


I am using the following code

!pip install datasets transformers[sentencepiece]
from transformers import pipeline
ner = pipeline("ner", grouped_entities=True, model='dbmdz/bert-large-cased-finetuned-conll03-english') #Named Entity Recognition (NER)
ner("My name is <Name> and I work at <Office> in <location>.")

And I got the following warning. How to improve upon this warning?

UserWarning: grouped_entities is deprecated and will be removed in version v5.0.0, defaulted to aggregation_strategy="AggregationStrategy.SIMPLE" instead.


Solution

  • According to [HuggingFace]: Pipelines - class transformers.TokenClassificationPipeline (emphasis is mine):

    • grouped_entities (bool, optional, defaults to False) - DEPRECATED, use aggregation_strategy instead. Whether or not to group the tokens corresponding to the same entity together in the predictions or not.

    So, your line of code could be:

    ner = pipeline("ner", aggregation_strategy="simple", model="dbmdz/bert-large-cased-finetuned-conll03-english")  # Named Entity Recognition (NER)