HuggingFace 管道:用户警告:`grouped_entities` 已弃用,将在 v5.0.0 版中删除。如何改进这个警告?

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

我正在使用以下代码

!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>.")

然后我收到了以下警告。如何改进这个警告?

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

根据[HuggingFace]: Pipelines - class transformers.TokenClassificationPipeline强调是我的):

  • grouped_entitiesbool可选,默认为 False)- 已弃用,请使用 aggregation_strategy 代替 。是否在预测中将对应于同一实体的标记组合在一起。

因此,您的代码行可能是:

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