Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
612b81c5
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
612b81c5
编写于
11月 30, 2022
作者:
C
ccrrong
提交者:
GitHub
11月 30, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove cos_sim (#48501)
上级
e9b4c6e7
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
24 addition
and
81 deletion
+24
-81
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+0
-38
python/paddle/fluid/tests/book/test_recommender_system.py
python/paddle/fluid/tests/book/test_recommender_system.py
+3
-1
python/paddle/fluid/tests/unittests/dist_fleet_simnet_bow.py
python/paddle/fluid/tests/unittests/dist_fleet_simnet_bow.py
+2
-2
python/paddle/fluid/tests/unittests/dygraph_to_static/simnet_dygraph_model.py
...tests/unittests/dygraph_to_static/simnet_dygraph_model.py
+1
-1
python/paddle/fluid/tests/unittests/test_cos_sim_op.py
python/paddle/fluid/tests/unittests/test_cos_sim_op.py
+0
-21
python/paddle/fluid/tests/unittests/test_dist_fleet_ps.py
python/paddle/fluid/tests/unittests/test_dist_fleet_ps.py
+2
-2
python/paddle/fluid/tests/unittests/test_dist_fleet_ps11.py
python/paddle/fluid/tests/unittests/test_dist_fleet_ps11.py
+2
-2
python/paddle/fluid/tests/unittests/test_dist_fleet_ps12.py
python/paddle/fluid/tests/unittests/test_dist_fleet_ps12.py
+2
-2
python/paddle/fluid/tests/unittests/test_dist_fleet_ps13.py
python/paddle/fluid/tests/unittests/test_dist_fleet_ps13.py
+2
-2
python/paddle/fluid/tests/unittests/test_dist_fleet_ps2.py
python/paddle/fluid/tests/unittests/test_dist_fleet_ps2.py
+2
-2
python/paddle/fluid/tests/unittests/test_dist_fleet_ps3.py
python/paddle/fluid/tests/unittests/test_dist_fleet_ps3.py
+2
-2
python/paddle/fluid/tests/unittests/test_dist_fleet_ps4.py
python/paddle/fluid/tests/unittests/test_dist_fleet_ps4.py
+2
-2
python/paddle/fluid/tests/unittests/test_dist_fleet_ps5.py
python/paddle/fluid/tests/unittests/test_dist_fleet_ps5.py
+2
-2
python/paddle/fluid/tests/unittests/test_dist_fleet_ps6.py
python/paddle/fluid/tests/unittests/test_dist_fleet_ps6.py
+2
-2
未找到文件。
python/paddle/fluid/layers/nn.py
浏览文件 @
612b81c5
...
...
@@ -67,7 +67,6 @@ __all__ = [
'embedding'
,
'linear_chain_crf'
,
'crf_decoding'
,
'cos_sim'
,
'conv2d'
,
'softmax'
,
'pool2d'
,
...
...
@@ -1005,43 +1004,6 @@ def crf_decoding(input, param_attr, label=None, length=None):
return
viterbi_path
@
templatedoc
()
def
cos_sim
(
X
,
Y
):
"""
${comment}
Args:
X (Tensor): ${x_comment}.
Y (Tensor): ${y_comment}.
Returns:
A Tensor representing the output of cosine(X, Y).
Examples:
.. code-block:: python
import paddle
x = paddle.rand(shape=[3, 7], dtype='float32')
y = paddle.rand(shape=[1, 7], dtype='float32')
out = paddle.fluid.layers.cos_sim(x, y)
print(out)
"""
check_variable_and_dtype
(
X
,
'X'
,
[
'float32'
],
'cos_sim'
)
check_variable_and_dtype
(
Y
,
'Y'
,
[
'float32'
],
'cos_sim'
)
helper
=
LayerHelper
(
'cos_sim'
,
**
locals
())
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
X
.
dtype
)
xnorm
=
helper
.
create_variable_for_type_inference
(
dtype
=
X
.
dtype
)
ynorm
=
helper
.
create_variable_for_type_inference
(
dtype
=
X
.
dtype
)
helper
.
append_op
(
type
=
'cos_sim'
,
inputs
=
{
'X'
:
[
X
],
'Y'
:
[
Y
]},
outputs
=
{
'Out'
:
[
out
],
'XNorm'
:
[
xnorm
],
'YNorm'
:
[
ynorm
]},
)
return
out
@
deprecated
(
since
=
"2.0.0"
,
update_to
=
"paddle.nn.functional.dropout"
)
def
dropout
(
x
,
...
...
python/paddle/fluid/tests/book/test_recommender_system.py
浏览文件 @
612b81c5
...
...
@@ -161,7 +161,9 @@ def model():
mov_combined_features
=
get_mov_combined_features
()
# need cos sim
inference
=
layers
.
cos_sim
(
X
=
usr_combined_features
,
Y
=
mov_combined_features
)
inference
=
paddle
.
nn
.
functional
.
cosine_similarity
(
x1
=
usr_combined_features
,
x2
=
mov_combined_features
)
scale_infer
=
paddle
.
scale
(
x
=
inference
,
scale
=
5.0
)
label
=
layers
.
data
(
name
=
'score'
,
shape
=
[
1
],
dtype
=
'float32'
)
...
...
python/paddle/fluid/tests/unittests/dist_fleet_simnet_bow.py
浏览文件 @
612b81c5
...
...
@@ -192,8 +192,8 @@ def train_network(
),
bias_attr
=
fluid
.
ParamAttr
(
name
=
"__fc_b__"
),
)
cos_q_pt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
pt_fc
)
cos_q_nt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
nt_fc
)
cos_q_pt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
pt_fc
)
cos_q_nt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
nt_fc
)
# loss
avg_cost
=
get_loss
(
cos_q_pt
,
cos_q_nt
)
# acc
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/simnet_dygraph_model.py
浏览文件 @
612b81c5
...
...
@@ -136,7 +136,7 @@ class CosSimLayer:
"""
operation
"""
sim
=
fluid
.
layers
.
cos_sim
(
x
,
y
)
sim
=
paddle
.
nn
.
functional
.
cosine_similarity
(
x
,
y
)
return
sim
...
...
python/paddle/fluid/tests/unittests/test_cos_sim_op.py
浏览文件 @
612b81c5
...
...
@@ -17,9 +17,6 @@ import unittest
import
numpy
as
np
from
op_test
import
OpTest
import
paddle.fluid
as
fluid
from
paddle.fluid
import
Program
,
program_guard
class
TestCosSimOp
(
OpTest
):
def
setUp
(
self
):
...
...
@@ -121,23 +118,5 @@ class TestCosSimOp4(TestCosSimOp):
}
class
TestCosSimOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
program_guard
(
Program
(),
Program
()):
# the input of batch_norm must be Variable.
x1
=
fluid
.
create_lod_tensor
(
np
.
array
([
-
1
,
3
,
5
,
5
]),
[[
1
,
1
,
1
,
1
]],
fluid
.
CPUPlace
()
)
x2
=
fluid
.
create_lod_tensor
(
np
.
array
([
-
1
,
3
,
5
,
5
]),
[[
1
,
1
,
1
,
1
]],
fluid
.
CPUPlace
()
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
cos_sim
,
x1
,
x2
)
# the input dtype of batch_norm must be float32
x3
=
fluid
.
layers
.
data
(
name
=
'x3'
,
shape
=
[
3
,
4
,
5
,
6
],
dtype
=
"int32"
)
x4
=
fluid
.
layers
.
data
(
name
=
'x4'
,
shape
=
[
3
,
4
,
5
,
6
],
dtype
=
"int64"
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
cos_sim
,
x3
,
x4
)
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_dist_fleet_ps.py
浏览文件 @
612b81c5
...
...
@@ -162,8 +162,8 @@ class TestPSPassWithBow(unittest.TestCase):
),
bias_attr
=
fluid
.
ParamAttr
(
name
=
"__fc_b__"
),
)
cos_q_pt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
pt_fc
)
cos_q_nt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
nt_fc
)
cos_q_pt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
pt_fc
)
cos_q_nt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
nt_fc
)
# loss
avg_cost
=
get_loss
(
cos_q_pt
,
cos_q_nt
)
# acc
...
...
python/paddle/fluid/tests/unittests/test_dist_fleet_ps11.py
浏览文件 @
612b81c5
...
...
@@ -150,8 +150,8 @@ class TestPSPassWithBow(unittest.TestCase):
),
bias_attr
=
fluid
.
ParamAttr
(
name
=
"__fc_b__"
),
)
cos_q_pt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
pt_fc
)
cos_q_nt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
nt_fc
)
cos_q_pt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
pt_fc
)
cos_q_nt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
nt_fc
)
# loss
avg_cost
=
get_loss
(
cos_q_pt
,
cos_q_nt
)
# acc
...
...
python/paddle/fluid/tests/unittests/test_dist_fleet_ps12.py
浏览文件 @
612b81c5
...
...
@@ -153,8 +153,8 @@ class TestPSPassWithBow(unittest.TestCase):
),
bias_attr
=
fluid
.
ParamAttr
(
name
=
"__fc_b__"
),
)
cos_q_pt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
pt_fc
)
cos_q_nt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
nt_fc
)
cos_q_pt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
pt_fc
)
cos_q_nt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
nt_fc
)
# loss
avg_cost
=
get_loss
(
cos_q_pt
,
cos_q_nt
)
# acc
...
...
python/paddle/fluid/tests/unittests/test_dist_fleet_ps13.py
浏览文件 @
612b81c5
...
...
@@ -160,8 +160,8 @@ class TestPSPassWithBow(unittest.TestCase):
),
bias_attr
=
fluid
.
ParamAttr
(
name
=
"__fc_b__"
),
)
cos_q_pt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
pt_fc
)
cos_q_nt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
nt_fc
)
cos_q_pt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
pt_fc
)
cos_q_nt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
nt_fc
)
# loss
avg_cost
=
get_loss
(
cos_q_pt
,
cos_q_nt
)
# acc
...
...
python/paddle/fluid/tests/unittests/test_dist_fleet_ps2.py
浏览文件 @
612b81c5
...
...
@@ -160,8 +160,8 @@ class TestPSPassWithBow(unittest.TestCase):
),
bias_attr
=
fluid
.
ParamAttr
(
name
=
"__fc_b__"
),
)
cos_q_pt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
pt_fc
)
cos_q_nt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
nt_fc
)
cos_q_pt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
pt_fc
)
cos_q_nt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
nt_fc
)
# loss
avg_cost
=
get_loss
(
cos_q_pt
,
cos_q_nt
)
# acc
...
...
python/paddle/fluid/tests/unittests/test_dist_fleet_ps3.py
浏览文件 @
612b81c5
...
...
@@ -162,8 +162,8 @@ class TestPSPassWithBow(unittest.TestCase):
),
bias_attr
=
fluid
.
ParamAttr
(
name
=
"__fc_b__"
),
)
cos_q_pt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
pt_fc
)
cos_q_nt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
nt_fc
)
cos_q_pt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
pt_fc
)
cos_q_nt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
nt_fc
)
# loss
avg_cost
=
get_loss
(
cos_q_pt
,
cos_q_nt
)
# acc
...
...
python/paddle/fluid/tests/unittests/test_dist_fleet_ps4.py
浏览文件 @
612b81c5
...
...
@@ -156,8 +156,8 @@ class TestPSPassWithBow(unittest.TestCase):
),
bias_attr
=
fluid
.
ParamAttr
(
name
=
"__fc_b__"
),
)
cos_q_pt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
pt_fc
)
cos_q_nt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
nt_fc
)
cos_q_pt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
pt_fc
)
cos_q_nt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
nt_fc
)
# loss
avg_cost
=
get_loss
(
cos_q_pt
,
cos_q_nt
)
# acc
...
...
python/paddle/fluid/tests/unittests/test_dist_fleet_ps5.py
浏览文件 @
612b81c5
...
...
@@ -162,8 +162,8 @@ class TestPSPassWithBow(unittest.TestCase):
),
bias_attr
=
fluid
.
ParamAttr
(
name
=
"__fc_b__"
),
)
cos_q_pt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
pt_fc
)
cos_q_nt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
nt_fc
)
cos_q_pt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
pt_fc
)
cos_q_nt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
nt_fc
)
# loss
avg_cost
=
get_loss
(
cos_q_pt
,
cos_q_nt
)
# acc
...
...
python/paddle/fluid/tests/unittests/test_dist_fleet_ps6.py
浏览文件 @
612b81c5
...
...
@@ -156,8 +156,8 @@ class TestPSPassWithBow(unittest.TestCase):
),
bias_attr
=
fluid
.
ParamAttr
(
name
=
"__fc_b__"
),
)
cos_q_pt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
pt_fc
)
cos_q_nt
=
fluid
.
layers
.
cos_sim
(
q_fc
,
nt_fc
)
cos_q_pt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
pt_fc
)
cos_q_nt
=
paddle
.
nn
.
functional
.
cosine_similarity
(
q_fc
,
nt_fc
)
# loss
avg_cost
=
get_loss
(
cos_q_pt
,
cos_q_nt
)
# acc
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录