Norms

Norms module.

class ffp.norms.Norms[source]

Bases: numpy.ndarray, ffp.io.Chunk

Embedding Norms.

Norms subclass numpy.ndarray, all typical numpy operations are available.

The ith norm is expected to correspond to the l2 norm of the ith row in the storage before normalizing it. Therefore, Norms should have at most the same length as a given Storage and are expected to match the length of the Vocabulary.

static chunk_identifier()[source]

Get the ChunkIdentifier for this Chunk.

Returns

chunk_identifier

Return type

ChunkIdentifier

static read_chunk(file: BinaryIO)ffp.norms.Norms[source]

Read the Chunk and return it.

The file must be positioned before the contents of the Chunk but after its header.

Parameters

file (BinaryIO) – a finalfusion file containing the given Chunk

Returns

chunk – The chunk read from the file.

Return type

Chunk

write_chunk(file: BinaryIO)[source]

Write the Chunk to a file.

Parameters

file (BinaryIO) – Output file for the Chunk

ffp.norms.load_norms(file: Union[str, bytes, int, os.PathLike])ffp.norms.Norms[source]

Load an Norms chunk from the given file.

Parameters

file (str, bytes, int, PathLike) – Finalfusion file with a norms chunk.

Returns

storage – The Norms from the file.

Return type

Norms

Raises

ValueError – If the file did not contain an Norms chunk.