Skip to content

Ft

FastTextEmbedding

Bases: AbstractEmbeddingModel

Class for embedding models using FastText model.

Source code in src/embedding/ft.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class FastTextEmbedding(AbstractEmbeddingModel):
    """
    Class for embedding models using FastText model.
    """

    def __init__(self, path: str, model: str = 'fastText', split_camel: bool = False):
        super().__init__(split_camel=split_camel)
        self._name = f'{model}'
        self.model = ft.load_model(path)

    def get_embedding(self, text: str) -> np.ndarray:
        """
        Returns the embedding of the text.
        :param text:
        :return:
        """
        if self._split_camel:
            text = ' '.join(self.split(text))
        return self.model.get_sentence_vector(text)

get_embedding(text)

Returns the embedding of the text.

Parameters:

Name Type Description Default
text str
required

Returns:

Type Description
ndarray
Source code in src/embedding/ft.py
17
18
19
20
21
22
23
24
25
def get_embedding(self, text: str) -> np.ndarray:
    """
    Returns the embedding of the text.
    :param text:
    :return:
    """
    if self._split_camel:
        text = ' '.join(self.split(text))
    return self.model.get_sentence_vector(text)