nlptest.modelhandler.modelhandler.ModelFactory#

class ModelFactory(model: str, task: str, hub: str, *args, **kwargs)#

Bases: object

A factory class for instantiating models.

__init__(model: str, task: str, hub: str, *args, **kwargs)#

Initializes the ModelFactory object. :param model: path to the model to evaluate :type model: str :param task: task to perform :type task: str

Raises:
  • ValueError – If the task specified is not supported.

  • ValueError – If the given model is not supported.

Methods

__init__(model, task, hub, *args, **kwargs)

Initializes the ModelFactory object.

load_model(task, hub, path, *args, **kwargs)

Loads the model.

predict(text, **kwargs)

Perform predictions on input text.

predict_raw(text)

Perform predictions on input text.

Attributes

SUPPORTED_HUBS

SUPPORTED_MODULES

SUPPORTED_TASKS

classmethod load_model(task: str, hub: str, path: str, *args, **kwargs) ModelFactory#

Loads the model.

Parameters:
  • path (str) – path to model to use

  • task (str) – task to perform

  • hub (str) – model hub to load custom model from the path, either to hub or local disk.

Returns

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

Perform predictions on input text.

Parameters:

text (str) – Input text to perform predictions on.

Returns:

predicted output

Return type:

Union[NEROutput, SequenceClassificationOutput]

predict_raw(text: str) List[str]#

Perform predictions on input text.

Parameters:

text (str) – Input text to perform predictions on.

Returns:

Predictions.

Return type:

List[str]