Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
strategy_embedding
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rank
strategy_embedding
Commits
2281c903
Commit
2281c903
authored
Nov 24, 2020
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add example
parent
7845ae89
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
answer_similarity.py
answer_similarity.py
+32
-0
No files found.
answer_similarity.py
0 → 100644
View file @
2281c903
import
numpy
as
np
from
bert_serving.client
import
BertClient
def
cos_sim
(
vector_a
,
vector_b
):
"""
计算两个向量之间的余弦相似度
:param vector_a: 向量 a
:param vector_b: 向量 b
:return: sim
"""
vector_a
=
np
.
mat
(
vector_a
)
vector_b
=
np
.
mat
(
vector_b
)
num
=
float
(
vector_a
*
vector_b
.
T
)
denom
=
np
.
linalg
.
norm
(
vector_a
)
*
np
.
linalg
.
norm
(
vector_b
)
cos
=
num
/
denom
sim
=
0.5
+
0.5
*
cos
return
sim
bc
=
BertClient
(
"172.16.44.82"
)
sentence
=
"""
<p>做完私处整形手术,最好在一个月以后进行同房。因为过早同房,可能会对女性的私处造成损伤,甚至可能出现感染的情况。在恢复期间,女性可以适当的多吃水果蔬菜,多喝水,保持体内水分的充足。尽量不要吃刺激性过强的食物。在平时要注意私处的卫生,如果私处有瘙痒的情况,尽量不要用手直接的抓挠,坚持每天更换内裤,不要擅自用妇科清洗液,可以用温水轻轻擦拭私处。如果私处有不适感,需要及时去医院进行检查并治疗。</p>
"""
sen1_em
=
bc
.
encode
([
sentence
])
sen2_em
=
bc
.
encode
([
sentence
])
print
(
type
(
sen1_em
),
sen1_em
)
print
(
sen2_em
)
print
(
cos_sim
(
sen1_em
,
sen2_em
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment