文档
注册

特征准入与淘汰

当某些特征的频率过低时,对模型的训练效果不会有帮助,还会造成内存浪费以及过拟合的问题。因此需要特征准入功能来过滤掉频率过低的特征。

对于一些对训练没有帮助的特征,我们需要将其淘汰以免影响训练效果,同时也能节约内存。在mxRec中我们支持特征淘汰功能,并提供了两种特征淘汰的触发方式,一是根据global step触发淘汰,二是根据时间间隔触发淘汰。

使用流程介绍

本节介绍如何使用特征准入与淘汰进行训练,涉及FeatureSpec模式与自动改图模式,对应流程请参见特征准入与淘汰

图1 特征准入与淘汰使用流程

关键步骤介绍

  • 在FeatureSpec模式下,请参考FeatureSpec进行配置。
    1. 开启准入功能仅需要设置准入阈值“access_threshold”大于0(单位:次),设置阈值等于或者小于0时将会报错。
    2. 开启淘汰功能需要依次执行以下步骤:
      1. 设置淘汰阈值“eviction_threshold”大于0(单位:秒),设置阈值等于或者小于0时报错。
      2. 设置“index_key”索引键为“timestamp”的FeatureSpec并携带参数is_timestamp=True,代表数据集含有时间戳。
      3. 使用_EvictHook接口为淘汰的触发方式设置“hook”,接口参数有三个,evict_enable=Trueevict_time_interval=24 * 60 * 60evict_step_interval=10000,分别代表淘汰功能开关、淘汰触发的时间间隔(单位:秒)、global step间隔。“evict_time_interval”“evict_step_interval”参数可选其一。
  • 在自动改图模式下,请参考自动改图进行配置。

    仅需要在使用sparse_lookup接口时,设置“access_and_evict_config”参数,参数类型dict,该dict由两个key-value对组成,key分别为“access_threshold”“eviction_threshold”value为对应的阈值。

示例代码

  1. FeatureSpec模式。
    feature_spec_list = [FeatureSpec("user_ids", feat_count=cfg.user_feat_cnt, table_name="user_table",
                                     access_threshold=cfg.access_threshold,
                                     eviction_threshold=cfg.eviction_threshold),
                         FeatureSpec("item_ids", feat_count=cfg.item_feat_cnt, table_name="item_table",
                                     access_threshold=cfg.access_threshold,
                                     eviction_threshold=cfg.eviction_threshold),
                         FeatureSpec("timestamp", is_timestamp=True)]
    hook_evict = _EvictHook(evict_enable=True, evict_time_interval=24*60*60, evict_step_interval=10000)
  2. 自动改图模式。
    config_for_user_table = dict(access_threshold=cfg.access_threshold, eviction_threshold=cfg.eviction_threshold)
    embedding = sparse_lookup(hash_table, feature, send_count, dim=None, is_train=is_train,
                              access_and_evict_config=config_for_user_table ,
                              name=hash_table.table_name + "_lookup", modify_graph=modify_graph)
    hook_evict = _EvictHook(evict_enable=True, evict_time_interval=24*60*60, evict_step_interval=10000)
搜索结果
找到“0”个结果

当前产品无相关内容

未找到相关内容,请尝试其他搜索词