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
# path to recommendation model checkpoints
checkpoint_path = "<path/to/downstream/model/checkpoints>"

# path to encoded predictions file
predictions_file = "<path/to/predictions/my_predictions.tsv>"

# product id for which we want to get scores
target_feature_value = "12345"


# 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 indices
target_to_index = read_target_entity_ids(checkpoint_path=checkpoint_path)


for entity_id, scored_products in scored_products_generator:
    # get score index of the selected product
    score_index = target_to_index[target_feature_value]
    
    # get score of the selected product
    score = scored_products[score_index]
    
    print(f"the score for customer {entity_id} and product {target_feature_value} 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.