Loading TOC...

cntk:cosine-distance-with-negative-samples

cntk:cosine-distance-with-negative-samples(
   $left-operand as cntk:variable,
   $right-operand as cntk:variable,
   $shift-window as xs:integer,
   $number-of-negative-samples as xs:integer,
   [$name as xs:string]
) as cntk:function

Summary

Given minibatches for x and y, this function computes for each element in x the cosine distance between it and the corresponding y and additionally the cosine distance between x and some other elements of y (referred to a negative samples). The x and y pairs are samples often derived from embeddings of textual data, though the function can be used for any form of numeric encodings. When using this function to compute textual similarity, x represents search query term embedding and y represents a document embedding. The negative samples are formed on the fly by shifting the right side (y). The shift indicates how many samples in y one should shift while forming each negative sample pair. It is often chosen to be 1. As the name suggests num_negative_samples indicates how many negative samples one would want to generate.

Parameters
$left-operand The left operand of the operation.
$right-operand The right operand of the operation.
$shift-window Non-zero positive integer representing number of shift to generate a negative sample.
$number-of-negative-samples Number of negative samples to generate, a non-zero positive integer.
$name The name of the function instance in the network.

Example

  let $input-variable1 := cntk:input-variable(cntk:shape((3)), "float",
    fn:false(), fn:false(), "feature")
  let $input-variable2 := cntk:input-variable(cntk:shape((3)), "float",
    fn:false(), fn:false(), "feature")
  return cntk:cosine-distance-with-negative-samples($input-variable2,
    $input-variable1, 599241700, 17, "cosine-distance-with-negative-samples")
  => cntk:function(Composite CosDistanceWithNegativeSamples (Input(Name(feature),
  Shape([3]), Dynamic Axes([Sequence Axis(Default Dynamic Axis),
  Batch Axis(Default Batch Axis)])), Input(Name(feature), Shape([3]),
  Dynamic Axes([Sequence Axis(Default Dynamic Axis), Batch Axis(Default Batch Axis)]))))

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.