Papers with Code Model Index

0.1.11 · active · verified Sun Apr 12

The model-index library helps machine learning researchers and engineers maintain a single source of truth for their ML model metadata. It allows storing metadata flexibly in JSONs, YAMLs, or markdown annotations, and enables browsing and comparing models on Papers with Code. The library is currently at version 0.1.11 and appears to have an active, though not rapid, release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a `model-index.yml` file and then programmatically load and inspect its contents using the `model-index` Python library. It highlights how the library facilitates reading structured model metadata into Python objects.

import os
from pathlib import Path
from modelindex.models import ModelIndex

# 1. Create a dummy model-index.yml file for demonstration
model_index_content = '''
Models:
  - Name: MyAwesomeModelV1
    Metadata:
      Task: Image Classification
      Dataset: CIFAR-10
      Metrics:
        Accuracy: 0.92
      Paper: https://arxiv.org/abs/2301.00001
      Code: https://github.com/myuser/myawesomemodel
      Weights: https://example.com/weights.pth
      License: MIT
  - Name: MyAwesomeModelV2
    Metadata:
      Task: Image Classification
      Dataset: CIFAR-10
      Metrics:
        Accuracy: 0.94
      Paper: https://arxiv.org/abs/2302.00002
      Code: https://github.com/myuser/myawesomemodel
      Weights: https://example.com/weights_v2.pth
      License: Apache-2.0
'''

index_file_path = "model-index.yml"
Path(index_file_path).write_text(model_index_content)

print(f"Created dummy {index_file_path}")

try:
    # 2. Load the model index from the YAML file
    # Note: The exact loading method might vary; .load_from_file() is a common pattern.
    # The library's core is parsing these files.
    model_index = ModelIndex.load_from_file(index_file_path)

    print(f"\nSuccessfully loaded {len(model_index.models)} model(s).")

    # 3. Access data from the loaded index
    for i, model in enumerate(model_index.models):
        print(f"\n--- Model {i+1} ---")
        print(f"Name: {model.name}")
        print(f"Task: {model.metadata['Task']}")
        print(f"Accuracy: {model.metadata['Metrics']['Accuracy']}")
        print(f"Paper: {model.metadata['Paper']}")

except Exception as e:
    print(f"An error occurred during loading or processing: {e}")
finally:
    # Clean up the dummy file
    if Path(index_file_path).exists():
        os.remove(index_file_path)
        print(f"\nCleaned up {index_file_path}")

view raw JSON →