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
91c45347
Commit
91c45347
authored
Nov 26, 2020
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add business_tags
parent
cdb95f79
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
match_api.py
personas_vector/match_api.py
+17
-17
No files found.
personas_vector/match_api.py
View file @
91c45347
...
@@ -23,24 +23,24 @@ def match_tractate_by_device(device_id, n=10):
...
@@ -23,24 +23,24 @@ def match_tractate_by_device(device_id, n=10):
if
device_id
not
in
[
"0"
,
"unknown"
,
"87654"
]:
if
device_id
not
in
[
"0"
,
"unknown"
,
"87654"
]:
time_begin
=
time
.
time
()
time_begin
=
time
.
time
()
business_tags
=
get_user_portrait_tag3_from_redis
(
device_id
,
tags_num
=
3
)
.
get
(
"business_tags"
,
[])
business_tags
=
get_user_portrait_tag3_from_redis
(
device_id
,
tags_num
=
3
)
.
get
(
"business_tags"
,
[])
# business_tags = ["假体下巴", "你好", "假体隆胸"]
res
=
[]
res
=
[]
vectors
=
[]
if
business_tags
:
for
tag
in
business_tags
:
vectors
=
[]
lst
=
json
.
loads
(
TAG_EMBEDDING_DICT
.
get
(
bytes
(
tag
,
"utf-8"
),
b
"[]"
))
for
tag
in
business_tags
:
if
lst
:
lst
=
json
.
loads
(
TAG_EMBEDDING_DICT
.
get
(
bytes
(
tag
,
"utf-8"
),
b
"[]"
))
vectors
.
append
(
np
.
array
(
lst
)
.
astype
(
"float32"
))
if
lst
:
if
vectors
:
vectors
.
append
(
np
.
array
(
lst
)
.
astype
(
"float32"
))
D
,
I
=
FAISS_TAGS_INDEX
.
search
(
np
.
array
([
np
.
average
(
vectors
,
axis
=
0
)])
.
astype
(
"float32"
),
n
)
if
vectors
:
distances
=
D
.
tolist
()[
0
]
D
,
I
=
FAISS_TAGS_INDEX
.
search
(
np
.
array
([
np
.
average
(
vectors
,
axis
=
0
)])
.
astype
(
"float32"
),
n
)
ids
=
I
.
tolist
()[
0
]
distances
=
D
.
tolist
()[
0
]
for
(
index
,
i
)
in
enumerate
(
distances
):
ids
=
I
.
tolist
()[
0
]
if
i
<=
5.0
:
for
(
index
,
i
)
in
enumerate
(
distances
):
res
.
append
(
ids
[
index
])
if
i
<=
5.0
:
time_end
=
time
.
time
()
-
time_begin
res
.
append
(
ids
[
index
])
if
time_end
>
0.04
:
time_end
=
time
.
time
()
-
time_begin
send_performance_msg_to_dingtalk
(
"match_tractate_by_device {} n={} cost {:.3f}ms"
.
format
(
if
time_end
>
0.04
:
device_id
,
n
,
time_end
*
1000
))
send_performance_msg_to_dingtalk
(
"match_tractate_by_device {} n={} cost {:.3f}ms"
.
format
(
device_id
,
n
,
time_end
*
1000
))
return
res
return
res
return
[]
return
[]
except
Exception
as
e
:
except
Exception
as
e
:
...
...
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