提交 a18cf5e1 编写于 作者: F FDInSky 提交者: lvmengsi

add a argument for softshrink python api (#19396)

* test=develop add a argument for softshrink python api

* test=develop fix doc format 

test=develop fix doc format

* test=develop fix API.spec

test=develop fix API.spec
上级 d6c85c96
......@@ -372,7 +372,6 @@ paddle.fluid.layers.exp (ArgSpec(args=['x', 'name'], varargs=None, keywords=None
paddle.fluid.layers.tanh (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'f820eeaf81dfbdd1c360122cd5795cc8'))
paddle.fluid.layers.atan (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '2dde114018cbcaff9b24c566bf6704a5'))
paddle.fluid.layers.tanh_shrink (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '63d198e36e1d85dcfb454c1a3cb3b38e'))
paddle.fluid.layers.softshrink (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '4f53a5e7f50c55ea516375ef8f46316b'))
paddle.fluid.layers.sqrt (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '893ec81a025f3c82f1c8fca6aa84d39f'))
paddle.fluid.layers.rsqrt (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'c629f5163fa04f80abb3d0240c462fa6'))
paddle.fluid.layers.abs (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'f6d5642f52e357f3cec89cc9c15dc66c'))
......@@ -388,6 +387,7 @@ paddle.fluid.layers.square (ArgSpec(args=['x', 'name'], varargs=None, keywords=N
paddle.fluid.layers.softplus (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'be4533a4cd97c84424512dca76142083'))
paddle.fluid.layers.softsign (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '410f27a44b7365cc60d5d5ff5a53407e'))
paddle.fluid.layers.uniform_random (ArgSpec(args=['shape', 'dtype', 'min', 'max', 'seed'], varargs=None, keywords=None, defaults=('float32', -1.0, 1.0, 0)), ('document', '6de6775d9e9ed885056e764982130cfd'))
paddle.fluid.layers.softshrink (ArgSpec(args=['x', 'alpha'], varargs=None, keywords=None, defaults=(None,)), ('document', '958c7bfdfb0b5e92af6ca4a90d24e5ef'))
paddle.fluid.layers.hard_shrink (ArgSpec(args=['x', 'threshold'], varargs=None, keywords=None, defaults=(None,)), ('document', '386a4103d2884b2f1312ebc1e8ee6486'))
paddle.fluid.layers.cumsum (ArgSpec(args=['x', 'axis', 'exclusive', 'reverse'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', '5ab9d5721a6734fe127069e4314e1309'))
paddle.fluid.layers.thresholded_relu (ArgSpec(args=['x', 'threshold'], varargs=None, keywords=None, defaults=(None,)), ('document', '9a0464425426a9b9c1b7500ede2836c1'))
......
......@@ -25,7 +25,6 @@ __activations_noattr__ = [
'tanh',
'atan',
'tanh_shrink',
'softshrink',
'sqrt',
'rsqrt',
'abs',
......@@ -97,6 +96,49 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0):
return _uniform_random_(**kwargs)
__all__ += ['softshrink']
_softshrink_ = generate_layer_fn('softshrink')
def softshrink(x, alpha=None):
locals_var = locals().copy()
kwargs = dict()
for name, val in locals_var.items():
if val is not None:
if name == 'alpha':
kwargs['lambda'] = val
else:
kwargs[name] = val
return _softshrink_(**kwargs)
softshrink.__doc__ = """
:strong:`Softshrink Activation Operator`
.. math::
out = \begin{cases}
x - \alpha, \text{if } x > \alpha \\
x + \alpha, \text{if } x < -\alpha \\
0, \text{otherwise}
\end{cases}
Args:
x: Input of Softshrink operator
alpha (FLOAT): non-negative offset
Returns:
Output of Softshrink operator
Examples:
.. code-block:: python
import paddle.fluid as fluid
data = fluid.layers.data(name="input", shape=[784])
result = fluid.layers.softshrink(x=data, alpha=0.3)
"""
__all__ += ['hard_shrink']
_hard_shrink_ = generate_layer_fn('hard_shrink')
......
......@@ -1813,7 +1813,7 @@ class TestBook(LayerTest):
with program_guard(fluid.default_main_program(),
fluid.default_startup_program()):
input = self._get_data(name="input", shape=[16], dtype="float32")
out = layers.softshrink(input, name='softshrink')
out = layers.softshrink(input, alpha=0.3)
return (out)
def make_iou_similarity(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册