模型打分服务配置

请求参数

请求参数为JSON格式,参数项如下:

参数项

说明

request_id

string, 请求ID

scene

string, 场景名,可选

algo

string, 算法名

user_id

string, 用户ID

items

string数组, 候选arm集合

user_feature

dict, 用户特征

item_features

dict数组,Arm特征,可选

limit

返回结果数量

返回结果

模型打分服务的返回结果也是json格式,如下:

{
  "output": [
    {
      "id": "123",
      "score": "0.8"
    },
    {
      "id": "223",
      "score": "0.7"
    },
    {
      "id": "323",
      "score": "0.6"
    }
  ]
}

配置参数

配置项

说明

HologresDSN

dict, hologres的链接字符串

SceneConf

dict, 场景配置,场景算法名+算法详细配置

SceneConf.${algo}.AlgoType

算法类型:random,disjoint, hybrid

SceneConf.${algo}.ArmFeatureDao

Arm原始特征表配置,打分服务从该表加载原始Arm特征

SceneConf.${algo}.LinUCBConf

LinUCB算法参数配置

SceneConf.${algo}.LinUCBConf.Alpha

用来平衡Exploration&Exploitation的参数,值越大越偏向于Exploration

SceneConf.${algo}.LinUCBConf.GlobalModelParamId

Hybrid算法的共享特征参数在 ModelTable 中的Key

SceneConf.${algo}.LinUCBConf.HologresName

Hologres链接字符串字典的key

SceneConf.${algo}.LinUCBConf.ModelTable

模型参数Hologres表

SceneConf.${algo}.LinUCBConf.FeatureTable

FG之后的特征向量Hologres表

SceneConf.${algo}.LinUCBConf.FeatureTablePKey

FG之后的特征向量Hologres表的主键

SceneConf.${algo}.LinUCBConf.ArmIdKey

ArmId在Hologres表的字段名

SceneConf.${algo}.LinUCBConf.CacheMaxSize

缓存在本地内存的模型参数最大数量

SceneConf.${algo}.LinUCBConf.CacheTimeInSeconds

本地缓存的有效时间, 单位:秒

SceneConf.${algo}.LinUCBConf.RequestArmNumPerTime

每次请求最多同步多少个模型参数

SceneConf.${algo}.LinUCBConf.RequestArmInterval

模型参数同步的时间间隔

SceneConf.${algo}.LinUCBConf.Parallelism

模型预测的并行度

SceneConf.${algo}.FeatureConf

FeatureGenerator特征配置

备注:

  • AlgoType: 算法类型

  • random表示随机从输入arm candidates中返回指定数量的arm;

  • disjoint表示不共享权重参数的linucb算法;

  • hybrid表示部分共享权重参数的linucb算法

完整配置文件示例

{
  "HologresDSN": {
    "vv_rec": "postgres://${asscessId}:${asscessKey}@hgpostcn-cn-xxxx-cn-beijing-vpc.hologres.aliyuncs.com:80/${db_name}?sslmode=disable&connect_timeout=10"
  },
  "AlgoConf": {
    "default": {
      "AlgoType": "random"
    },
    "cold_start": {
      "ArmFeatureDao": [
        {
          "HologresName": "vv_rec",
          "HologresTableName": "sv_rec.sv_dropoutnet_embedding",
          "FeatureKey": "svid",
          "SelectFields": "svid,embedding"
        }
      ],
      "AlgoType": "hybrid",
      "CompressFeature": false,
      "LinUCBConf": {
        "Alpha": 1.0,
        "ArmIdKey": "arm_id",
        "HologresName": "vv_rec",
        "ModelTable": "sv_rec.contextual_bandit_models_v2",
        "FeatureTable": "sv_rec.contextual_bandit_features_v2",
        "FeatureTablePKey": "user_id,arm_id",
        "CacheTimeInSeconds": 86400,
        "CacheMaxSize": 100000,
        "RequestArmNumPerTime": 100,
        "RequestArmInterval": 5,
        "Parallelism": 8
      },
      "FeatureConf": [
        {
          "feature_type": "raw_feature",
          "expression": "user:ColdStartVideoVectorRecall_embedding",
          "value_dimension": 64,
          "separator": ","
        },
        {
          "feature_type": "raw_feature",
          "expression": "arm:embedding",
          "value_dimension": 64,
          "share_weight": true
        },
        {
          "feature_type": "raw_feature",
          "expression": "arm:recall_score",
          "share_weight": true
        }
      ]
    },
    "linucb": {
      "ArmFeatureDao": [
        {
          "HologresName": "vv_rec",
          "HologresTableName": "vvarticle.smart_video",
          "FeatureKey": "smartVideoId",
          "SelectFields": "*"
        }
      ],
      "AlgoType": "disjoint",
      "CompressFeature": true,
      "LinUCBConf": {
        "Alpha": 1.0,
        "ArmIdKey": "arm_id",
        "HologresName": "vv_rec",
        "ModelTable": "sv_rec.contextual_bandit_models",
        "FeatureTable": "sv_rec.contextual_bandit_features",
        "FeatureTablePKey": "user_id,arm_id",
        "CacheTimeInSeconds": 86400,
        "CacheMaxSize": 100000,
        "RequestArmNumPerTime": 100,
        "RequestArmInterval": 5,
        "Parallelism": 8
      },
      "FeatureConf": [
        {
          "feature_type": "binary_feature",
          "expression": "gender",
          "vocab_list": ["M"]
        },
        {
          "feature_type": "raw_feature",
          "expression": "is_member"
        },
        {
          "feature_type": "raw_feature",
          "expression": "is_new_userid"
        },
        {
          "feature_type": "id_feature",
          "expression": "province",
          "hash_bucket_size": 36
        },
        {
          "feature_type": "id_feature",
          "expression": "constellation",
          "vocab_list": ["巨蟹座", "金牛座", "摩羯座", "狮子座", "双子座", "白羊座", "天蝎座", "双鱼座", "射手座", "水瓶座", "处女座", "天秤座"]
        },
        {
          "feature_type": "id_feature",
          "expression": "birthyear",
          "boundaries": [1967, 1971, 1974, 1977, 1980, 1982, 1985, 1988, 1992, 2001]
        },
        {
          "feature_type": "id_feature",
          "expression": "fans_num",
          "boundaries": [2, 7, 16, 29, 54, 104, 210, 455, 1022]
        },
        {
          "feature_type": "id_feature",
          "expression": "follow_num",
          "boundaries": [1, 4, 9, 17, 30, 53, 99, 214, 544]
        },
        {
          "feature_type": "id_feature",
          "expression": "visitor_num",
          "boundaries": [0, 58, 157, 349, 795, 1865, 4796, 12664, 35753]
        },
        {
          "feature_type": "id_feature",
          "expression": "level",
          "num_buckets": 50,
          "offset": 1
        },
        {
          "feature_type": "geohash_feature",
          "expression": ["latitude", "longitude"],
          "geohash_precision": 4,
          "hash_bucket_size": 128
        },
        {
          "feature_type": "id_feature",
          "expression": "familyid",
          "hash_bucket_size": 50
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_exposure_cnt_distinct_svid_15",
          "boundaries": [63, 159, 252, 348, 439, 508, 580, 679, 878]
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_click_cnt_15",
          "boundaries": [0, 3, 7, 13, 19, 27, 42, 72, 151]
        },
        {
          "feature_type": "binary_feature",
          "expression": "os",
          "vocab_list": ["ios"]
        },
        {
          "feature_type": "combo_feature",
          "expression": ["os", "os_version"],
          "hash_bucket_size": 100
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_likes_comment_collect_share_cnt_15",
          "boundaries": [0, 1, 2, 3, 6, 11, 27]
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_max_duration_15",
          "boundaries": [13.3, 44, 80.8, 137, 200.8, 240.4, 276.9, 317.9, 443.9]
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_min_duration_15",
          "boundaries": [0, 0.1, 5.1, 6.2, 7, 8, 9.7, 12.7]
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_avg_duration_15",
          "boundaries": [11, 20.15, 25.2857, 29.3875, 32.8862, 36.2385, 39.915, 44.7783, 54.0227]
        },
        {
          "feature_type": "id_feature",
          "expression": "author_play_ct",
          "boundaries": [0, 50, 356, 2130]
        },
        {
          "feature_type": "id_feature",
          "expression": "user_auth_type",
          "vocab_list": ["0", "1", "13", "24", "14", "20", "30", "11", "5", "15", "3", "16", "12", "2", "10", "29", "19", "4", "17", "21", "31", "25", "7", "8", "9"]
        },
        {
          "feature_type": "id_feature",
          "expression": "author_av_ct",
          "boundaries": [0, 1, 2, 5, 14, 34, 90]
        },
        {
          "feature_type": "id_feature",
          "expression": "flower_ct",
          "boundaries": [0, 72, 347, 1070, 2610, 6463, 16157]
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_avg_hot_15",
          "boundaries": [0, 0.018, 0.0741, 0.25, 8.53, 46.37, 94.11, 159.86]
        },

        {
          "feature_type": "id_feature",
          "expression": "diamond_ct",
          "boundaries": [0, 10, 50, 160, 460, 1332, 4910]
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_exposure_cnt_distinct_svid_7",
          "boundaries": [36, 93, 146, 201, 248, 285, 332, 399, 521]
        },
        {
          "feature_type": "id_feature",
          "expression": "family_member_ct",
          "boundaries": [0, 82, 159, 234, 322, 438, 642, 1113]
        },
        {
          "feature_type": "id_feature",
          "expression": "author_sv_ct",
          "boundaries": [0, 2, 8, 34]
        },
        {
          "feature_type": "id_feature",
          "expression": "userid_exposure_cnt_15",
          "boundaries": [63, 162, 257, 354, 446, 514, 587, 687, 890]
        }
      ]
    }
  }
}