Class: DurableHuggingfaceHub::ModelCard

Inherits:
RepoCard
  • Object
show all
Defined in:
lib/durable_huggingface_hub/repo_card.rb

Overview

Model card for documenting machine learning models.

Model cards provide essential information about models including:

  • Model architecture and training details

  • Intended use and limitations

  • Training data and evaluation results

  • Ethical considerations

Examples:

Create a model card

card = ModelCard.new(
  text: "# BERT Base Uncased\n\nBERT model trained on...",
  data: {
    "license" => "apache-2.0",
    "language" => "en",
    "tags" => ["bert", "nlp"]
  }
)

Instance Attribute Summary

Attributes inherited from RepoCard

#data, #text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RepoCard

from_hub, #initialize, load, parse, #push_to_hub, #save, #to_s, #update_metadata

Constructor Details

This class inherits a constructor from DurableHuggingfaceHub::RepoCard

Class Method Details

.default_repo_typeString

Returns Default repository type for model cards.

Returns:

  • (String)

    Default repository type for model cards



248
249
250
# File 'lib/durable_huggingface_hub/repo_card.rb', line 248

def self.default_repo_type
  "model"
end

Instance Method Details

#add_evaluation_result(task_type:, dataset_name:, metric_name:, metric_value:) ⇒ Object

Add evaluation results to the model card metadata.

Examples:

Add evaluation result

card.add_evaluation_result(
  task_type: "text-classification",
  dataset_name: "glue",
  metric_name: "accuracy",
  metric_value: 0.95
)

Parameters:

  • task_type (String)

    Type of task (e.g., “text-classification”)

  • dataset_name (String)

    Name of the evaluation dataset

  • metric_name (String)

    Name of the metric

  • metric_value (Numeric)

    Value of the metric



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/durable_huggingface_hub/repo_card.rb', line 303

def add_evaluation_result(task_type:, dataset_name:, metric_name:, metric_value:)
  @data["model-index"] ||= []

  model_index = @data["model-index"].first || {}
  model_index["results"] ||= []

  result = {
    "task" => { "type" => task_type },
    "dataset" => { "name" => dataset_name },
    "metrics" => [{ "name" => metric_name, "value" => metric_value }]
  }

  model_index["results"] << result
  @data["model-index"] = [model_index] if @data["model-index"].empty?
end

#validateArray<String>

Validate model card metadata.

Returns:

  • (Array<String>)

    List of validation errors



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/durable_huggingface_hub/repo_card.rb', line 255

def validate
  errors = []

  # Check for required fields
  errors << "license is required" unless @data["license"]
  errors << "language is required" unless @data["language"]

  # Validate license format (should be SPDX identifier)
  if @data["license"] && !@data["license"].is_a?(String)
    errors << "license must be a string"
  end

  # Validate language format
  if @data["language"]
    if @data["language"].is_a?(String)
      # Single language
    elsif @data["language"].is_a?(Array)
      # Multiple languages
      @data["language"].each do |lang|
        errors << "language array elements must be strings" unless lang.is_a?(String)
      end
    else
      errors << "language must be a string or array of strings"
    end
  end

  # Validate tags format
  if @data["tags"] && !@data["tags"].is_a?(Array)
    errors << "tags must be an array"
  end

  errors
end