Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
ydl_ai_recommender
Overview
Overview
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
闫发泽
ydl_ai_recommender
Commits
3b497d9f
Commit
3b497d9f
authored
Dec 13, 2022
by
柴鹏飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口默认返回100条数据
parent
a7c2622d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
16 deletions
+16
-16
test.py
bin/test.py
+3
-3
order_data_manager.py
src/core/order_data_manager.py
+9
-9
recommender.py
src/core/recommender.py
+4
-4
No files found.
bin/test.py
View file @
3b497d9f
...
...
@@ -46,7 +46,7 @@ def load_test_data():
def
evaluation
(
result_detail
):
top_n_list
=
[
1
,
3
,
5
,
10
]
top_n_list
=
[
1
,
3
,
5
,
10
,
20
,
50
,
100
]
metrics
=
{
'all_test_cnt'
:
0
,
'all_recall_cnt'
:
0
,
...
...
@@ -69,7 +69,7 @@ def evaluation(result_detail):
for
top_n
,
counselor
in
enumerate
(
rd
[
'recall_counselors'
]):
if
counselor
[
'counselor'
]
==
rd
[
'supplier_id'
]:
from_info
=
counselor
[
'from'
]
.
split
(
' '
)
if
from_info
[
0
]
==
'top_
5
0'
:
if
from_info
[
0
]
==
'top_
10
0'
:
metrics
[
'default_recall_cnt'
]
+=
1
else
:
from_id
=
from_info
[
1
]
...
...
@@ -201,7 +201,7 @@ if __name__ == '__main__':
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--mode'
,
default
=
0
,
type
=
int
,
help
=
'模式:0-推荐的咨询师列表去重(默认,与实际线上一样);1-推荐的咨询师列表没有去重'
)
parser
.
add_argument
(
'--k'
,
default
=
1
0
,
type
=
int
,
help
=
'召回相似用户的数量'
)
parser
.
add_argument
(
'--k'
,
default
=
2
0
,
type
=
int
,
help
=
'召回相似用户的数量'
)
parser
.
add_argument
(
'--top_n'
,
default
=
5
,
type
=
int
,
help
=
'每个相似用户召回的咨询师数量'
)
parser
.
add_argument
(
'--max_test'
,
default
=
0
,
type
=
int
,
help
=
'最多测试数据量'
)
...
...
src/core/order_data_manager.py
View file @
3b497d9f
...
...
@@ -63,7 +63,7 @@ class OrderDataManager():
"""
构建索引
用户-咨询师 索引
top
5
0 咨询师列表 用于冷启动
top
10
0 咨询师列表 用于冷启动
"""
self
.
logger
.
info
(
''
)
self
.
logger
.
info
(
'开始构建 用户-咨询师 索引'
)
...
...
@@ -100,14 +100,14 @@ class OrderDataManager():
# 订单最多的咨询师
supplier_cnter
=
Counter
(
df
[
'supplier_id'
])
top
5
0_supplier
=
[]
for
key
,
_
in
supplier_cnter
.
most_common
(
5
0
):
top
5
0_supplier
.
append
(
str
(
key
))
self
.
logger
.
info
(
'top
5
0 订单量咨询师统计完成'
)
with
open
(
os
.
path
.
join
(
self
.
local_file_dir
,
'top
5
0_supplier.txt'
),
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
'
\n
'
.
join
(
top
5
0_supplier
))
self
.
logger
.
info
(
'top
5
0 订单量咨询师列表已保存'
)
top
10
0_supplier
=
[]
for
key
,
_
in
supplier_cnter
.
most_common
(
10
0
):
top
10
0_supplier
.
append
(
str
(
key
))
self
.
logger
.
info
(
'top
10
0 订单量咨询师统计完成'
)
with
open
(
os
.
path
.
join
(
self
.
local_file_dir
,
'top
10
0_supplier.txt'
),
'w'
,
encoding
=
'utf-8'
)
as
f
:
f
.
write
(
'
\n
'
.
join
(
top
10
0_supplier
))
self
.
logger
.
info
(
'top
10
0 订单量咨询师列表已保存'
)
if
__name__
==
'__main__'
:
...
...
src/core/recommender.py
View file @
3b497d9f
...
...
@@ -24,7 +24,7 @@ class Recommender():
class
UserCFRecommender
(
Recommender
):
def
__init__
(
self
,
top_n
=
5
,
k
=
1
0
,
is_use_db
=
True
)
->
None
:
def
__init__
(
self
,
top_n
=
5
,
k
=
2
0
,
is_use_db
=
True
)
->
None
:
super
()
.
__init__
()
# 召回 top_n 个相似用户
self
.
top_n
=
top_n
...
...
@@ -57,7 +57,7 @@ class UserCFRecommender(Recommender):
with
open
(
os
.
path
.
join
(
self
.
local_file_dir
,
'user_doctor_index.json'
),
encoding
=
'utf-8'
)
as
f
:
order_user_counselor_index
=
json
.
load
(
f
)
with
open
(
os
.
path
.
join
(
self
.
local_file_dir
,
'top
5
0_supplier.txt'
),
'r'
,
encoding
=
'utf-8'
)
as
f
:
with
open
(
os
.
path
.
join
(
self
.
local_file_dir
,
'top
10
0_supplier.txt'
),
'r'
,
encoding
=
'utf-8'
)
as
f
:
default_counselor
=
[
line
.
strip
()
for
line
in
f
]
self
.
order_user_embedding
=
order_user_embedding
...
...
@@ -66,7 +66,7 @@ class UserCFRecommender(Recommender):
self
.
default_counselor
=
[{
'counselor'
:
str
(
user
),
'score'
:
1
-
0.01
*
index
,
'from'
:
'top_
5
0'
,
'from'
:
'top_
10
0'
,
}
for
index
,
user
in
enumerate
(
default_counselor
)]
self
.
index
=
faiss
.
IndexFlatL2
(
len
(
self
.
order_user_embedding
[
0
]))
...
...
@@ -91,7 +91,7 @@ class UserCFRecommender(Recommender):
return
self
.
manager
.
profile_to_embedding
(
user_profile
)
def
_recommend_top
(
self
,
size
=
5
0
):
def
_recommend_top
(
self
,
size
=
10
0
):
return
self
.
default_counselor
[:
size
]
...
...
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