Skip to main content

finalfusion-python

Documentation Status

Introduction

finalfusion is a Python package for reading, writing and using finalfusion embeddings, but also supports other commonly used embeddings like fastText, GloVe and word2vec.

The Python package supports the same types of embeddings as the finalfusion-rust crate:

  • Vocabulary:
    • No subwords
    • Subwords
  • Embedding matrix:
    • Array
    • Memory-mapped
    • Quantized
  • Norms
  • Metadata

Installation

The finalfusion module is available on PyPi for Linux, Mac and Windows. You can use pip to install the module:

$ pip install --upgrade finalfusion

Installing from source

Building from source depends on Cython. If you install the package using pip, you don't need to explicitly install the dependency since it is specified in pyproject.toml.

$ git clone https://github.com/finalfusion/finalfusion-python
$ cd finalfusion-python
$ pip install .

If you want to build wheels from source, wheel needs to be installed. It's then possible to build wheels through:

$ python setup.py bdist_wheel

The wheels can be found in dist.

Package Usage

Basic usage

import finalfusion
# loading from different formats
w2v_embeds = finalfusion.load_word2vec("/path/to/w2v.bin")
text_embeds = finalfusion.load_text("/path/to/embeds.txt")
text_dims_embeds = finalfusion.load_text_dims("/path/to/embeds.dims.txt")
fasttext_embeds = finalfusion.load_fasttext("/path/to/fasttext.bin")
fifu_embeds = finalfusion.load_finalfusion("/path/to/embeddings.fifu")

# serialization to formats works similarly
finalfusion.compat.write_word2vec("to_word2vec.bin", fifu_embeds)

# embedding lookup
embedding = fifu_embeds["Test"]

# reading an embedding into a buffer
import numpy as np
buffer = np.zeros(fifu_embeds.storage.shape[1], dtype=np.float32)
fifu_embeds.embedding("Test", out=buffer)

# similarity and analogy query
sim_query = fifu_embeds.word_similarity("Test")
analogy_query = fifu_embeds.analogy("A", "B", "C")

# accessing the vocab and printing the first 10 words
vocab = fifu_embeds.vocab
print(vocab.words[:10])

# SubwordVocabs give access to the subword indexer:
subword_indexer = vocab.subword_indexer
print(subword_indexer.subword_indices("Test", with_ngrams=True))

# accessing the storage and calculate its dot product with an embedding
res = embedding.dot(fifu_embeds.storage)

# printing metadata
print(fifu_embeds.metadata) 

Beyond Embeddings

# load only a vocab from a finalfusion file
from finalfusion import load_vocab
vocab = load_vocab("/path/to/finalfusion_file.fifu")

# serialize vocab to single file
vocab.write("/path/to/vocab_file.fifu.voc")

# more specific loading functions exist
from finalfusion.vocab import load_finalfusion_bucket_vocab
fifu_bucket_vocab = load_finalfusion_bucket_vocab("/path/to/vocab_file.fifu.voc")

The package supports loading and writing all finalfusion chunks this way. This is only supported by the Python package, reading will fail with e.g. the finalfusion-rust.

Scripts

finalfusion also includes a conversion script ffp-convert to convert between the supported formats.

# convert from fastText format to finalfusion
$ ffp-convert -f fasttext fasttext.bin -t finalfusion embeddings.fifu

ffp-bucket-to-explicit can be used to convert bucket embeddings to embeddings with an explicit ngram lookup.

# convert finalfusion bucket embeddings to explicit
$ ffp-bucket-to-explicit -f finalfusion embeddings.fifu explicit.fifu

Finally, the package comes with ffp-similar and ffp-analogy to do analogy and similarity queries.

# get the 5 nearest neighbours of "Tübingen"
$ echo Tübingen | ffp-similar embeddings.fifu
# get the 5 top answers for "Tübingen" is to "Stuttgart" like "Heidelberg" to...
$ echo Tübingen Stuttgart Heidelberg | ffp-analogy embeddings.fifu

Where to go from here

Release files for finalfusion 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for finalfusion 0.7.1
File Size Uploaded
finalfusion-0.7.1.tar.gz 227.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for finalfusion 0.7.1
File
finalfusion-0.7.1-cp38-cp38m-win_amd64.whl CPython 3.8 CPython 3.8 pymalloc Windows x86-64 Details
finalfusion-0.7.1-cp38-cp38-manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
finalfusion-0.7.1-cp38-cp38-macosx_10_14_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.14+ x86-64 Details
finalfusion-0.7.1-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
finalfusion-0.7.1-cp37-cp37m-manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details
finalfusion-0.7.1-cp37-cp37m-macosx_10_14_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.14+ x86-64 Details
finalfusion-0.7.1-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
finalfusion-0.7.1-cp36-cp36m-manylinux2014_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64 Details
finalfusion-0.7.1-cp36-cp36m-macosx_10_14_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.14+ x86-64 Details

Total release size: 4.2 MB

Release files / finalfusion-0.7.1.tar.gz

Download URL finalfusion-0.7.1.tar.gz
Size 227.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f6a5f7b123fa573ad0a418261ef30e4516083bd4afc8db66ead322055d281f9f
BLAKE2b-256 checksum
How to use checksums
c668544cbd6e9b80fa70d7d181d0f615b396b34c6c5a5dc1b3c7d5bd64f4b028
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.10

Release files / finalfusion-0.7.1-cp38-cp38m-win_amd64.whl

Download URL finalfusion-0.7.1-cp38-cp38m-win_amd64.whl
Size 303.7 kB
Tags CPython 3.8 CPython 3.8 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
e6115a8a4e1e17280e781cbabea032233018c38cae9a610784a082b6a143dc67
BLAKE2b-256 checksum
How to use checksums
1ff5cb2b6608f8a468e64350be52205b34f6b29cf8e7c5a467ceb2d69da6b70c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release files / finalfusion-0.7.1-cp38-cp38-manylinux2014_x86_64.whl

Download URL finalfusion-0.7.1-cp38-cp38-manylinux2014_x86_64.whl
Size 780.2 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
bc9adbfa634f7f269ea880df1bf1f6f071c59ba378a66df499c813505bcc324e
BLAKE2b-256 checksum
How to use checksums
5d458b04d1a4efcac4611a78fe46f180a9748cbcb07c7c2fa1be24674cc35a14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.10

Release files / finalfusion-0.7.1-cp38-cp38-macosx_10_14_x86_64.whl

Download URL finalfusion-0.7.1-cp38-cp38-macosx_10_14_x86_64.whl
Size 298.0 kB
Tags CPython 3.8 macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
65cae920e09a23633f8921520307dcbffeb3f618fc95198415f607fd45695c99
BLAKE2b-256 checksum
How to use checksums
308702c8da9d67791b8ca4f21af73c53d3930c10a1d7160339fc5d23925f3e0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release files / finalfusion-0.7.1-cp37-cp37m-win_amd64.whl

Download URL finalfusion-0.7.1-cp37-cp37m-win_amd64.whl
Size 302.3 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
1479200d70e3588d01104d2b6d5986609a92aabcc7df8c66f95a37b36d199cad
BLAKE2b-256 checksum
How to use checksums
dbc3e316e9a3487e8d94a2f0b69847daf28af3fc25560f3af68e5e4bb1c8be33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

Release files / finalfusion-0.7.1-cp37-cp37m-manylinux2014_x86_64.whl

Download URL finalfusion-0.7.1-cp37-cp37m-manylinux2014_x86_64.whl
Size 689.1 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c0224bfd3c40e42a34c9f2c1620d994da2452cc974130f4589414fd60760f164
BLAKE2b-256 checksum
How to use checksums
d8e85a0b6f17bf23d0ff3faee78420089d799219f56b5f2f0e56c41cc4dea307
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.10

Release files / finalfusion-0.7.1-cp37-cp37m-macosx_10_14_x86_64.whl

Download URL finalfusion-0.7.1-cp37-cp37m-macosx_10_14_x86_64.whl
Size 296.7 kB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
b183d60c4ab02eb8610fb739df9da1579e6c393f9bb81e5116f651634821c502
BLAKE2b-256 checksum
How to use checksums
6a68a99546cfc4a4489ab314f00cb86b5db2a1d415b81dd6f3d81fa1e8c9830e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

Release files / finalfusion-0.7.1-cp36-cp36m-win_amd64.whl

Download URL finalfusion-0.7.1-cp36-cp36m-win_amd64.whl
Size 302.5 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
140c602f518881a4e7a36ebc01a2d027954e8ead57d210285a3c1b22883cdb83
BLAKE2b-256 checksum
How to use checksums
9067a6a10ca4a7be988568fe0e4e10faa642f01d96e1ffba5210238da31ab462
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.8

Release files / finalfusion-0.7.1-cp36-cp36m-manylinux2014_x86_64.whl

Download URL finalfusion-0.7.1-cp36-cp36m-manylinux2014_x86_64.whl
Size 688.6 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
dc3aff6798728ae684ef7ee7d3ecf7534ab594ebdb2a4b5a676d7559937d3d64
BLAKE2b-256 checksum
How to use checksums
7a2bcef007359f5ade9e8eb67f19159ff42d7008f35c0959344f6c75f8063499
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.10

Release files / finalfusion-0.7.1-cp36-cp36m-macosx_10_14_x86_64.whl

Download URL finalfusion-0.7.1-cp36-cp36m-macosx_10_14_x86_64.whl
Size 297.6 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
28f491d8f1bcd58ed0a077cce84dd04965c37c71529cf3f64838b9a08301e7e8
BLAKE2b-256 checksum
How to use checksums
b9a316017cdc236a709cf1ce344672c002fa6d583befacbace8b69b51182be1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.10

Release history Release notifications | RSS feed

This release

0.7.1 This release

10 release files

0.6.2

7 release files

0.6.1

9 release files

0.6.0

9 release files

0.5.0

8 release files

0.4.0

3 release files

0.3.1

11 release files

0.3.0

4 release files

0.2.0

9 release files

0.1.0

8 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page