NetPairEmbeddingOperator
represents a net that takes a pair of arrays, embeds them into a vector space using net, and outputs the distance under the embedding.
NetPairEmbeddingOperator[net,opts]
includes options for distance function to use and other parameters.
Details and Options
- In NetPairEmbeddingOperator[net], net should take exactly one input and produce exactly one output.
- NetExtract can be used to extract net from a NetPairEmbeddingOperator[net] object.
- The following optional parameter can be included:
-
DistanceFunction EuclideanDistance distance function to use LearningRateMultipliers Automatic learning rate multipliers for trainable arrays in the net - The following values of DistanceFunction are supported:
-
EuclideanDistance Euclidean distance between inputs CosineDistance cosine distance between inputs - The input and output ports of the net represented by NetPairEmbeddingOperator are:
-
"Input" a pair of arrays "Output" a real number - When it cannot be inferred from other layers in a larger net, the option "Input"->{n1,n2,…} can be used to fix the input dimensions of each of the pair of input arrays of NetPairEmbeddingOperator.
- When a NetPairEmbeddingOperator is trained, NetTrain will automatically attach a ContrastiveLossLayer if a loss is not specified.
- NetExtract allows access to the forward and reverse nets via "Net".
- Options[NetPairEmbeddingOperator] gives the list of default options to construct the operator. Options[NetPairEmbeddingOperator[…]] gives the list of default options to evaluate the operator on some data.
- Information[NetPairEmbeddingOperator[…]] gives a report about the operator.
- Information[NetPairEmbeddingOperator[…],prop] gives the value of the property prop of NetPairEmbeddingOperator[…]. Possible properties are the same as for NetGraph.
Examples
open allclose allBasic Examples (2)
Create a NetPairEmbeddingOperator that embeds inputs using a NetChain:
Create a NetPairEmbeddingOperator that embeds a pair of length-2 vectors using a randomly initialized NetChain:
Scope (1)
Create a NetGraph with one input and output:
Create a NetPairEmbeddingOperator that embeds vectors using a NetGraph:
The embedding network in NetPairEmbeddingOperator[net] can be extracted using NetExtract:
Options (1)
DistanceFunction (1)
Create a NetPairEmbeddingOperator that uses the CosineDistance function to calculate the distance between the two embedded arrays:
Applications (2)
Train a multilayer perceptron to embed a synthetic dataset based only on its topology. First, create the training data on a spiral-like manifold that is dense in the plane:
Use NetPairEmbeddingOperator to define a loss network that measures the performance of the embedding:
Create a generator that will sample pairs of points and associate them with True if their parameterization on the manifold differs by more than Pi:
Train the network, using a generator to sample pairs of points, and classify them as the same if their original parameterization was close:
Extract the embedding from the net:
Plot the 1D embedding learned by the net as a color map:
Learn an embedding of the digits in the MNIST dataset. First, import the data and take only those examples with labels between 0 and 4:
Create a training set by sampling pairs of images and associating them with True if their labels are different and False if their labels are the same:
Define a convolutional network to use as an embedding network:
Construct the pair-embedding net:
Apply the network to a list of pairs of digits to compute their distances under the embedding. Digits with the same label have small distances:
Extract the embedding network:
Compute the embedding of a digit:
Sample 500 digits and group them by their labels:
Compute their embeddings and plot them. Digits with the same label are clustered under the learned embedding:
Properties & Relations (1)
NetMapOperator can be used to implement NetPairEmbeddingOperator. Create an initialized LinearLayer:
Create NetPairEmbeddingOperator using the linear layer as its embedding net, and evaluate it on an input:
Define a NetGraph with a NetMapOperator that is equivalent to the previous NetPairEmbeddingOperator, and evaluate it on the same input:
Possible Issues (1)
Nets with multiple inputs or outputs cannot be used as the embedding network in NetPairEmbeddingOperator[net]:
Text
Wolfram Research (2017), NetPairEmbeddingOperator, Wolfram Language function, https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html (updated 2020).
CMS
Wolfram Language. 2017. "NetPairEmbeddingOperator." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html.
APA
Wolfram Language. (2017). NetPairEmbeddingOperator. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html