Skip to content

feature: Add Jumpstart example notebooks #3068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 72 additions & 3 deletions doc/doc_utils/jumpstart_doc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,73 @@
from urllib import request
import json
from packaging.version import Version
from enum import Enum


class Tasks(str, Enum):
"""The ML task name as referenced in the infix of the model ID."""

IC = "ic"
OD = "od"
OD1 = "od1"
SEMSEG = "semseg"
IS = "is"
TC = "tc"
SPC = "spc"
EQA = "eqa"
TEXT_GENERATION = "textgeneration"
IC_EMBEDDING = "icembedding"
TC_EMBEDDING = "tcembedding"
NER = "ner"
SUMMARIZATION = "summarization"
TRANSLATION = "translation"
TABULAR_REGRESSION = "regression"
TABULAR_CLASSIFICATION = "classification"


class ProblemTypes(str, Enum):
"""Possible problem types for JumpStart models."""

IMAGE_CLASSIFICATION = "Image Classification"
IMAGE_EMBEDDING = "Image Embedding"
OBJECT_DETECTION = "Object Detection"
SEMANTIC_SEGMENTATION = "Semantic Segmentation"
INSTANCE_SEGMENTATION = "Instance Segmentation"
TEXT_CLASSIFICATION = "Text Classification"
TEXT_EMBEDDING = "Text Embedding"
QUESTION_ANSWERING = "Question Answering"
SENTENCE_PAIR_CLASSIFICATION = "Sentence Pair Classification"
TEXT_GENERATION = "Text Generation"
TEXT_SUMMARIZATION = "Text Summarization"
MACHINE_TRANSLATION = "Machine Translation"
NAMED_ENTITY_RECOGNITION = "Named Entity Recognition"
TABULAR_REGRESSION = "Regression"
TABULAR_CLASSIFICATION = "Classification"


JUMPSTART_REGION = "eu-west-2"
SDK_MANIFEST_FILE = "models_manifest.json"
JUMPSTART_BUCKET_BASE_URL = "https://jumpstart-cache-prod-{}.s3.{}.amazonaws.com".format(
JUMPSTART_REGION, JUMPSTART_REGION
)
TASK_MAP = {
Tasks.IC: ProblemTypes.IMAGE_CLASSIFICATION,
Tasks.IC_EMBEDDING: ProblemTypes.IMAGE_EMBEDDING,
Tasks.OD: ProblemTypes.OBJECT_DETECTION,
Tasks.OD1: ProblemTypes.OBJECT_DETECTION,
Tasks.SEMSEG: ProblemTypes.SEMANTIC_SEGMENTATION,
Tasks.IS: ProblemTypes.INSTANCE_SEGMENTATION,
Tasks.TC: ProblemTypes.TEXT_CLASSIFICATION,
Tasks.TC_EMBEDDING: ProblemTypes.TEXT_EMBEDDING,
Tasks.EQA: ProblemTypes.QUESTION_ANSWERING,
Tasks.SPC: ProblemTypes.SENTENCE_PAIR_CLASSIFICATION,
Tasks.TEXT_GENERATION: ProblemTypes.TEXT_GENERATION,
Tasks.SUMMARIZATION: ProblemTypes.TEXT_SUMMARIZATION,
Tasks.TRANSLATION: ProblemTypes.MACHINE_TRANSLATION,
Tasks.NER: ProblemTypes.NAMED_ENTITY_RECOGNITION,
Tasks.TABULAR_REGRESSION: ProblemTypes.TABULAR_REGRESSION,
Tasks.TABULAR_CLASSIFICATION: ProblemTypes.TABULAR_CLASSIFICATION,
}


def get_jumpstart_sdk_manifest():
Expand All @@ -36,6 +97,11 @@ def get_jumpstart_sdk_spec(key):
return json.loads(model_spec)


def get_model_task(id):
task_short = id.split("-")[1]
return TASK_MAP[task_short] if task_short in TASK_MAP else "Source"


def create_jumpstart_model_table():
sdk_manifest = get_jumpstart_sdk_manifest()
sdk_manifest_top_versions_for_models = {}
Expand Down Expand Up @@ -69,26 +135,29 @@ def create_jumpstart_model_table():
)
file_content.append(
"""
Each model id is linked to an external page that describes the model.\n
Click on the Problem Type to navigate to the source of the model.\n
"""
)
file_content.append("\n")
file_content.append(".. list-table:: Available Models\n")
file_content.append(" :widths: 50 20 20 20\n")
file_content.append(" :widths: 50 20 20 20 30\n")
file_content.append(" :header-rows: 1\n")
file_content.append(" :class: datatable\n")
file_content.append("\n")
file_content.append(" * - Model ID\n")
file_content.append(" - Fine Tunable?\n")
file_content.append(" - Latest Version\n")
file_content.append(" - Min SDK Version\n")
file_content.append(" - Problem Type/Source\n")

for model in sdk_manifest_top_versions_for_models.values():
model_spec = get_jumpstart_sdk_spec(model["spec_key"])
file_content.append(" * - `{} <{}>`_\n".format(model_spec["model_id"], model_spec["url"]))
model_task = get_model_task(model_spec["model_id"])
file_content.append(" * - {}\n".format(model_spec["model_id"]))
file_content.append(" - {}\n".format(model_spec["training_supported"]))
file_content.append(" - {}\n".format(model["version"]))
file_content.append(" - {}\n".format(model["min_version"]))
file_content.append(" - `{} <{}>`__\n".format(model_task, model_spec["url"]))

f = open("doc_utils/jumpstart.rst", "w")
f.writelines(file_content)
40 changes: 37 additions & 3 deletions doc/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -573,15 +573,49 @@ Here is an example:
# When you are done using your endpoint
model.sagemaker_session.delete_endpoint('my-endpoint')

********************************************
Use Prebuilt Models with SageMaker JumpStart
********************************************
*********************************************************
Use SageMaker JumpStart Algorithms with Pretrained Models
*********************************************************

JumpStart for the SageMaker Python SDK uses model ids and model versions to access the necessary
utilities. This table serves to provide the core material plus some extra information that can be useful
in selecting the correct model id and corresponding parameters.

.. toctree::
:maxdepth: 2

doc_utils/jumpstart

Example notebooks
=================

JumpStart supports 15 different machine learning problem types. Below is a list of all the supported
problem types with a link to a Jupyter notebook that provides example usage.

Vision
- `Image Classification <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_image_classification/Amazon_JumpStart_Image_Classification.ipynb>`__
- `Object Detection <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_object_detection/Amazon_JumpStart_Object_Detection.ipynb>`__
- `Semantic Segmentation <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_semantic_segmentation/Amazon_JumpStart_Semantic_Segmentation.ipynb>`__
- `Instance Segmentation <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_instance_segmentation/Amazon_JumpStart_Instance_Segmentation.ipynb>`__
- `Image Embedding <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_image_embedding/Amazon_JumpStart_Image_Embedding.ipynb>`__

Text
- `Text Classification <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_text_classification/Amazon_JumpStart_Text_Classification.ipynb>`__
- `Sentence Pair Classification <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_sentence_pair_classification/Amazon_JumpStart_Sentence_Pair_Classification.ipynb>`__
- `Question Answering <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_question_answering/Amazon_JumpStart_Question_Answering.ipynb>`__
- `Named Entity Recognition <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_named_entity_recognition/Amazon_JumpStart_Named_Entity_Recognition.ipynb>`__
- `Text Summarization <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_text_summarization/Amazon_JumpStart_Text_Summarization.ipynb>`__
- `Text Generation <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_text_generation/Amazon_JumpStart_Text_Generation.ipynb>`__
- `Machine Translation <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_machine_translation/Amazon_JumpStart_Machine_Translation.ipynb>`__
- `Text Embedding <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_text_embedding/Amazon_JumpStart_Text_Embedding.ipynb>`__

Tabular
- `Tabular Classification (LightGBM & Catboost) <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_tabular_classification/Amazon_JumpStart_Tabular_Classification_LightGBM_CatBoost.ipynb>`__
- `Tabular Classification (XGBoost & Linear Learner) <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_tabular_classification/Amazon_JumpStart_Tabular_Classification_XGBoost_LinearLearner.ipynb>`__
- `Tabular Regression (LightGBM & Catboost) <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_tabular_regression/Amazon_JumpStart_Tabular_Regression_LightGBM_CatBoost.ipynb>`__
- `Tabular Regression (XGBoost & Linear Learner) <https://github.com/aws/amazon-sagemaker-examples/blob/main/introduction_to_amazon_algorithms/jumpstart_tabular_regression/Amazon_JumpStart_Tabular_Regression_XGBoost_LinearLearner.ipynb>`__


`Amazon SageMaker JumpStart <https://aws.amazon.com/sagemaker/getting-started/>`__ is a
SageMaker feature that helps users bring machine learning (ML)
applications to market using prebuilt solutions for common use cases,
Expand Down