lib.ner_bert package

Submodules

lib.ner_bert.inference module

class lib.ner_bert.inference.Bert(nr_tags, weights_path=None)

Bases: abc.ABC

Abstract Base Class for the BERT to be used in the pipeline. Has a factory method create_bert that returns either a real BERT in TensorFlow-style based on a .ht weights file or a mocked BERT. PyTorch is no longer supported.

abstract __call__(sentences)
Parameters:

sentences – Sentences to do NER on

Returns:

Predictions in numpy array form, it is left to the data supplier class to handle the translation to

readable values.

abstract __init__(nr_tags, weights_path=None)
Parameters:
  • nr_tags (int) – Number of tags used by the BERT

  • weights_path (Optional[str]) – Path to the weights file.

classmethod create_bert(vocab, weights_path)
Parameters:
  • vocab (Tuple[str, …]) – Number of tags used by the BERT

  • weights_path (str) – Path to the weights file.

Returns:

An instance of the appropriate BERT class, determined by the extension of the weights file:

  • .h5 results in a TensorFlow BERT

  • no extension, e.g. by passing an empty string for the weights, results in a mocked BERT

Other implementations are no longer supported.

lib.ner_bert.ner_bert module