提交 8aaeab15 编写于 作者: W wangguibao

elastic CTR

上级 7f3cfbce
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
from __future__ import print_function from __future__ import print_function
import json import json
import httplib
import sys import sys
import os import os
...@@ -27,6 +26,13 @@ CTR_EMBEDDING_TABLE_SIZE = 400000001 ...@@ -27,6 +26,13 @@ CTR_EMBEDDING_TABLE_SIZE = 400000001
SLOTS = [] SLOTS = []
def str2long(str):
if sys.version_info[0] == 2:
return long(str)
elif sys.version_info[0] == 3:
return int(str)
def data_reader(data_file, samples, labels): def data_reader(data_file, samples, labels):
if not os.path.exists(data_file): if not os.path.exists(data_file):
print("Path %s not exist" % data_file) print("Path %s not exist" % data_file)
...@@ -45,10 +51,14 @@ def data_reader(data_file, samples, labels): ...@@ -45,10 +51,14 @@ def data_reader(data_file, samples, labels):
for i in range(0, len(features)): for i in range(0, len(features)):
if slots[i] in sample: if slots[i] in sample:
sample[slots[i]] = [sample[slots[i]] + long(features[i])] sample[slots[i]] = [
sample[slots[i]] + str2long(features[i]) %
CTR_EMBEDDING_TABLE_SIZE
]
else: else:
sample[slots[ sample[slots[i]] = [
i]] = [long(features[i]) % CTR_EMBEDDING_TABLE_SIZE] str2long(features[i]) % CTR_EMBEDDING_TABLE_SIZE
]
for x in SLOTS: for x in SLOTS:
if not x in sample: if not x in sample:
...@@ -85,8 +95,12 @@ if __name__ == "__main__": ...@@ -85,8 +95,12 @@ if __name__ == "__main__":
for sample in batch: for sample in batch:
instance = api.add_instance() instance = api.add_instance()
kv = [] kv = []
for k, v in sample.iteritems(): if sys.version_info[0] == 2:
api.add_slot(instance, k, v) for k, v in sample.iteritems():
api.add_slot(instance, k, v)
elif sys.version_info[0] == 3:
for k, v in sample.items():
api.add_slot(instance, k, v)
ret = api.inference() ret = api.inference()
print(ret) print(ret)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册