nlptest.modelhandler.transformers_modelhandler.PretrainedModelForNER#

class PretrainedModelForNER(model)#

Bases: _ModelHandler

Parameters:

model (transformers.pipeline.Pipeline) – Pretrained HuggingFace NER pipeline for predictions.

__init__(model)#
model#

Loaded NER pipeline for predictions.

Type:

transformers.pipeline.Pipeline

Methods

__init__(model)

model#

group_entities(entities)

Find and group together the adjacent tokens with the same entity predicted.

load_model(path)

Load the NER model into the model attribute.

predict(text, **kwargs)

Perform predictions on the input text.

predict_raw(text)

Predict a list of labels.

group_entities(entities: List[Dict]) List[Dict]#

Find and group together the adjacent tokens with the same entity predicted. Inspired and adapted from: huggingface/transformers

Parameters:

entities (List[Dict]) – The entities predicted by the pipeline.

Returns:

grouped entities

Return type:

List[Dict]

classmethod load_model(path: str) Pipeline#

Load the NER model into the model attribute.

Parameters:

path (str) – path to model or model name

Return type:

‘Pipeline’

predict(text: str, **kwargs) NEROutput#

Perform predictions on the input text.

Parameters:
  • text (str) – Input text to perform NER on.

  • kwargs – Additional keyword arguments.

Keyword Arguments:

group_entities (bool) – Option to group entities.

Returns:

A list of named entities recognized in the input text.

Return type:

NEROutput

predict_raw(text: str) List[str]#

Predict a list of labels. :param text: Input text to perform NER on. :type text: str

Returns:

A list of named entities recognized in the input text.

Return type:

List[str]