Papers with Code Model Index
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
- gotcha The package name on PyPI is `model-index` (with a hyphen). An alias package `modelindex` (without a hyphen) exists but primarily serves as a dependency for `model-index`. Always use `pip install model-index` to ensure you get the correct, maintained library.
- gotcha The `model-index` library relies heavily on the correct structure and syntax of `model-index.yml` and referenced metadata files (YAML, JSON, Markdown). Incorrect formatting, broken relative paths, or non-adherence to the Papers with Code schema can lead to parsing errors or validation failures.
- gotcha While a Python API exists for programmatic interaction (e.g., loading the index), much of the official documentation and usage examples emphasize defining metadata via `model-index.yml` files and processing them with the provided command-line interface (CLI) tool (`mi`). Explicit Python API quickstart examples for building an index programmatically from scratch are less prevalent.
Install
-
pip install model-index
Imports
- ModelIndex
from modelindex.models import ModelIndex
Quickstart
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}")