@@ -7560,14 +7560,17 @@ def similarity_focus(input, axis, indexes, name=None):
7560
7560
SimilarityFocus Operator
7561
7561
7562
7562
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
7564
7564
to the axis according to the indexes. For example, if axis=1 and indexes=[a],
7565
7565
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.
7571
7574
3. Broadcast the 3-D similarity focus mask to the same shape of input X.
7572
7575
7573
7576
Refer to `Similarity Focus Layer <http://www.aclweb.org/anthology/N16-1108>`_
@@ -7624,9 +7627,9 @@ def similarity_focus(input, axis, indexes, name=None):
7624
7627
Args:
7625
7628
input(Variable): The input tensor variable(default float). It should
7626
7629
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
7628
7631
1, 2 or 3.
7629
- indexes(list): indicating the indexes of the selected dimension.
7632
+ indexes(list): Indicating the indexes of the selected dimension.
7630
7633
7631
7634
Returns:
7632
7635
Variable: A tensor variable with the same shape and same type
@@ -7649,7 +7652,11 @@ def similarity_focus(input, axis, indexes, name=None):
7649
7652
if len (indexes ) == 0 :
7650
7653
raise ValueError ("indexes can not be empty." )
7651
7654
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 )
7653
7660
helper .append_op (
7654
7661
type = 'similarity_focus' ,
7655
7662
inputs = {'X' : input },
0 commit comments