speechbrain.lobes.models.flair.sequencetagger module

Models and tooling for sequence tagging using Flair

Authors * Sylvain de Langen 2024

Summary

Classes:

FlairSequenceTagger

Sequence tagger using the flair toolkit, e.g. for part-of-speech (POS) extraction.

Reference

class speechbrain.lobes.models.flair.sequencetagger.FlairSequenceTagger(model: flair.models.SequenceTagger)[source]

Bases: object

Sequence tagger using the flair toolkit, e.g. for part-of-speech (POS) extraction.

Parameters:

model (SequenceTagger) – The Flair sequence tagger model. If you do not have one initialized, use from_hf() instead.

static from_hf(source, save_path='./model_checkpoints', filename='pytorch_model.bin') FlairSequenceTagger[source]

Fetches and load a flair PyTorch model according to the speechbrain.utils.fetching.fetch() semantics. The model will be saved into a unique subdirectory in save_path.

Parameters:
  • source (str) – The location of the model (a directory or HF repo, for instance).

  • save_path (str, optional) – The saving location for the model (i.e. the root for the download or symlink location).

  • filename (str, optional) – The filename of the model. The default is the usual filename for this kind of model.

Return type:

FlairSequenceTagger

__call__(inputs: List[str] | List[List[str]]) List[List[str]][source]

Tag a batch of sentences.

Parameters:

inputs (list of sentences (str or list of tokens)) – Sentences to tag, in the form of batches of lists of tokens (list of str) or a str. In the case of token lists, tokens do not need to be already tokenized for this specific sequence tagger.

Returns:

For each sentence, the sequence of extracted tags as `str`s.

Return type:

list of list of str