Skip to content

Commit 5e7bb6a

Browse files
committed
update docs test=develop
1 parent 316e020 commit 5e7bb6a

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

paddle/fluid/operators/similarity_focus_op.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ class SimilarityFocusOpMaker : public framework::OpProtoAndCheckerMaker {
3535
SimilarityFocus Operator.
3636
3737
Generate a similarity focus mask with the same shape of input using the following method:
38-
1. Extract the 4-D matrix(here the first dimension is BatchSize) corresponding
39-
to the axis according to the indexes. For example, if axis=1 and indexes=[a],
40-
it will get the matrix T=X[:, a, :, :]. In this case, if the shape of input X
41-
is (BatchSize, A, B, C), the shape of matrix T is (BatchSize, B, C).
42-
2. For each index, find the largest numbers in the matrix T, so that the same
43-
row and same column has at most one number(obviously there will be min(B, C)
44-
numbers), and mark the corresponding position of the 3-D similarity focus mask
45-
as 1, otherwise as 0. Do elementwise-or for each index.
38+
1. Extract the 3-D tensor(here the first dimension is BatchSize) corresponding
39+
to the axis according to the indexes. For example, if axis=1 and indexes=[a],
40+
it will get the matrix T=X[:, a, :, :]. In this case, if the shape of input X
41+
is (BatchSize, A, B, C), the shape of tensor T is (BatchSize, B, C).
42+
2. For each index, find the largest numbers in the tensor T, so that the same
43+
row and same column has at most one number(what it means is that if the
44+
largest number has been found in the i-th row and the j-th column, then
45+
the numbers in the i-th or j-th column will be skipped. Obviously there
46+
will be min(B, C) numbers), and mark the corresponding position of the
47+
3-D similarity focus mask as 1, otherwise as 0. Do elementwise-or for
48+
each index.
4649
3. Broadcast the 3-D similarity focus mask to the same shape of input X.
4750
4851
Refer to `Similarity Focus Layer <http://www.aclweb.org/anthology/N16-1108>`_

python/paddle/fluid/layers/nn.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7560,14 +7560,17 @@ def similarity_focus(input, axis, indexes, name=None):
75607560
SimilarityFocus Operator
75617561
75627562
Generate a similarity focus mask with the same shape of input using the following method:
7563-
1. Extract the 4-D matrix(here the first dimension is BatchSize) corresponding
7563+
1. Extract the 3-D tensor(here the first dimension is BatchSize) corresponding
75647564
to the axis according to the indexes. For example, if axis=1 and indexes=[a],
75657565
it will get the matrix T=X[:, a, :, :]. In this case, if the shape of input X
7566-
is (BatchSize, A, B, C), the shape of matrix T is (BatchSize, B, C).
7567-
2. For each index, find the largest numbers in the matrix T, so that the same
7568-
row and same column has at most one number(obviously there will be min(B, C)
7569-
numbers), and mark the corresponding position of the 3-D similarity focus mask
7570-
as 1, otherwise as 0. Do elementwise-or for each index.
7566+
is (BatchSize, A, B, C), the shape of tensor T is (BatchSize, B, C).
7567+
2. For each index, find the largest numbers in the tensor T, so that the same
7568+
row and same column has at most one number(what it means is that if the
7569+
largest number has been found in the i-th row and the j-th column, then
7570+
the numbers in the i-th or j-th column will be skipped. Obviously there
7571+
will be min(B, C) numbers), and mark the corresponding position of the
7572+
3-D similarity focus mask as 1, otherwise as 0. Do elementwise-or for
7573+
each index.
75717574
3. Broadcast the 3-D similarity focus mask to the same shape of input X.
75727575
75737576
Refer to `Similarity Focus Layer <http://www.aclweb.org/anthology/N16-1108>`_
@@ -7624,9 +7627,9 @@ def similarity_focus(input, axis, indexes, name=None):
76247627
Args:
76257628
input(Variable): The input tensor variable(default float). It should
76267629
be a 4-D tensor with shape [BatchSize, A, B, C].
7627-
axis(int): Indicating the dimension to be select. It can only be
7630+
axis(int): Indicating the dimension to be selected. It can only be
76287631
1, 2 or 3.
7629-
indexes(list): indicating the indexes of the selected dimension.
7632+
indexes(list): Indicating the indexes of the selected dimension.
76307633
76317634
Returns:
76327635
Variable: A tensor variable with the same shape and same type
@@ -7649,7 +7652,11 @@ def similarity_focus(input, axis, indexes, name=None):
76497652
if len(indexes) == 0:
76507653
raise ValueError("indexes can not be empty.")
76517654

7652-
out = helper.create_tmp_variable(dtype=helper.input_dtype())
7655+
if name is None:
7656+
out = helper.create_variable_for_type_inference(dtype=input.dtype)
7657+
else:
7658+
out = helper.create_variable(
7659+
name=name, dtype=input.dtype, persistable=False)
76537660
helper.append_op(
76547661
type='similarity_focus',
76557662
inputs={'X': input},

0 commit comments

Comments
 (0)