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
35deca1b
Commit
35deca1b
authored
Nov 26, 2020
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update get portrait
parent
5982f258
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
match_api.py
personas_vector/match_api.py
+2
-2
personas.py
utils/personas.py
+14
-5
No files found.
personas_vector/match_api.py
View file @
35deca1b
...
...
@@ -8,7 +8,7 @@ import numpy as np
from
gm_rpcd.all
import
bind
from
utils.cache
import
redis_client_db
from
utils.message
import
(
send_msg_to_dingtalk
,
send_performance_msg_to_dingtalk
)
from
utils.personas
import
get_user_portrait_tag3_
from_redi
s
from
utils.personas
import
get_user_portrait_tag3_
business_tag
s
MODEL_PATH
=
os
.
path
.
join
(
os
.
getcwd
(),
"_models"
)
INDEX_PATH
=
os
.
path
.
join
(
MODEL_PATH
,
"faiss_personas_vector.index"
)
...
...
@@ -22,7 +22,7 @@ def match_tractate_by_device(device_id, n=10):
try
:
if
device_id
not
in
[
"0"
,
"unknown"
,
"87654"
]:
time_begin
=
time
.
time
()
business_tags
=
get_user_portrait_tag3_
from_redi
s
(
device_id
,
tags_num
=
3
)
.
get
(
"business_tags"
,
[])
business_tags
=
get_user_portrait_tag3_
business_tag
s
(
device_id
,
tags_num
=
3
)
.
get
(
"business_tags"
,
[])
res
=
[]
if
business_tags
:
vectors
=
[]
...
...
utils/personas.py
View file @
35deca1b
...
...
@@ -7,12 +7,13 @@ def get_user_portrait_tag3_redis_key(device_id):
return
"doris:user_portrait:tag3:device_id:"
+
str
(
device_id
)
def
get_user_portrait_tag3_from_redis
(
device_i
d
,
limit_score
=
0
,
tags_num
=
5
):
def
items_gt_score
(
d
,
tags_num
=
tags_num
):
new_d
=
dict
(
sorted
(
d
.
items
(),
key
=
lambda
x
:
x
[
1
],
reverse
=
True
)[:
tags_num
])
res
=
{
tag
:
float
(
score
)
for
tag
,
score
in
new_d
.
items
()
if
float
(
score
)
>=
limit_score
}
return
list
(
res
.
keys
())
def
items_gt_score
(
d
,
limit_score
=
0
,
tags_num
=
5
):
new_d
=
dict
(
sorted
(
d
.
items
(),
key
=
lambda
x
:
x
[
1
],
reverse
=
True
))
res
=
{
tag
:
float
(
score
)
for
tag
,
score
in
new_d
.
items
()
if
float
(
score
)
>=
limit_score
}
return
list
(
res
.
keys
())[:
tags_num
]
def
get_user_portrait_tag3_from_redis
(
device_id
,
limit_score
=
0
,
tags_num
=
5
):
portrait_key
=
get_user_portrait_tag3_redis_key
(
device_id
)
if
redis_client2
.
exists
(
portrait_key
):
user_portrait
=
json
.
loads
(
redis_client2
.
get
(
portrait_key
))
...
...
@@ -37,3 +38,11 @@ def get_user_portrait_tag3_from_redis(device_id, limit_score=0, tags_num=5):
"business_tags"
:
business_tags
}
return
{}
def
get_user_portrait_tag3_business_tags
(
device_id
,
limit_score
=
0
,
tags_num
=
5
):
portrait_key
=
get_user_portrait_tag3_redis_key
(
device_id
)
if
redis_client2
.
exists
(
portrait_key
):
user_portrait
=
json
.
loads
(
redis_client2
.
get
(
portrait_key
))
business_tags
=
items_gt_score
(
user_portrait
.
get
(
"business_tags"
,
{}))
return
business_tags
return
[]
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