Skip to content

Commit

Permalink
Update top-k documentation (#5948)
Browse files Browse the repository at this point in the history
### Description
Redo of PR #5826 (which has stalled), extended to address another issue
in the documentation.

Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
  • Loading branch information
gramalingam committed Feb 27, 2024
1 parent 833575e commit ff60ddc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 42 deletions.
36 changes: 18 additions & 18 deletions docs/Changelog.md
Expand Up @@ -4364,10 +4364,10 @@ This version of the operator has been available since version 1 of the default O
### <a name="TopK-1"></a>**TopK-1**</a>

Retrieve the top-K elements along a specified axis. Given an input tensor of
shape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs:
-Value tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n]
shape [a_0, a_1, ..., a_{n-1}] and integer argument k, return two outputs:
-Value tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}]
which contains the values of the top k elements along the specified axis
-Index tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] which
-Index tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] which
contains the indices of the top k elements (original indices from the input
tensor).
Given two equivalent values, this operator uses the indices along the axis as
Expand All @@ -4390,16 +4390,16 @@ This version of the operator has been available since version 1 of the default O

<dl>
<dt><tt>X</tt> : T</dt>
<dd>Tensor of shape [a_1, a_2, ..., a_n, r]</dd>
<dd>Tensor of shape [a_0, a_1, ..., a_{n-1}]</dd>
</dl>

#### Outputs

<dl>
<dt><tt>Values</tt> : T</dt>
<dd>Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing top K values from the input tensor</dd>
<dd>Tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] containing top K values from the input tensor</dd>
<dt><tt>Indices</tt> : I</dt>
<dd>Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing the corresponding input tensor indices for the top K values.</dd>
<dd>Tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] containing the corresponding input tensor indices for the top K values.</dd>
</dl>

#### Type Constraints
Expand Down Expand Up @@ -10239,10 +10239,10 @@ This version of the operator has been available since version 10 of the default
### <a name="TopK-10"></a>**TopK-10**</a>

Retrieve the top-K elements along a specified axis. Given an input tensor of
shape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs:
-Value tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n]
shape [a_0, a_1, ..., a_{n-1}] and integer argument k, return two outputs:
-Value tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}]
which contains the values of the top k elements along the specified axis
-Index tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] which
-Index tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] which
contains the indices of the top k elements (original indices from the input
tensor).

Expand All @@ -10264,7 +10264,7 @@ This version of the operator has been available since version 10 of the default

<dl>
<dt><tt>X</tt> : T</dt>
<dd>Tensor of shape [a_1, a_2, ..., a_n, r]</dd>
<dd>Tensor of shape [a_0, a_1, ..., a_{n-1}]</dd>
<dt><tt>K</tt> : tensor(int64)</dt>
<dd>A 1-D tensor containing a single positive value corresponding to the number of top elements to retrieve</dd>
</dl>
Expand All @@ -10273,9 +10273,9 @@ This version of the operator has been available since version 10 of the default

<dl>
<dt><tt>Values</tt> : T</dt>
<dd>Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing top K values from the input tensor</dd>
<dd>Tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] containing top K values from the input tensor</dd>
<dt><tt>Indices</tt> : I</dt>
<dd>Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing the corresponding input tensor indices for the top K values.</dd>
<dd>Tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] containing the corresponding input tensor indices for the top K values.</dd>
</dl>

#### Type Constraints
Expand Down Expand Up @@ -13672,11 +13672,11 @@ This version of the operator has been available since version 11 of the default
### <a name="TopK-11"></a>**TopK-11**</a>

Retrieve the top-K largest or smallest elements along a specified axis. Given an input tensor of
shape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs:
shape [a_0, a_1, ..., a_{n-1}] and integer argument k, return two outputs:

* Value tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n]
* Value tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}]
which contains the values of the top k elements along the specified axis
* Index tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] which
* Index tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] which
contains the indices of the top k elements (original indices from the input
tensor).

Expand Down Expand Up @@ -13706,7 +13706,7 @@ This version of the operator has been available since version 11 of the default

<dl>
<dt><tt>X</tt> (differentiable) : T</dt>
<dd>Tensor of shape [a_1, a_2, ..., a_n, r]</dd>
<dd>Tensor of shape [a_0, a_1, ..., a_{n-1}]</dd>
<dt><tt>K</tt> (non-differentiable) : tensor(int64)</dt>
<dd>A 1-D tensor containing a single positive value corresponding to the number of top elements to retrieve</dd>
</dl>
Expand All @@ -13715,9 +13715,9 @@ This version of the operator has been available since version 11 of the default

<dl>
<dt><tt>Values</tt> (differentiable) : T</dt>
<dd>Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing top K values from the input tensor</dd>
<dd>Tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] containing top K values from the input tensor</dd>
<dt><tt>Indices</tt> (non-differentiable) : I</dt>
<dd>Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing the corresponding input tensor indices for the top K values.</dd>
<dd>Tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] containing the corresponding input tensor indices for the top K values.</dd>
</dl>

#### Type Constraints
Expand Down
12 changes: 6 additions & 6 deletions docs/Operators.md
Expand Up @@ -33533,11 +33533,11 @@ expect(node, inputs=[x, repeats], outputs=[z], name="test_tile_precomputed")
### <a name="TopK"></a><a name="topk">**TopK**</a>

Retrieve the top-K largest or smallest elements along a specified axis. Given an input tensor of
shape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs:
shape [a_0, a_1, ..., a_{n-1}] and integer argument k, return two outputs:

* Value tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n]
* Value tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}]
which contains the values of the top k elements along the specified axis
* Index tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] which
* Index tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] which
contains the indices of the top k elements (original indices from the input
tensor).

Expand Down Expand Up @@ -33569,7 +33569,7 @@ Other versions of this operator: <a href="Changelog.md#TopK-1">1</a>, <a href="C

<dl>
<dt><tt>X</tt> (differentiable) : T</dt>
<dd>Tensor of shape [a_1, a_2, ..., a_n, r]</dd>
<dd>Tensor of shape [a_0, a_1, ..., a_{n-1}]</dd>
<dt><tt>K</tt> (non-differentiable) : tensor(int64)</dt>
<dd>A 1-D tensor containing a single positive value corresponding to the number of top elements to retrieve</dd>
</dl>
Expand All @@ -33578,9 +33578,9 @@ Other versions of this operator: <a href="Changelog.md#TopK-1">1</a>, <a href="C

<dl>
<dt><tt>Values</tt> (differentiable) : T</dt>
<dd>Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing top K values from the input tensor</dd>
<dd>Tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] containing top K values from the input tensor</dd>
<dt><tt>Indices</tt> (non-differentiable) : I</dt>
<dd>Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] containing the corresponding input tensor indices for the top K values.</dd>
<dd>Tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] containing the corresponding input tensor indices for the top K values.</dd>
</dl>

#### Type Constraints
Expand Down
12 changes: 6 additions & 6 deletions onnx/defs/math/defs.cc
Expand Up @@ -1415,11 +1415,11 @@ ONNX_OPERATOR_SET_SCHEMA(

static const char* TopK_ver11_doc = R"DOC(
Retrieve the top-K largest or smallest elements along a specified axis. Given an input tensor of
shape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs:
shape [a_0, a_1, ..., a_{n-1}] and integer argument k, return two outputs:
* Value tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n]
* Value tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}]
which contains the values of the top k elements along the specified axis
* Index tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] which
* Index tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] which
contains the indices of the top k elements (original indices from the input
tensor).
Expand All @@ -1439,7 +1439,7 @@ ONNX_OPERATOR_SET_SCHEMA(
.Input(
0,
"X",
"Tensor of shape [a_1, a_2, ..., a_n, r]",
"Tensor of shape [a_0, a_1, ..., a_{n-1}]",
"T",
OpSchema::Single,
true,
Expand All @@ -1457,7 +1457,7 @@ ONNX_OPERATOR_SET_SCHEMA(
.Output(
0,
"Values",
"Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] "
"Tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] "
"containing top K values from the input tensor",
"T",
OpSchema::Single,
Expand All @@ -1467,7 +1467,7 @@ ONNX_OPERATOR_SET_SCHEMA(
.Output(
1,
"Indices",
"Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] "
"Tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] "
"containing the corresponding input tensor indices for the top K "
"values.",
"I",
Expand Down
24 changes: 12 additions & 12 deletions onnx/defs/math/old.cc
Expand Up @@ -2631,10 +2631,10 @@ ONNX_OPERATOR_SET_SCHEMA(

static const char* TopK_ver1_doc = R"DOC(
Retrieve the top-K elements along a specified axis. Given an input tensor of
shape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs:
-Value tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n]
shape [a_0, a_1, ..., a_{n-1}] and integer argument k, return two outputs:
-Value tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}]
which contains the values of the top k elements along the specified axis
-Index tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] which
-Index tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] which
contains the indices of the top k elements (original indices from the input
tensor).
Given two equivalent values, this operator uses the indices along the axis as
Expand All @@ -2646,17 +2646,17 @@ ONNX_OPERATOR_SET_SCHEMA(
1,
OpSchema()
.SetDoc(TopK_ver1_doc)
.Input(0, "X", "Tensor of shape [a_1, a_2, ..., a_n, r]", "T")
.Input(0, "X", "Tensor of shape [a_0, a_1, ..., a_{n-1}]", "T")
.Output(
0,
"Values",
"Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] "
"Tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] "
"containing top K values from the input tensor",
"T")
.Output(
1,
"Indices",
"Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] "
"Tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] "
"containing the corresponding input tensor indices for the top K "
"values.",
"I")
Expand Down Expand Up @@ -2697,10 +2697,10 @@ ONNX_OPERATOR_SET_SCHEMA(

static const char* TopK_ver10_doc = R"DOC(
Retrieve the top-K elements along a specified axis. Given an input tensor of
shape [a_1, a_2, ..., a_n, r] and integer argument k, return two outputs:
-Value tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n]
shape [a_0, a_1, ..., a_{n-1}] and integer argument k, return two outputs:
-Value tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}]
which contains the values of the top k elements along the specified axis
-Index tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] which
-Index tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] which
contains the indices of the top k elements (original indices from the input
tensor).
Expand All @@ -2713,7 +2713,7 @@ ONNX_OPERATOR_SET_SCHEMA(
10,
OpSchema()
.SetDoc(TopK_ver10_doc)
.Input(0, "X", "Tensor of shape [a_1, a_2, ..., a_n, r]", "T")
.Input(0, "X", "Tensor of shape [a_0, a_1, ..., a_{n-1}]", "T")
.Input(
1,
"K",
Expand All @@ -2722,13 +2722,13 @@ ONNX_OPERATOR_SET_SCHEMA(
.Output(
0,
"Values",
"Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] "
"Tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] "
"containing top K values from the input tensor",
"T")
.Output(
1,
"Indices",
"Tensor of shape [a_1, a_2, ..., a_{axis-1}, k, a_{axis+1}, ... a_n] "
"Tensor of shape [a_0, a_1, ..., a_{axis-1}, k, a_{axis+1}, ... a_{n-1}] "
"containing the corresponding input tensor indices for the top K "
"values.",
"I")
Expand Down

0 comments on commit ff60ddc

Please sign in to comment.