|
@@ -10,6 +10,7 @@ import com.tzld.piaoquan.recommend.server.service.rank.extractor.ExtractorUtils;
|
|
import com.tzld.piaoquan.recommend.server.service.recall.strategy.*;
|
|
import com.tzld.piaoquan.recommend.server.service.recall.strategy.*;
|
|
import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
|
|
import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
|
|
import com.tzld.piaoquan.recommend.server.util.CommonCollectionUtils;
|
|
import com.tzld.piaoquan.recommend.server.util.CommonCollectionUtils;
|
|
|
|
+import com.tzld.piaoquan.recommend.server.util.JSONUtils;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.collections4.MapUtils;
|
|
import org.apache.commons.collections4.MapUtils;
|
|
import org.apache.commons.math3.util.Pair;
|
|
import org.apache.commons.math3.util.Pair;
|
|
@@ -32,17 +33,13 @@ public class RankStrategy4RegionMergeModelV562 extends RankStrategy4RegionMergeM
|
|
@ApolloJsonValue("${rank.score.merge.weightv562:}")
|
|
@ApolloJsonValue("${rank.score.merge.weightv562:}")
|
|
private Map<String, Double> mergeWeight;
|
|
private Map<String, Double> mergeWeight;
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private FeatureService featureService;
|
|
private FeatureService featureService;
|
|
|
|
|
|
Map<String, double[]> bucketsMap = new HashMap<>();
|
|
Map<String, double[]> bucketsMap = new HashMap<>();
|
|
Map<String, Double> bucketsLen = new HashMap<>();
|
|
Map<String, Double> bucketsLen = new HashMap<>();
|
|
|
|
|
|
- @Value("${similarity.concurrent: false}")
|
|
|
|
|
|
+ @Value("${similarity.concurrent: true}")
|
|
private boolean similarityConcurrent;
|
|
private boolean similarityConcurrent;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -70,13 +67,13 @@ public class RankStrategy4RegionMergeModelV562 extends RankStrategy4RegionMergeM
|
|
List<Video> rovRecallRank = new ArrayList<>(v0);
|
|
List<Video> rovRecallRank = new ArrayList<>(v0);
|
|
//-------------------return相似召回------------------
|
|
//-------------------return相似召回------------------
|
|
List<Video> v6 = extractAndSort(param, ReturnVideoRecallStrategy.PUSH_FORM);
|
|
List<Video> v6 = extractAndSort(param, ReturnVideoRecallStrategy.PUSH_FORM);
|
|
- v6 = v6.stream().filter(r-> !setVideo.contains(r.getVideoId())).collect(Collectors.toList());
|
|
|
|
|
|
+ v6 = v6.stream().filter(r -> !setVideo.contains(r.getVideoId())).collect(Collectors.toList());
|
|
v6 = v6.subList(0, Math.min(mergeWeight.getOrDefault("v6", 5.0).intValue(), v6.size()));
|
|
v6 = v6.subList(0, Math.min(mergeWeight.getOrDefault("v6", 5.0).intValue(), v6.size()));
|
|
rovRecallRank.addAll(v6);
|
|
rovRecallRank.addAll(v6);
|
|
setVideo.addAll(v6.stream().map(Video::getVideoId).collect(Collectors.toSet()));
|
|
setVideo.addAll(v6.stream().map(Video::getVideoId).collect(Collectors.toSet()));
|
|
//-------------------新地域召回------------------
|
|
//-------------------新地域召回------------------
|
|
List<Video> v1 = extractAndSort(param, RegionRealtimeRecallStrategyV1.PUSH_FORM);
|
|
List<Video> v1 = extractAndSort(param, RegionRealtimeRecallStrategyV1.PUSH_FORM);
|
|
- v1 = v1.stream().filter(r-> !setVideo.contains(r.getVideoId())).collect(Collectors.toList());
|
|
|
|
|
|
+ v1 = v1.stream().filter(r -> !setVideo.contains(r.getVideoId())).collect(Collectors.toList());
|
|
v1 = v1.subList(0, Math.min(mergeWeight.getOrDefault("v1", 5.0).intValue(), v1.size()));
|
|
v1 = v1.subList(0, Math.min(mergeWeight.getOrDefault("v1", 5.0).intValue(), v1.size()));
|
|
rovRecallRank.addAll(v1);
|
|
rovRecallRank.addAll(v1);
|
|
setVideo.addAll(v1.stream().map(Video::getVideoId).collect(Collectors.toSet()));
|
|
setVideo.addAll(v1.stream().map(Video::getVideoId).collect(Collectors.toSet()));
|
|
@@ -241,7 +238,12 @@ public class RankStrategy4RegionMergeModelV562 extends RankStrategy4RegionMergeM
|
|
String tags = c34567Map.getOrDefault(key, "");
|
|
String tags = c34567Map.getOrDefault(key, "");
|
|
if (!tags.isEmpty()) {
|
|
if (!tags.isEmpty()) {
|
|
Future<Pair<String, Double[]>> future = ThreadPoolFactory.defaultPool().submit(() -> {
|
|
Future<Pair<String, Double[]>> future = ThreadPoolFactory.defaultPool().submit(() -> {
|
|
- Double[] doubles = ExtractorUtils.funcC34567ForTags(tags, title);
|
|
|
|
|
|
+ Double[] doubles = null;
|
|
|
|
+ if (param.getAbExpCodes().contains(word2vecExp)) {
|
|
|
|
+ doubles = ExtractorUtils.funcC34567ForTagsNew(tags, title);
|
|
|
|
+ } else {
|
|
|
|
+ doubles = ExtractorUtils.funcC34567ForTags(tags, title);
|
|
|
|
+ }
|
|
return Pair.create(key, doubles);
|
|
return Pair.create(key, doubles);
|
|
});
|
|
});
|
|
futures.add(future);
|
|
futures.add(future);
|
|
@@ -263,7 +265,12 @@ public class RankStrategy4RegionMergeModelV562 extends RankStrategy4RegionMergeM
|
|
for (String key_time : Arrays.asList("tags_1d", "tags_3d", "tags_7d")) {
|
|
for (String key_time : Arrays.asList("tags_1d", "tags_3d", "tags_7d")) {
|
|
String tags = c34567Map.getOrDefault(name + "_" + key_time, "");
|
|
String tags = c34567Map.getOrDefault(name + "_" + key_time, "");
|
|
if (!tags.isEmpty()) {
|
|
if (!tags.isEmpty()) {
|
|
- Double[] doubles = ExtractorUtils.funcC34567ForTags(tags, title);
|
|
|
|
|
|
+ Double[] doubles = null;
|
|
|
|
+ if (param.getAbExpCodes().contains(word2vecExp)) {
|
|
|
|
+ doubles = ExtractorUtils.funcC34567ForTagsNew(tags, title);
|
|
|
|
+ } else {
|
|
|
|
+ doubles = ExtractorUtils.funcC34567ForTags(tags, title);
|
|
|
|
+ }
|
|
featureMap.put(name + "_" + key_time + "_matchnum", doubles[0]);
|
|
featureMap.put(name + "_" + key_time + "_matchnum", doubles[0]);
|
|
featureMap.put(name + "_" + key_time + "_maxscore", doubles[1]);
|
|
featureMap.put(name + "_" + key_time + "_maxscore", doubles[1]);
|
|
featureMap.put(name + "_" + key_time + "_avgscore", doubles[2]);
|
|
featureMap.put(name + "_" + key_time + "_avgscore", doubles[2]);
|
|
@@ -362,7 +369,6 @@ public class RankStrategy4RegionMergeModelV562 extends RankStrategy4RegionMergeM
|
|
weightList.add(mergeWeight.getOrDefault("h1_ago_vov_w", 0.0));
|
|
weightList.add(mergeWeight.getOrDefault("h1_ago_vov_w", 0.0));
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
Map<String, Map<String, String>> vid2MapFeature = this.getVideoRedisFeature(vids, "redis:vid_hasreturn_rov:");
|
|
Map<String, Map<String, String>> vid2MapFeature = this.getVideoRedisFeature(vids, "redis:vid_hasreturn_rov:");
|
|
Map<String, Map<String, String>> vid2VovFeatureMap = this.getVideoRedisFeature(vids, "redis:vid_vovhour4rank:");
|
|
Map<String, Map<String, String>> vid2VovFeatureMap = this.getVideoRedisFeature(vids, "redis:vid_vovhour4rank:");
|
|
List<Video> result = new ArrayList<>();
|
|
List<Video> result = new ArrayList<>();
|
|
@@ -411,7 +417,6 @@ public class RankStrategy4RegionMergeModelV562 extends RankStrategy4RegionMergeM
|
|
item.getScoresMap().put("vov_thresh", vov_thresh);
|
|
item.getScoresMap().put("vov_thresh", vov_thresh);
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
List<Double> featureList = new ArrayList<>(7);
|
|
List<Double> featureList = new ArrayList<>(7);
|
|
featureList.add(d2_ago_vov);
|
|
featureList.add(d2_ago_vov);
|
|
featureList.add(d1_ago_vov);
|
|
featureList.add(d1_ago_vov);
|
|
@@ -424,13 +429,13 @@ public class RankStrategy4RegionMergeModelV562 extends RankStrategy4RegionMergeM
|
|
// todo 线性加权 预测VoV
|
|
// todo 线性加权 预测VoV
|
|
|
|
|
|
|
|
|
|
- double vov_p = calculateScore(featureList, weightList,item, vov_thresh, view_thresh, h1_ago_view,level50_vov,level_95_vov,beta_vov);
|
|
|
|
|
|
+ double vov_p = calculateScore(featureList, weightList, item, vov_thresh, view_thresh, h1_ago_view, level50_vov, level_95_vov, beta_vov);
|
|
|
|
|
|
|
|
|
|
double hasReturnRovScore = Double.parseDouble(vid2MapFeature.getOrDefault(item.getVideoId() + "", new HashMap<>())
|
|
double hasReturnRovScore = Double.parseDouble(vid2MapFeature.getOrDefault(item.getVideoId() + "", new HashMap<>())
|
|
.getOrDefault("rate_n", "0"));
|
|
.getOrDefault("rate_n", "0"));
|
|
item.getScoresMap().put("hasReturnRovScore", hasReturnRovScore);
|
|
item.getScoresMap().put("hasReturnRovScore", hasReturnRovScore);
|
|
- score = fmRov * (1 + hasReturnRovScore) * (1.0 + alpha_vov * vov_p);
|
|
|
|
|
|
+ score = fmRov * (1 + hasReturnRovScore) * (1.0 + alpha_vov * vov_p);
|
|
|
|
|
|
|
|
|
|
item.getScoresMap().put("vov_p", vov_p);
|
|
item.getScoresMap().put("vov_p", vov_p);
|
|
@@ -457,8 +462,8 @@ public class RankStrategy4RegionMergeModelV562 extends RankStrategy4RegionMergeM
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- private double calculateScore(List<Double> featureList, List<Double> weightList,RankItem rankItem,
|
|
|
|
- double vov_thresh, double view_thresh, double h1_ago_view,double level50_vov,double level_95_vov,double beta_vov) {
|
|
|
|
|
|
+ private double calculateScore(List<Double> featureList, List<Double> weightList, RankItem rankItem,
|
|
|
|
+ double vov_thresh, double view_thresh, double h1_ago_view, double level50_vov, double level_95_vov, double beta_vov) {
|
|
// 检查 h1_ago_view 条件
|
|
// 检查 h1_ago_view 条件
|
|
if (h1_ago_view == -2 || h1_ago_view == -1 || h1_ago_view < view_thresh) {
|
|
if (h1_ago_view == -2 || h1_ago_view == -1 || h1_ago_view < view_thresh) {
|
|
rankItem.getScoresMap().put("origin_vov_p", 0d);
|
|
rankItem.getScoresMap().put("origin_vov_p", 0d);
|
|
@@ -497,8 +502,8 @@ public class RankStrategy4RegionMergeModelV562 extends RankStrategy4RegionMergeM
|
|
if (score < vov_thresh) {
|
|
if (score < vov_thresh) {
|
|
score = 0;
|
|
score = 0;
|
|
} else {
|
|
} else {
|
|
- double term1 = 1 / (1 + Math.exp(-1*beta_vov * (score - level50_vov)));
|
|
|
|
- double term2 = 1 + Math.exp(-1*beta_vov * (level_95_vov - level50_vov));
|
|
|
|
|
|
+ double term1 = 1 / (1 + Math.exp(-1 * beta_vov * (score - level50_vov)));
|
|
|
|
+ double term2 = 1 + Math.exp(-1 * beta_vov * (level_95_vov - level50_vov));
|
|
score = term1 * term2;
|
|
score = term1 * term2;
|
|
}
|
|
}
|
|
return score;
|
|
return score;
|