Class ModelCard

java.lang.Object
org.tribuo.interop.modelcard.ModelCard

public class ModelCard extends Object
ModelCard feature to allow more transparent model reporting.

See:

 M. Mitchell et al.
 "Model Cards for Model Reporting"
 In Conference in Fairness, Accountability, and Transparency, 2019.
 

At the moment, the ModelCard system only supports models trained within Tribuo and throws an error for all external models.

  • Constructor Details

    • ModelCard

      public ModelCard(Model<?> model, Evaluation<?> evaluation, Map<String,Double> testingMetrics, UsageDetails usage)
      Creates an instance of ModelCard.

      Throws IllegalArgumentException if the model is an external model trained outside Tribuo.

      Parameters:
      model - The trained model for which a model card will be built.
      evaluation - An Evaluation object for the trained model.
      testingMetrics - A map of metric descriptions paired with their corresponding metric values for the trained model.
      usage - A UsageDetails object specifying the usage details of the trained model.
    • ModelCard

      public ModelCard(Model<?> model, Evaluation<?> evaluation, UsageDetails usage)
      Creates an instance of ModelCard that does not include any extracted metrics.
      Parameters:
      model - The trained model for which a model card will be built.
      evaluation - An Evaluation object for the trained model.
      usage - A UsageDetails object specifying the usage details of the trained model.
    • ModelCard

      public ModelCard(Model<?> model, Evaluation<?> evaluation, Map<String,Double> testingMetrics)
      Creates an instance of ModelCard that has its UsageDetails set to null.
      Parameters:
      model - The trained model for which a model card will be built.
      evaluation - An Evaluation object for the trained model.
      testingMetrics - A map of metric descriptions paired with their corresponding metric values for the trained model.
    • ModelCard

      public ModelCard(Model<?> model, Evaluation<?> evaluation)
      Creates an instance of ModelCard that does not include any extracted metrics and has its UsageDetails set to null.
      Parameters:
      model - The trained model for which a model card will be built.
      evaluation - An Evaluation object for the trained model.
  • Method Details

    • deserializeFromJson

      public static ModelCard deserializeFromJson(Path sourceFile) throws IOException
      Reads the Json content corresponding to a ModelCard from file and instantiates it.
      Parameters:
      sourceFile - The Json file path corresponding to a serialized ModelCard.
      Returns:
      A ModelCard object corresponding to the provided serialized ModelCard.
      Throws:
      IOException - If the model card could not be read from the path, or the Json failed to parse.
    • deserializeFromJson

      public static ModelCard deserializeFromJson(com.fasterxml.jackson.databind.JsonNode modelCard) throws com.fasterxml.jackson.core.JsonProcessingException
      Reads the Json content corresponding to a ModelCard and instantiates it.
      Parameters:
      modelCard - The Json content corresponding to a serialized ModelCard that will be used to recreate a new instance of a ModelCard.
      Returns:
      A ModelCard object corresponding to the provided serialized ModelCard.
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if a problem is encountered when processing Json content.
    • getModelDetails

      public ModelDetails getModelDetails()
      Gets the ModelDetails of the ModelCard object.
      Returns:
      The ModelDetails of the ModelCard object.
    • getTrainingDetails

      public TrainingDetails getTrainingDetails()
      Gets the TrainingDetails of the ModelCard object.
      Returns:
      The TrainingDetails of the ModelCard object.
    • getTestingDetails

      public TestingDetails getTestingDetails()
      Gets the TestingDetails of the ModelCard object.
      Returns:
      The TestingDetails of the ModelCard object.
    • getUsageDetails

      public UsageDetails getUsageDetails()
      Gets the UsageDetails of the ModelCard object, which may be null.
      Returns:
      The UsageDetails of the ModelCard object.
    • toJson

      public com.fasterxml.jackson.databind.node.ObjectNode toJson()
      Creates a Json object corresponding this ModelCard instance.
      Returns:
      The ObjectNode corresponding to this ModelCard instance.
    • saveToFile

      public void saveToFile(Path destinationFile) throws IOException
      Serializes and saves the ModelCard object to the specified path.
      Parameters:
      destinationFile - The file path to which the serialized ModelCard will be saved.
      Throws:
      IOException - if a problem is encountered when processing Json content or writing the file.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object