类参考
FeatureSpec
待查询特征的配置描述类,适用于非自动改图模式。
| 参数名 | 类型 | 必选/可选 | 说明 |
|---|---|---|---|
| index_key | int/string | 可选 | 索引键。默认值:table_name的值。 取值范围: |
| table_name | string | 可选 | 表名。 表名长度范围:[1, 255]。 |
| access_threshold | int | 可选 | 特征准入阈值。 取值范围:[-1, 2147483647]。 |
| eviction_threshold | int | 可选 | 特征淘汰阈值。 取值范围:[-1, 2147483647]。 |
| is_timestamp | bool | 可选 | 是否为时间戳。 取值范围:True、False。 |
| batch_size | int | 可选 | 数据集batch的大小。 取值范围:[1, 2147483647]。 |
| faae_coefficient | int | 可选 | 特征准入系数。默认值:1。 取值范围:[1, 2147483647]。 |
| name | string | 必选 | FeatureSpec名称。长度范围:[1,255]。 |
from mx_rec.core.asc.feature_spec import FeatureSpec
feature_spec_list = FeatureSpec("user_ids", table_name="user_table",
access_threshold=1,
eviction_threshold=1,
faae_coefficient=1)
GraphModifierHook
自动改图Hook类,仅在使用Estimator训练模式下使用,添加后即可开启自动改图功能。
| 参数名 | 类型 | 必选/可选 | 说明 |
|---|---|---|---|
| dump_graph | bool | 可选 | 是否保存TensorFlow当前计算图,默认为False。 |
| modify_graph | bool | 可选 | 是否开启自动改图功能,默认为True。 |
from mx_rec.graph.modifier import GraphModifierHook
#定义数据处理函数
def input_fn():
pass
est.train(input_fn=lambda: input_fn(), hooks=[GraphModifierHook()]) #est为创建的NPUEstimator对象
EvictHook
特征淘汰Hook类,仅在特征准入与淘汰模式下使用,配合特征淘汰的阈值“eviction_threshold”设置,添加后即可开启特征淘汰功能。
Note
特征淘汰Hook类仅支持在训练场景下使用。
| 参数名 | 类型 | 必选/可选 | 说明 |
|---|---|---|---|
| evict_enable | bool | 可选 | 是否开启特征淘汰功能,默认为False。 |
| evict_time_interval | int | 可选 | 淘汰功能触发时间间隔,单位:秒,默认为24 * 60 * 60。取值范围:[1, MAXINT32]。 |
| evict_step_interval | int | 可选 | 淘汰功能触发步数间隔,单位:步,默认为None。取值范围:[1, MAXINT32]。 |
from mx_rec.core.feature_process import EvictHook
hooks_list = []
hook_evict = EvictHook(evict_enable=True, evict_time_interval=30, evict_step_interval=20)
hooks_list.append(hook_evict)
#定义数据处理函数
def input_fn():
pass
est.train(input_fn=lambda: input_fn(), hooks=hooks_list) #est为创建的NPUEstimator对象
ConfigInitializer
保存全局配置信息的管理类,为单例模式。
该类通过init()函数自动初始化,不需要手动进行构建。同时,本章节只列举该类中对外公开的接口,剩余未在此处公示的为内部接口,不推荐直接调用。
| 接口 | 作用 | 原型 |
|---|---|---|
| get_instance() | 获取ConfigInitializer的全局唯一实例。 | from mx_rec.util.initialize import ConfigInitializerConfigInitializer.get_instance() |
| use_dynamic_expansion() | 请参见use_dynamic_expansion。 | |
| get_target_batch() | 请参见get_target_batch。 | |
| if_load() | 请参见if_load。 | |
| get_initializer(is_training) | 请参见get_initializer。 | |
| ascend_global_hashtable_collection() | 请参见ascend_global_hashtable_collection。 |
TrainParamsConfig
保存训练任务参数配置的数据类,例如哈希表集合的名字。
该类通过init()函数自动初始化,不需要手动进行构建。同时,本章节只列举该类中对外公开的接口,剩余未在此处公示的为内部接口,不推荐直接调用。
| 接口 | 作用 |
|---|---|
| ascend_global_hashtable_collection() | 请参见ascend_global_hashtable_collection。 |