Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
gm_strategy_cvr
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
gm_strategy_cvr
Commits
2b19cefa
Commit
2b19cefa
authored
Jul 22, 2020
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add timer
parent
831ec291
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
30 deletions
+34
-30
main.py
src/main.py
+1
-1
model.py
src/models/esmm/model.py
+33
-29
No files found.
src/main.py
View file @
2b19cefa
...
...
@@ -14,7 +14,7 @@ from sklearn.model_selection import train_test_split
from
models.esmm.fe
import
(
click_feature_engineering
,
device_feature_engineering
,
diary_feature_engineering
,
get_device_dict_from_redis
,
get_diary_dict_from_redis
,
join_features
,
read_csv_data
)
from
models.esmm.input_fn
import
build_features
,
esmm_input_fn
from
models.esmm.model
import
(
esmm_model_fn
,
model_export
,
model_predict
,
model_predict2
)
from
models.esmm.model
import
esmm_model_fn
,
model_export
,
model_predict2
# tf.compat.v1.enable_eager_execution()
...
...
src/models/esmm/model.py
View file @
2b19cefa
...
...
@@ -123,33 +123,6 @@ def model_predict2(device_id, diary_ids, device_dict, diary_dict, predict_fn):
features
[
col
]
=
_bytes_feature
(
str
(
value
)
.
encode
(
encoding
=
"utf-8"
))
example
=
tf
.
train
.
Example
(
features
=
tf
.
train
.
Features
(
feature
=
features
))
examples
.
append
(
example
.
SerializeToString
())
predictions
=
predict_fn
({
"examples"
:
examples
})
total_1
=
(
timeit
.
default_timer
()
-
time_1
)
print
(
"prediction cost {:.5f}s"
.
format
(
total_1
))
return
predictions
def
model_predict
(
inputs
,
predict_fn
):
time_1
=
timeit
.
default_timer
()
int_columns
=
[
"active_type"
,
"active_days"
,
"card_id"
,
"is_pure_author"
,
"is_have_reply"
,
"is_have_pure_reply"
,
"content_level"
,
"topic_num"
,
"favor_num"
,
"vote_num"
]
float_columns
=
[
"one_ctr"
,
"three_ctr"
,
"seven_ctr"
,
"fifteen_ctr"
]
examples
=
[]
for
index
,
row
in
inputs
.
iterrows
():
features
=
{}
for
col
,
value
in
row
.
iteritems
():
if
col
in
[
"click_label"
,
"conversion_label"
]:
pass
elif
col
in
int_columns
:
features
[
col
]
=
_int64_feature
(
int
(
value
))
elif
col
in
float_columns
:
features
[
col
]
=
_float_feature
(
float
(
value
))
else
:
features
[
col
]
=
_bytes_feature
(
str
(
value
)
.
encode
(
encoding
=
"utf-8"
))
example
=
tf
.
train
.
Example
(
features
=
tf
.
train
.
Features
(
feature
=
features
))
examples
.
append
(
example
.
SerializeToString
())
total_1
=
(
timeit
.
default_timer
()
-
time_1
)
print
(
"make example cost {:.5f}s"
.
format
(
total_1
))
...
...
@@ -157,6 +130,37 @@ def model_predict(inputs, predict_fn):
predictions
=
predict_fn
({
"examples"
:
examples
})
total_1
=
(
timeit
.
default_timer
()
-
time_1
)
print
(
"prediction cost {:.5f}s"
.
format
(
total_1
))
# print(predictions)
# TODO get the diary ids
return
predictions
# def model_predict(inputs, predict_fn):
# time_1 = timeit.default_timer()
# int_columns = [
# "active_type", "active_days", "card_id", "is_pure_author", "is_have_reply", "is_have_pure_reply", "content_level",
# "topic_num", "favor_num", "vote_num"
# ]
# float_columns = ["one_ctr", "three_ctr", "seven_ctr", "fifteen_ctr"]
# examples = []
# for index, row in inputs.iterrows():
# features = {}
# for col, value in row.iteritems():
# if col in ["click_label", "conversion_label"]:
# pass
# elif col in int_columns:
# features[col] = _int64_feature(int(value))
# elif col in float_columns:
# features[col] = _float_feature(float(value))
# else:
# features[col] = _bytes_feature(str(value).encode(encoding="utf-8"))
# example = tf.train.Example(features=tf.train.Features(feature=features))
# examples.append(example.SerializeToString())
# total_1 = (timeit.default_timer() - time_1)
# print("make example cost {:.5f}s".format(total_1))
# time_1 = timeit.default_timer()
# predictions = predict_fn({"examples": examples})
# total_1 = (timeit.default_timer() - time_1)
# print("prediction cost {:.5f}s".format(total_1))
# # print(predictions)
# # TODO get the diary ids
# return predictions
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