WOLFRAM

represents a net that takes a pair of arrays, embeds them into a vector space using net, and outputs the distance under the embedding.

includes options for distance function to use and other parameters.

Details and Options

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

Create a NetPairEmbeddingOperator that embeds inputs using a NetChain:

Out[1]=1

Create a NetPairEmbeddingOperator that embeds a pair of length-2 vectors using a randomly initialized NetChain:

Out[1]=1

Apply the net to a pair of input vectors:

Out[2]=2

Thread the layer across a batch of input vectors:

Out[3]=3

Scope  (1)Survey of the scope of standard use cases

Create a NetGraph with one input and output:

Out[1]=1

Create a NetPairEmbeddingOperator that embeds vectors using a NetGraph:

Out[2]=2

The embedding network in NetPairEmbeddingOperator[net] can be extracted using NetExtract:

Out[3]=3

Options  (1)Common values & functionality for each option

DistanceFunction  (1)

Create a NetPairEmbeddingOperator that uses the CosineDistance function to calculate the distance between the two embedded arrays:

Out[1]=1

Apply the layer to a pair of input vectors:

Out[2]=2

Applications  (2)Sample problems that can be solved with this function

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:

Out[2]=2

Create the perceptron:

Use NetPairEmbeddingOperator to define a loss network that measures the performance of the embedding:

Out[4]=4

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:

Out[6]=6

Train the network, using a generator to sample pairs of points, and classify them as the same if their original parameterization was close:

Out[7]=7

Extract the embedding from the net:

Plot the 1D embedding learned by the net as a color map:

Out[9]=9

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:

Out[4]=4

Define a convolutional network to use as an embedding network:

Out[5]=5

Construct the pair-embedding net:

Out[6]=6

Train the network:

Out[7]=7

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:

Out[8]=8

Extract the embedding network:

Out[9]=9

Compute the embedding of a digit:

Out[10]=10

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:

Out[13]=13

Properties & Relations  (1)Properties of the function, and connections to other functions

NetMapOperator can be used to implement NetPairEmbeddingOperator. Create an initialized LinearLayer:

Out[1]=1

Create NetPairEmbeddingOperator using the linear layer as its embedding net, and evaluate it on an input:

Out[2]=2
Out[3]=3

Define a NetGraph with a NetMapOperator that is equivalent to the previous NetPairEmbeddingOperator, and evaluate it on the same input:

Out[4]=4
Out[5]=5

Possible Issues  (1)Common pitfalls and unexpected behavior

Nets with multiple inputs or outputs cannot be used as the embedding network in NetPairEmbeddingOperator[net]:

Out[1]=1
Wolfram Research (2017), NetPairEmbeddingOperator, Wolfram Language function, https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html (updated 2020).
Wolfram Research (2017), NetPairEmbeddingOperator, Wolfram Language function, https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html (updated 2020).

Text

Wolfram Research (2017), NetPairEmbeddingOperator, Wolfram Language function, https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html (updated 2020).

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.

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

Wolfram Language. (2017). NetPairEmbeddingOperator. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html

BibTeX

@misc{reference.wolfram_2025_netpairembeddingoperator, author="Wolfram Research", title="{NetPairEmbeddingOperator}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html}", note=[Accessed: 08-June-2025 ]}

@misc{reference.wolfram_2025_netpairembeddingoperator, author="Wolfram Research", title="{NetPairEmbeddingOperator}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html}", note=[Accessed: 08-June-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_netpairembeddingoperator, organization={Wolfram Research}, title={NetPairEmbeddingOperator}, year={2020}, url={https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html}, note=[Accessed: 08-June-2025 ]}

@online{reference.wolfram_2025_netpairembeddingoperator, organization={Wolfram Research}, title={NetPairEmbeddingOperator}, year={2020}, url={https://reference.wolfram.com/language/ref/NetPairEmbeddingOperator.html}, note=[Accessed: 08-June-2025 ]}