Embeddings Models¶
The embeddings models convert each word of an address into a vector that the Seq2Seq network then tags. The
AddressParser creates the right embeddings model for its model_type, so you only need
these classes to use the embeddings directly or to build your own pipeline:
the FastText models (
"fasttext"and"fasttext-attention") useFastTextEmbeddingsModel, which reads the French fastText.binembeddings,the FastText Light models (
"fasttext-light") useMagnitudeEmbeddingsModel, which reads the same embeddings in the Magnitude format,the BPEmb models (
"bpemb"and"bpemb-attention") useBPEmbEmbeddingsModel, which uses the byte-pair multilingual subword embeddings.
The FastText .bin embeddings are read by FastTextBinReader, our own reader of the fastText binary format.
It gives the same vectors as the fasttext package without depending on fasttext nor gensim, and its input
matrix is memory-mapped: it loads in a few seconds, only the rows used are kept in RAM, and the data loading workers
share its memory. It replaces the fasttext/gensim loader used up to version 0.11.0.
Interface¶
Implementations¶
- class deepparse.embeddings_models.FastTextEmbeddingsModel(embeddings_path: str, verbose: bool = True)[source]¶
FastText embeddings network from Enriching Word Vectors with Subword Information.
- Parameters:
Note
The embeddings are read with our own reader of the fastText
.binformat (FastTextBinReader), which gives the same vectors as thefasttextpackage without depending on it nor ongensim. The input matrix is memory-mapped, so the loading is fast and the data loading workers share its memory.
- class deepparse.embeddings_models.MagnitudeEmbeddingsModel(embeddings_path: str, verbose: bool = True)[source]¶
FastText embeddings network from Enriching Word Vectors with Subword Information using the magnitude mapping (Magnitude), which reduces the memory footprint.
- Parameters:
- class deepparse.embeddings_models.BPEmbEmbeddingsModel(cache_dir: str, verbose: bool = True)[source]¶
BPEmb embeddings network from BPEmb: Tokenization-free Pre-trained Subword Embeddings in 275 Languages. The arguments are the same as the BPEmb class
- Parameters:
FastText Binary Reader¶
- class deepparse.embeddings_models.FastTextBinReader(path: str)[source]¶
Reader of the Facebook fastText
.binformat (version 12, non-quantized, unsupervised models) that computes word vectors likeFastText::getWordVectorwithout thefasttextorgensimpackages.The input matrix is memory-mapped, so loading is fast, the RAM usage stays low, and the pages are shared between processes (e.g.
DataLoaderworkers). When pickled, only the path and the parsed dictionary are kept, and the memory map is reopened on unpickling.- Parameters:
path (str) – Path to the fastText
.binfile.
- get_dimension() int[source]¶
Return the dimension of the word vectors (same interface as the
fasttextmodel object).
- get_word_id(word: str) int[source]¶
Return the id of a word in the dictionary, or -1 if the word is out of vocabulary.
Factory¶
- class deepparse.embeddings_models.EmbeddingsModelFactory[source]¶
A factory for the creation of embeddings models.
- create(embedding_model_type: str, cache_dir: str, verbose: bool = True) EmbeddingsModel[source]¶
Embeddings model creation method.
- Parameters:
embedding_model_type (str) – the type of the embeddings model to create. Valid options are
"bpemb","fasttext","fasttext-light"(the Magnitude embeddings),"model2vec-8m","model2vec-32m"and"model2vec-multilingual".cache_dir (str) – Path to the cache directory where the embeddings model exists or is to be downloaded.
verbose (bool) – Whether or not to make the loading of the embeddings verbose.
- Returns: