speechbrain.lobes.models.flair.embeddings moduleο
Wrappers for Flair embedding classes
Authors * Sylvain de Langen 2024
Summaryο
Classes:
Simple wrapper for generic Flair embeddings. |
Referenceο
- class speechbrain.lobes.models.flair.embeddings.FlairEmbeddings(embeddings: flair.embeddings.Embeddings)[source]ο
Bases:
object
Simple wrapper for generic Flair embeddings.
- Parameters:
embeddings (Embeddings) β The Flair embeddings object. If you do not have one initialized, use
from_hf()
instead.
- static from_hf(embeddings_class, source, save_path='./model_checkpoints', filename='model.bin', *args, **kwargs) FlairEmbeddings [source]ο
Fetches and load flair embeddings according to the
speechbrain.utils.fetching.fetch()
semantics. Embedding files will be saved into a unique subdirectory insave_path
.- Parameters:
embeddings_class (class) β The class to use to initialize the model, e.g.
FastTextEmbeddings
.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.
*args β Extra positional arguments to pass to the flair class constructor
**kwargs β Extra keyword arguments to pass to the flair class constructor
- Return type:
- __call__(inputs: List[str] | List[List[str]], pad_tensor: Tensor = tensor([0.])) Tensor [source]ο
Extract embeddings for a batch of sentences.
- Parameters:
inputs (list of sentences (str or list of tokens)) β Sentences to embed, 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. However, a token may be considered as a single word. Similarly, out-of-vocabulary handling depends on the underlying embedding class.
pad_tensor (torch.Tensor, optional) β What embedding tensor (of shape
[]
, living on the same device as the embeddings to insert as padding.
- Returns:
Batch of shape
[len(inputs), max_len, embed_size]
- Return type:
torch.Tensor