|
@@ -27,7 +27,8 @@ import java.util.concurrent.*;
|
|
|
public class VlogShareLRScorer extends BaseLRModelScorer{
|
|
|
|
|
|
private final static int CORE_POOL_SIZE = 64;
|
|
|
- private final static int TIME_OUT = 150;
|
|
|
+
|
|
|
+ private static final int LOCAL_TIME_OUT= 150;
|
|
|
private final static Logger LOGGER = LoggerFactory.getLogger(VlogShareLRScorer.class);
|
|
|
private static final ExecutorService executorService = Executors.newFixedThreadPool(128);
|
|
|
private static final FeatureUsage featureUsage = new FeatureUsage();
|
|
@@ -53,7 +54,6 @@ public class VlogShareLRScorer extends BaseLRModelScorer{
|
|
|
return rankItems;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
List<RankItem> result = rankItems;
|
|
|
result = rankByJava(rankItems, request, userFeature);
|
|
|
|
|
@@ -70,13 +70,14 @@ public class VlogShareLRScorer extends BaseLRModelScorer{
|
|
|
LRModel model = (LRModel) this.getModel();
|
|
|
LOGGER.debug("model size: [{}]", model.getModelSize());
|
|
|
|
|
|
+ // init request context
|
|
|
String cityCode = request.getCityCode();
|
|
|
RequestContext requestContext = new RequestContext();
|
|
|
- requestContext.setCityCode(cityCode);
|
|
|
-
|
|
|
+ requestContext.setCity(request.getCityCode());
|
|
|
|
|
|
+ // userBytes
|
|
|
UserBytesFeature userInfoBytes = null;
|
|
|
- userInfoBytes = new UserBytesFeature(user.getSex());
|
|
|
+ userInfoBytes = new UserBytesFeature(user);
|
|
|
|
|
|
// 所有都参与打分,按照ctr排序
|
|
|
multipleCtrScore(items, userInfoBytes, requestContext, model);
|
|
@@ -110,11 +111,11 @@ public class VlogShareLRScorer extends BaseLRModelScorer{
|
|
|
bytesFeatureExtractor = new VlogShareLRFeatureExtractor(featureUsage, 100.0, 1);
|
|
|
|
|
|
try {
|
|
|
- VideoBytesFeature newsInfoBytes = new VideoBytesFeature(item);
|
|
|
+ VideoBytesFeature newsInfoBytes = new VideoBytesFeature(item.getItemFeature());
|
|
|
lrSamples = bytesFeatureExtractor.single(userInfoBytes, newsInfoBytes,
|
|
|
new RequestContextBytesFeature(requestContext));
|
|
|
} catch (Exception e) {
|
|
|
- LOGGER.error("extract feature error for imei={}, doc={}, [{}]", new Object[]{new String(userInfoBytes.imei), item.getId(),
|
|
|
+ LOGGER.error("extract feature error for imei={}, doc={}, [{}]", new Object[]{new String(userInfoBytes.getUid()), item.getVideoid(),
|
|
|
ExceptionUtils.getFullStackTrace(e)});
|
|
|
}
|
|
|
|
|
@@ -125,11 +126,11 @@ public class VlogShareLRScorer extends BaseLRModelScorer{
|
|
|
pro = lrModel.score(lrSamples);
|
|
|
} catch (Exception e) {
|
|
|
LOGGER.error("score error for doc={} exception={}", new Object[]{
|
|
|
- item.getVideoId(), ExceptionUtils.getFullStackTrace(e)});
|
|
|
+ item.getVideoid(), ExceptionUtils.getFullStackTrace(e)});
|
|
|
}
|
|
|
|
|
|
|
|
|
- CtrSamples samples = CtrSamples.newBuilder();
|
|
|
+ CtrSamples.Builder samples = com.tzld.piaoquan.recommend.server.gen.recommend.CtrSamples.newBuilder();
|
|
|
samples.setLr_samples(lrSamples);
|
|
|
item.setSamples(samples);
|
|
|
}
|
|
@@ -143,22 +144,31 @@ public class VlogShareLRScorer extends BaseLRModelScorer{
|
|
|
* 并行打分
|
|
|
*
|
|
|
*/
|
|
|
- private void multipleCtrScore(final RecommendRequest request,
|
|
|
- final RankParam param,
|
|
|
- final UserFeature userFeature,
|
|
|
- final List<RankItem> rankItems) {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 并行打分
|
|
|
+ *
|
|
|
+ * @param items
|
|
|
+ * @param userInfoBytes
|
|
|
+ * @param requestContext
|
|
|
+ * @param model
|
|
|
+ */
|
|
|
+ private void multipleCtrScore(final List<RankItem> items,
|
|
|
+ final UserBytesFeature userInfoBytes,
|
|
|
+ final RequestContext requestContext,
|
|
|
+ final LRModel model) {
|
|
|
|
|
|
List<Callable<Object>> calls = new ArrayList<Callable<Object>>();
|
|
|
- for (int index = 0; index < rankItems.size(); index++) {
|
|
|
+ for (int index = 0; index < items.size(); index++) {
|
|
|
final int fIndex = index;
|
|
|
- rankItems.get(fIndex).setRankScore(0.0);//原始分为 cube中的粗打分,如果超时,为原始值存在问题, 需要置0
|
|
|
+ items.get(fIndex).setScore(0.0); //原始分为 cube中的粗打分,如果超时,为原始值存在问题, 需要置0
|
|
|
calls.add(new Callable<Object>() {
|
|
|
@Override
|
|
|
public Object call() throws Exception {
|
|
|
try {
|
|
|
- calcScore(model, items.get(fIndex), userInfoBytes, requestContext, feedsContext);
|
|
|
+ calcScore(model, items.get(fIndex), userInfoBytes, requestContext);
|
|
|
} catch (Exception e) {
|
|
|
- LOGGER.error("ctr exception: [{}] [{}]", items.get(fIndex).getId(), ExceptionUtils.getFullStackTrace(e));
|
|
|
+ LOGGER.error("ctr exception: [{}] [{}]", items.get(fIndex).videoid, ExceptionUtils.getFullStackTrace(e));
|
|
|
}
|
|
|
return new Object();
|
|
|
}
|
|
@@ -167,7 +177,7 @@ public class VlogShareLRScorer extends BaseLRModelScorer{
|
|
|
|
|
|
List<Future<Object>> futures = null;
|
|
|
try {
|
|
|
- futures = executorService.invokeAll(calls, 200, TimeUnit.MILLISECONDS);
|
|
|
+ futures = executorService.invokeAll(calls, LOCAL_TIME_OUT, TimeUnit.MILLISECONDS);
|
|
|
} catch (InterruptedException e) {
|
|
|
LOGGER.error("execute invoke fail: {}", ExceptionUtils.getFullStackTrace(e));
|
|
|
}
|
|
@@ -183,13 +193,12 @@ public class VlogShareLRScorer extends BaseLRModelScorer{
|
|
|
} catch (InterruptedException e) {
|
|
|
LOGGER.error("InterruptedException {},{}", ExceptionUtils.getFullStackTrace(e));
|
|
|
} catch (ExecutionException e) {
|
|
|
- LOGGER.error("ExecutionException {},{}", request.getRequestId(),
|
|
|
+ LOGGER.error("ExecutionException {},{}", requestContext.getRequest_id(),
|
|
|
ExceptionUtils.getFullStackTrace(e));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- LOGGER.debug("Ctr Score {}, Total: {}, Cancel: {}", new Object[]{request.getRequestId(), rankItems.size(), cancel});
|
|
|
+ LOGGER.debug("Ctr Score {}, Total: {}, Cancel: {}", new Object[]{requestContext.getRequest_id(), items.size(), cancel});
|
|
|
}
|
|
|
}
|
|
|
|