embfile.initializers

Embedding initializers.

Classes

Initializer()

A random number generator meant to be used with build_matrix().

NormalInitializer()

Generates vectors using a normal distribution with the same mean and standard deviation of the set of vectors passed to the fit method.

Functions

normal([mean, deviation])

Returns a normal sampler.

Reference

class embfile.initializers.Initializer[source]

Bases: abc.ABC

A random number generator meant to be used with build_matrix(). It can be fit to a sequence of other vectors in order to compute stats to be used for generation. When passed to build_matrix, the initializer is fit to the found vectors.

abstractmethod __call__(shape)[source]

(Abstract method) Generate an array of shape shape

Return type

ndarray

abstractmethod fit(vectors)[source]

(Abstract method) Computes stats that will be use for generating new vectors.

Parameters

vectors (ndarray) –

class embfile.initializers.NormalInitializer[source]

Bases: embfile.initializers.Initializer

Generates vectors using a normal distribution with the same mean and standard deviation of the set of vectors passed to the fit method. When used with build_matrix(), it initializes out-of-file-vocabulary vectors so that they have the same mean and deviation of the vectors found in the file.

If not fit before to generate vectors, it raises IllegalOperation

fit(vectors)[source]

Computes mean and standard deviation of the input vectors

embfile.initializers.normal(mean=0.0, deviation=None)[source]

Returns a normal sampler. If deviation is not given, it is set dynamically to

1.0 / sqrt(shape[-1])

where shape[-1] is the vector size.