neupy.layers.embedding module

class neupy.layers.embedding.Embedding[source]

Embedding layer accepts indeces as an input and returns rows from the weight matrix associated with these indeces. Useful in case of categorical features or for the word embedding tasks.

Parameters:

input_size : int

Layer’s input vector dimension. Usualy associated with number of categories or number of unique words that input vector has.

output_size : int

Layer’s output vector dimension.

weight : array-like, Tensorfow variable, scalar or Initializer

Defines layer’s weights. Default initialization methods you can find here. Defaults to HeNormal().

name : str or None

Layer’s identifier. If name is equal to None than name will be generated automatically. Defaults to None.

Examples

This example converts dataset that has only categorical variables into format that suitable for Embedding layer.

>>> import numpy as np
>>> from neupy import layers
>>>
>>> dataset = np.array([
...     ['cold', 'high'],
...     ['hot',  'low'],
...     ['cold', 'low'],
...     ['hot',  'low'],
... ])
>>>
>>> unique_value, dataset_indeces = np.unique(
...     dataset, return_inverse=True
... )
>>> dataset_indeces = dataset_indeces.reshape((4, 2))
>>> dataset_indeces
array([[0, 1],
       [2, 3],
       [0, 3],
       [2, 3]])
>>>
>>> n_features = dataset.shape[1]
>>> n_unique_categories = len(unique_value)
>>> embedded_size = 1
>>>
>>> connection = layers.join(
...     layers.Input(n_features),
...     layers.Embedding(n_unique_categories, embedded_size),
...     # Output from the embedding layer is 3D
...     # To make output 2D we need to reshape dimensions
...     layers.Reshape(),
... )

Attributes

input_shape (tuple) Layer’s input shape.
output_shape (tuple) Layer’s output shape.
training_state (bool) Defines whether layer in training state or not.
parameters (dict) Trainable parameters.
graph (LayerGraph instance) Graphs that stores all relations between layers.

Methods

disable_training_state() Swith off trainig state.
initialize() Set up important configurations related to the layer.
initialize()[source]

Initialize connection

input_size = None[source]
options = {'name': Option(class_name='BaseLayer', value=Property(name="name")), 'input_size': Option(class_name='Embedding', value=IntProperty(name="input_size")), 'output_size': Option(class_name='Embedding', value=IntProperty(name="output_size")), 'weight': Option(class_name='Embedding', value=ParameterProperty(name="weight"))}[source]
output(input_value)[source]

Return output base on the input value.

Parameters:input_value
output_shape[source]
output_size = None[source]
weight = None[source]