API Reference

read_target_entity_ids

monad.ui.module.read_target_entity_ids

monad.ui.module.read_target_entity_ids(predictions_file, checkpoint_path)

Returns a mapping from entity ids to their indices in the decoded sketch.

from  monad.ui.module import readout_sketch, read_target_entity_ids

# declare variables
checkpoint_path = "<path/to/downstream/model/checkpoints>" # location of recommendation model checkpoints
predictions_file = "<path/to/predictions/my_predictions.tsv>" # location where encoded predictions are stored
target_feature_value = "12345" # product id for which we want to get scores

# Get a generator yielding entity id and all scored products
scored_products_generator = readout_sketch(
  predictions_file=predictions_file, 
  checkpoint_path=checkpoint_path,
)

# get mapping of target values to score index
target_to_index = read_target_entity_ids(checkpoint_path=checkpoint_path)

for entity_id, scored_products in scored_products_generator:
  	# score index of a selected product
    score_index = target_to_index[target_feature_value]
    # score of a selected product
    score = scored_products[score_index]
    
    print(f"The score for customer {entity_id} and product {target} is {score}")
Parameters

checkpoint_path: str
Path to saved model checkpoint.

Returns

dict[str, int] the dictionary with the following structure:

  • keys - target feature values,
  • values - indexes of products in the array returned by readout_sketch.