Model hit rate evaluation

Updated at:

Compute hit rates for retrieved items against ground truth to evaluate recommendation model recall quality.

Limitations

Requires MaxCompute resources.

Configure the component in PAI console

Input ports

Two input ports, listed left to right:

Input port Data type Recommended upstream component PAI command parameter Required
Item embedding table name MaxCompute table SQL Script, Read Table Passed in as the tables parameter Yes
Ground truth table name MaxCompute table SQL Script, Read Table Passed in as the tables parameter Yes

Parameters

Configure these parameters on the Parameters Setting tab:

Parameter Required Description PAI command parameter Default value
recall_type No Retrieval mode. Valid values: u2i (user-to-item), i2i (item-to-item). recall_type u2i
top_k hitrate No Number of top results to retrieve for hit rate evaluation. top_k 200
embedding dimension No Dimension of the embedding vectors. emb_dim 32
knn_metric No Similarity metric for recall. Valid values: 0 (L2 distance), 1 (inner product similarity). knn_metric 0
use exact search:knn_strict No Whether to use exact k-nearest neighbors (kNN) search. Valid values: True (exact kNN, higher compute cost), False (approximate kNN). knn_strict True
batch_size No Number of samples processed simultaneously. batch_size 1024
max number of interests:num_interests No Maximum number of interest vectors. num_interests 1
Specify the algorithm version Yes EasyRec algorithm package to run. Steps: 1. Generate an EasyRec .tar.gz package (see Release & Upgrade). 2. Upload to OSS (see Upload objects). 3. Select the uploaded package. script N/A

Configure these parameters on the Tuning tab (passed as the cluster parameter in PAI commands):

Parameter Required Description Default value
ps Count No Number of Parameter Server (PS) nodes. 2
ps CPU No Number of vCPUs per PS node (1 = one vCPU). 10
ps Memory No Memory size per PS node in MB. 40000
Worker Count No Number of worker nodes. 6
Worker CPU No Number of vCPUs per worker node (1 = one vCPU). 8
Worker Memory No Memory size per worker node in MB. 40000
Worker GPU No GPUs per worker node. Not required for most EasyRec training jobs. 0

Output ports

Two output ports, listed left to right:

Output port Data type PAI command parameter Required
hit_rate_details MaxCompute table Passed in as the outputs parameter Yes
total_hit_rate MaxCompute table Passed in as the outputs parameter Yes

Configure the component using PAI commands

Run PAI commands through SQL scripts. See SQL Script.

Command syntax

PAI -name tensorflow1120_cpu_ext
  -project algo_public
  -Darn="acs:ram::xxx:role/aliyunodpspaidefaultrole"
  -Dbuckets="oss://examplebucket/"
  -DossHost="oss-cn-hangzhou-internal.aliyuncs.com"
  -DentryFile="easy_rec/python/tools/hit_rate_pai.py"
  -Dcluster="{\"ps\": {\"count\": 2, \"cpu\": 1000, \"memory\": 40000}, \"worker\": {\"count\": 6, \"cpu\": 800, \"gpu\": 0, \"memory\": 40000}}"
  -Dtables="odps://pai_hangzhou/tables/pai_temp_flow_vjmgur2q5ca5lz****_node_j5c8mx2h26wqxu****_outputTable/,odps://pai_hangzhou/tables/pai_temp_flow_hfd4fk1z1ba9z5****_node_msqfceossxpy7v****_outputTable/"
  -Doutputs="odps://pai_hangzhou/tables/pai_temp_flow_1y1h6j8bnl94ao****_node_74kp8xcaugwmy8****_hit_rate_details,odps://pai_hangzhou/tables/pai_temp_flow_1y1h6j8bnl94ao****_node_74kp8xcaugwmy8****_total_hit_rate"
  -DuserDefinedParameters="--recall_type=u2i --top_k=200 --emb_dim=32 --knn_metric=0 --knn_strict=True --batch_size=1024 --num_interests=1"
  -Dscript="oss://examplebucket/easy_rec_ext_0.6.1_res.tar.gz"

Parameter descriptions

Parameter Description Required
entryFile Entry file. Run the hit_rate_pai.py script for hit rate evaluation. Yes
tables Input tables: item embedding table and ground truth table, comma-separated. Yes
outputs Output tables: hit_rate_details table and total_hit_rate table, comma-separated. Yes
arn Resource authorization information for the RAM role. To get the ARN, log on to the PAI console and choose Activation & Authorization > Dependent Services. In the Designer section, click View Authorization in the Actions column. Yes
ossHost OSS endpoint. See Regions and endpoints. Yes
buckets OSS bucket storing the model file. Separate multiple buckets with commas. Example: oss://xxxx/,oss://xxxx/. Yes
userDefinedParameters Additional parameters not specified in the pipeline: recall_type, top_k, emb_dim, knn_metric, knn_strict, batch_size, and num_interests. No
script OSS path of EasyRec .tar.gz package. See Release & Upgrade for package generation. No

Example

This example creates item embedding and ground truth tables, uploads sample data, and runs the Model Hitrate Eval component in a pipeline.

Step 1: Create the input tables

Run these commands on the MaxCompute client to create the item embedding and ground truth tables. See MaxCompute client (odpscmd).

CREATE TABLE IF NOT EXISTS dssm_recall_item_embedding_tmp_for_eval_v1
(
    item_id bigint
    , item_emb string COMMENT 'Item Embedding'
);
CREATE TABLE IF NOT EXISTS dssm_recall_vector_recall_sample_eval_sequence_v1
(
    requestid string
    ,item_ids string
    , user_emb string COMMENT 'User Embedding'
    ,emb_num bigint
);

Step 2: Upload sample data

Download the sample data files (item_embedding.csv and ground.csv). Upload them to MaxCompute tables using Tunnel commands (see Tunnel commands).

Specify the directory containing the CSV file or its absolute path:

tunnel upload item_embedding.csv dssm_recall_item_embedding_tmp_for_eval_v1 -fd \t;
tunnel upload ground.csv dssm_recall_vector_recall_sample_eval_sequence_v1 -fd \t;

Step 3: Build the pipeline

Create a pipeline as shown:

cf1ac196182ff9c2d07f8ec2c4172534..png
Section Description
1 Set Table Name for the Read Table-3 component to dssm_recall_item_embedding_tmp_for_eval_v1.
2 Set Table Name for the Read Table-4 component to dssm_recall_vector_recall_sample_eval_sequence_v1.
3 Connect the left input port to Read Table-3 and the right input port to Read Table-4. Set Specify the algorithm version to the OSS path of the uploaded EasyRec .tar.gz package. For package preparation, see the "Configure the component in PAI console" section. This example uses 18_rec_sln_demo_dssm_recall_total_hit_rate_v1_2 to configure the .tar.gz file (see DSSM vector recall).

Step 4: Run the pipeline

Click the image icon to run the pipeline.

Step 5: View the results

After the pipeline finishes, right-click Model Hitrate Eval and select View Data. Two output tables are available:

  • hit_rate_details

    image..png

  • total_hit_rate

    image..png

References

For a complete end-to-end example, see 18_rec_sln_demo_dssm_recall_total_hit_rate_v1 in DSSM vector recall.