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
e0f67561
Commit
e0f67561
authored
Nov 26, 2020
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add time logger
parent
87b52217
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
35 deletions
+38
-35
match_api.py
personas_vector/match_api.py
+6
-1
message.py
utils/message.py
+24
-0
request.py
utils/request.py
+0
-32
api.py
word_vector/api.py
+8
-2
No files found.
personas_vector/match_api.py
View file @
e0f67561
import
json
import
os
import
time
import
traceback
import
faiss
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
from
utils.message
import
(
send_msg_to_dingtalk
,
send_performance_msg_to_dingtalk
)
from
utils.personas
import
get_user_portrait_tag3_from_redis
MODEL_PATH
=
os
.
path
.
join
(
os
.
getcwd
(),
"_models"
)
...
...
@@ -19,6 +20,7 @@ TAG_EMBEDDING_DICT = redis_client_db.hgetall("personas_tags_embedding")
@bind
(
"strategy_embedding/personas_vector/match"
)
def
match_tractate_by_device
(
device_id
,
n
=
10
):
try
:
time_begin
=
time
.
time
()
business_tags
=
get_user_portrait_tag3_from_redis
(
device_id
,
tags_num
=
5
)
.
get
(
"business_tags"
,
[])
# business_tags = ["假体下巴", "你好", "假体隆胸"]
res
=
[]
...
...
@@ -30,6 +32,9 @@ def match_tractate_by_device(device_id, n=10):
if
vectors
:
D
,
I
=
FAISS_TAGS_INDEX
.
search
(
np
.
array
([
np
.
average
(
vectors
,
axis
=
0
)])
.
astype
(
"float32"
),
n
)
res
=
I
.
tolist
()[
0
]
time_end
=
time
.
time
()
-
time_begin
# if time_end > 0.03:
send_performance_msg_to_dingtalk
(
"match_tractate_by_device cost {}ms"
.
format
(
time_end
))
return
res
except
Exception
as
e
:
send_msg_to_dingtalk
(
str
(
traceback
.
format_exc
()))
...
...
utils/message.py
View file @
e0f67561
...
...
@@ -30,3 +30,27 @@ def send_msg_to_dingtalk(msg, mobiles=[]):
except
Exception
as
e
:
print
(
e
)
return
str
(
e
)
def
send_performance_msg_to_dingtalk
(
msg
,
mobiles
=
[]):
try
:
secret
=
"SEC8ff4070e6cf492b386e5c8baa4fdd2702a69adbfde15e662013313a050795ffb"
timestamp
=
str
(
round
(
time
.
time
()
*
1000
))
secret_enc
=
secret
.
encode
(
"utf-8"
)
string_to_sign
=
"{}
\n
{}"
.
format
(
timestamp
,
secret
)
string_to_sign_enc
=
string_to_sign
.
encode
(
"utf-8"
)
hmac_code
=
hmac
.
new
(
secret_enc
,
string_to_sign_enc
,
digestmod
=
hashlib
.
sha256
)
.
digest
()
sign
=
urllib
.
parse
.
quote_plus
(
base64
.
b64encode
(
hmac_code
))
headers
=
{
"Content-Type"
:
"application/json"
}
data
=
{
"msgtype"
:
"text"
,
"text"
:
{
"content"
:
msg
}}
if
mobiles
:
data
=
{
"msgtype"
:
"text"
,
"text"
:
{
"content"
:
msg
},
"at"
:
{
"atMobiles"
:
mobiles
,
"isAtAll"
:
False
}}
json_data
=
json
.
dumps
(
data
)
url
=
"https://oapi.dingtalk.com/robot/send?access_token=820e20b589e3e5d47023fd20859d1d54177e5b03178c25b02cadbbf95cc7e9b8&sign={}×tamp={}"
.
format
(
sign
,
timestamp
)
response
=
requests
.
post
(
url
=
url
,
data
=
json_data
,
headers
=
headers
)
return
str
(
response
.
status_code
)
+
" "
+
str
(
response
.
content
.
decode
(
"utf-8"
))
except
Exception
as
e
:
print
(
e
)
return
str
(
e
)
utils/request.py
deleted
100644 → 0
View file @
87b52217
import
base64
import
hashlib
import
hmac
import
json
import
time
import
urllib
import
requests
def
send_feed_msg_to_dingtalk
(
msg
,
mobiles
=
[]):
try
:
secret
=
"SEC8ff4070e6cf492b386e5c8baa4fdd2702a69adbfde15e662013313a050795ffb"
timestamp
=
str
(
round
(
time
.
time
()
*
1000
))
secret_enc
=
secret
.
encode
(
"utf-8"
)
string_to_sign
=
"{}
\n
{}"
.
format
(
timestamp
,
secret
)
string_to_sign_enc
=
string_to_sign
.
encode
(
"utf-8"
)
hmac_code
=
hmac
.
new
(
secret_enc
,
string_to_sign_enc
,
digestmod
=
hashlib
.
sha256
)
.
digest
()
sign
=
urllib
.
parse
.
quote_plus
(
base64
.
b64encode
(
hmac_code
))
headers
=
{
"Content-Type"
:
"application/json"
}
data
=
{
"msgtype"
:
"text"
,
"text"
:
{
"content"
:
msg
}}
if
mobiles
:
data
=
{
"msgtype"
:
"text"
,
"text"
:
{
"content"
:
msg
},
"at"
:
{
"atMobiles"
:
mobiles
,
"isAtAll"
:
False
}}
json_data
=
json
.
dumps
(
data
)
url
=
"https://oapi.dingtalk.com/robot/send?access_token=820e20b589e3e5d47023fd20859d1d54177e5b03178c25b02cadbbf95cc7e9b8&sign={}×tamp={}"
.
format
(
sign
,
timestamp
)
response
=
requests
.
post
(
url
=
url
,
data
=
json_data
,
headers
=
headers
)
return
str
(
response
.
status_code
)
+
" "
+
str
(
response
.
content
.
decode
(
"utf-8"
))
except
Exception
as
e
:
print
(
e
)
return
str
(
e
)
word_vector/api.py
View file @
e0f67561
import
multiprocessing
import
os
import
sys
import
time
import
traceback
sys
.
path
.
append
(
os
.
path
.
realpath
(
"."
))
...
...
@@ -9,7 +10,7 @@ from gensim.models import Word2Vec, word2vec
from
gm_rpcd.all
import
bind
from
utils.es
import
es_scan
from
utils.files
import
DATA_PATH
,
MODEL_PATH
from
utils.message
import
send_msg_to_dingtalk
from
utils.message
import
(
send_msg_to_dingtalk
,
send_performance_msg_to_dingtalk
)
from
word_vector.tractate
import
TRACTATE_CLICK_IDS_MODEL
...
...
@@ -87,7 +88,12 @@ def projects_item2vec(score_limit=5):
@bind
(
"strategy_embedding/word_vector/tractate_item2vec"
)
def
clicked_tractate_ids_item2vec_model
(
id
,
n
=
5
):
try
:
return
TRACTATE_CLICK_IDS_MODEL
.
wv
.
most_similar
(
id
,
topn
=
n
)
time_begin
=
time
.
time
()
res
=
TRACTATE_CLICK_IDS_MODEL
.
wv
.
most_similar
(
id
,
topn
=
n
)
time_end
=
time
.
time
()
-
time_begin
# if time_end > 0.03:
send_performance_msg_to_dingtalk
(
"clicked_tractate_ids_item2vec_model cost {}ms"
.
format
(
time_end
))
return
res
except
KeyError
as
e
:
send_msg_to_dingtalk
(
"tractate_item2vec: "
+
str
(
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