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
0f48d413
Commit
0f48d413
authored
Nov 26, 2020
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add timer
parent
ee69f945
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
9 deletions
+11
-9
match_api.py
personas_vector/match_api.py
+11
-9
No files found.
personas_vector/match_api.py
View file @
0f48d413
...
@@ -22,27 +22,29 @@ def match_tractate_by_device(device_id, n=10):
...
@@ -22,27 +22,29 @@ def match_tractate_by_device(device_id, n=10):
try
:
try
:
if
device_id
not
in
[
"0"
,
"unknown"
,
"87654"
,
""
]:
if
device_id
not
in
[
"0"
,
"unknown"
,
"87654"
,
""
]:
time_begin
=
time
.
time
()
time_begin
=
time
.
time
()
portrait_time_begin
=
time
.
time
()
business_tags
=
get_user_portrait_tag3_business_tags
(
device_id
,
tags_num
=
3
)
business_tags
=
get_user_portrait_tag3_business_tags
(
device_id
,
tags_num
=
3
)
portrait_time_end
=
time
.
time
()
-
portrait_time_begin
res
=
[]
res
=
[]
if
business_tags
:
if
business_tags
:
vectors_time_begin
=
time
.
time
()
vectors
=
[]
vectors
=
[]
for
tag
in
business_tags
:
for
tag
in
business_tags
:
lst
=
json
.
loads
(
TAG_EMBEDDING_DICT
.
get
(
bytes
(
tag
,
"utf-8"
),
b
"[]"
))
lst
=
json
.
loads
(
TAG_EMBEDDING_DICT
.
get
(
bytes
(
tag
,
"utf-8"
),
b
"[]"
))
if
lst
:
if
lst
:
vectors
.
append
(
np
.
array
(
lst
)
.
astype
(
"float32"
))
vectors
.
append
(
np
.
array
(
lst
)
.
astype
(
"float32"
))
vectors_time_end
=
time
.
time
()
-
vectors_time_begin
search_time_begin
=
time
.
time
()
if
vectors
:
if
vectors
:
D
,
I
=
FAISS_TAGS_INDEX
.
search
(
np
.
array
([
np
.
average
(
vectors
,
axis
=
0
)])
.
astype
(
"float32"
),
n
)
average_time_begin
=
time
.
time
()
average_vectors
=
np
.
array
([
np
.
average
(
vectors
,
axis
=
0
)])
.
astype
(
"float32"
)
average_time_end
=
time
.
time
()
-
average_time_begin
search_time_begin
=
time
.
time
()
D
,
I
=
FAISS_TAGS_INDEX
.
search
(
average_vectors
,
n
)
search_time_end
=
time
.
time
()
-
search_time_begin
to_list_time_begin
=
time
.
time
()
distances
=
D
.
tolist
()[
0
]
distances
=
D
.
tolist
()[
0
]
ids
=
I
.
tolist
()[
0
]
ids
=
I
.
tolist
()[
0
]
to_list_time_end
=
time
.
time
()
-
to_list_time_begin
for
(
index
,
i
)
in
enumerate
(
distances
):
for
(
index
,
i
)
in
enumerate
(
distances
):
if
i
<=
5.0
:
if
i
<=
5.0
:
res
.
append
(
ids
[
index
])
res
.
append
(
ids
[
index
])
search_time_end
=
time
.
time
()
-
search_time_begin
time_end
=
time
.
time
()
-
time_begin
time_end
=
time
.
time
()
-
time_begin
if
time_end
>
0.04
:
if
time_end
>
0.04
:
timer_dict
=
{
timer_dict
=
{
...
@@ -50,8 +52,8 @@ def match_tractate_by_device(device_id, n=10):
...
@@ -50,8 +52,8 @@ def match_tractate_by_device(device_id, n=10):
"api"
:
"strategy_embedding/personas_vector/match"
,
"api"
:
"strategy_embedding/personas_vector/match"
,
"device_id"
:
device_id
,
"device_id"
:
device_id
,
"n"
:
n
,
"n"
:
n
,
"
get_business_tags"
:
"{:.3f}ms"
.
format
(
portrait
_time_end
*
1000
),
"
average_time"
:
"{:.3f}ms"
.
format
(
average
_time_end
*
1000
),
"
get_vectors"
:
"{:.3f}ms"
.
format
(
vectors
_time_end
*
1000
),
"
to_list_time"
:
"{:.3f}ms"
.
format
(
to_list
_time_end
*
1000
),
"search"
:
"{:.3f}ms"
.
format
(
search_time_end
*
1000
),
"search"
:
"{:.3f}ms"
.
format
(
search_time_end
*
1000
),
"total_time"
:
"{:.3f}ms"
.
format
(
time_end
*
1000
)
"total_time"
:
"{:.3f}ms"
.
format
(
time_end
*
1000
)
}
}
...
...
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