{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using AI21 Contextual Answers on SageMaker through Model Packages\n", "\n", "This sample notebook shows you how to deploy **AI21 Contextual Answers** using Amazon SageMaker.\n", "\n", "https://docs.ai21.com/docs/contextual-answers-api
\n", "https://docs.ai21.com/reference/contextual-answers-api-ref\n", "\n", "## Pre-requisites:\n", "1. Before running this notebook, please make sure you got this notebook from the model catalog on SageMaker AWS Management Console.\n", "1. **Note**: This notebook contains elements which render correctly in Jupyter interface. Open this notebook from an Amazon SageMaker Notebook Instance or Amazon SageMaker Studio.\n", "1. Ensure that IAM role used has **AmazonSageMakerFullAccess**.\n", "1. This notebook is intended to work with **boto3 v1.25.4** or higher.\n", "\n", "## Contents:\n", "1. [Select model package](#1.-Select-model-package)\n", "1. [Create an endpoint and perform real-time inference](#2.-Create-an-endpoint-and-perform-real-time-inference)\n", " 1. [Create an endpoint](#A.-Create-an-endpoint)\n", " 1. [Interact with the model](#B.-Interact-with-the-model)\n", " 1. [Ask about financial reports](#C.-Ask-about-financial-reports)\n", "1. [Clean-up](#3.-Clean-up)\n", " 1. [Delete the endpoint](#A.-Delete-the-endpoint)\n", " 1. [Delete the model](#B.-Delete-the-model)\n", "\n", "\n", "## Usage instructions\n", "You can run this notebook one cell at a time (By using Shift+Enter for running a cell)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Select model package\n", "Confirm that you received this notebook from the model catalog in SageMaker AWS Management Console." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [] }, "outputs": [], "source": [ "model_package_map = {\n", " \"us-east-1\": \"arn:aws:sagemaker:us-east-1:865070037744:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"us-east-2\": \"arn:aws:sagemaker:us-east-2:057799348421:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"us-west-1\": \"arn:aws:sagemaker:us-west-1:382657785993:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"us-west-2\": \"arn:aws:sagemaker:us-west-2:594846645681:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"ca-central-1\": \"arn:aws:sagemaker:ca-central-1:470592106596:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"eu-central-1\": \"arn:aws:sagemaker:eu-central-1:446921602837:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"eu-west-1\": \"arn:aws:sagemaker:eu-west-1:985815980388:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"eu-west-2\": \"arn:aws:sagemaker:eu-west-2:856760150666:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"eu-west-3\": \"arn:aws:sagemaker:eu-west-3:843114510376:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"eu-north-1\": \"arn:aws:sagemaker:eu-north-1:136758871317:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"ap-southeast-1\": \"arn:aws:sagemaker:ap-southeast-1:192199979996:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"ap-southeast-2\": \"arn:aws:sagemaker:ap-southeast-2:666831318237:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"ap-northeast-2\": \"arn:aws:sagemaker:ap-northeast-2:745090734665:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"ap-northeast-1\": \"arn:aws:sagemaker:ap-northeast-1:977537786026:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"ap-south-1\": \"arn:aws:sagemaker:ap-south-1:077584701553:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\",\n", " \"sa-east-1\": \"arn:aws:sagemaker:sa-east-1:270155090741:model-package/contextual-answers-1-0-001-a85d7d493b3a39e3a8a8ec734f2befae\"\n", "}" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "tags": [] }, "outputs": [], "source": [ "import json\n", "from sagemaker import ModelPackage\n", "from sagemaker import get_execution_role\n", "import sagemaker as sage\n", "import boto3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Check the version of boto3 - must be v1.25.4 or higher\n", "If you see a lower version number, pick another kernel to run the notebook, with Python 3.8 or above" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "'1.26.114'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "boto3.__version__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Install ai21 python SDK" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Looking in indexes: https://pypi.org/simple, https://pip.repos.neuron.amazonaws.com\n", "Collecting ai21[SM]\n", " Downloading ai21-1.1.4.tar.gz (13 kB)\n", " Preparing metadata (setup.py) ... \u001b[?25ldone\n", "\u001b[?25h\u001b[33mWARNING: ai21 1.1.4 does not provide the extra 'sm'\u001b[0m\u001b[33m\n", "\u001b[0mRequirement already satisfied: requests in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from ai21[SM]) (2.28.1)\n", "Requirement already satisfied: charset-normalizer<3,>=2 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from requests->ai21[SM]) (2.1.1)\n", "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from requests->ai21[SM]) (1.26.8)\n", "Requirement already satisfied: idna<4,>=2.5 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from requests->ai21[SM]) (3.4)\n", "Requirement already satisfied: certifi>=2017.4.17 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from requests->ai21[SM]) (2022.12.7)\n", "Building wheels for collected packages: ai21\n", " Building wheel for ai21 (setup.py) ... \u001b[?25ldone\n", "\u001b[?25h Created wheel for ai21: filename=ai21-1.1.4-py3-none-any.whl size=21794 sha256=ab61a497b0cd881938d0f345f1f10609ce126234b4f4992107785cce0ce78977\n", " Stored in directory: /home/ec2-user/.cache/pip/wheels/07/a4/d2/084c23e5034998226d1d532610766e00f34ca01797938a9d39\n", "Successfully built ai21\n", "Installing collected packages: ai21\n", "Successfully installed ai21-1.1.4\n" ] } ], "source": [ "! pip install -U \"ai21[SM]\"\n", "import ai21" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "tags": [] }, "outputs": [], "source": [ "region = boto3.Session().region_name\n", "if region not in model_package_map.keys():\n", " raise (\"UNSUPPORTED REGION\")\n", "\n", "model_package_arn = model_package_map[region]" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "tags": [] }, "outputs": [], "source": [ "role = get_execution_role()\n", "sagemaker_session = sage.Session()\n", "\n", "runtime_sm_client = boto3.client(\"runtime.sagemaker\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. Create an endpoint and perform real-time inference" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you want to understand how real-time inference with Amazon SageMaker works, see [Documentation](https://docs.aws.amazon.com/sagemaker/latest/dg/deploy-model.html)." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "tags": [] }, "outputs": [], "source": [ "endpoint_name = \"contextual-answers\"\n", "\n", "content_type = \"application/json\"\n", "\n", "real_time_inference_instance_type = (\n", " \"ml.g5.12xlarge\"\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### A. Create an endpoint" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "tags": [] }, "outputs": [ { "ename": "ClientError", "evalue": "An error occurred (ValidationException) when calling the CreateEndpointConfig operation: Cannot create already existing endpoint configuration \"arn:aws:sagemaker:us-east-1:057716757052:endpoint-config/contextual-answers\".", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mClientError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[8], line 7\u001b[0m\n\u001b[1;32m 2\u001b[0m model \u001b[38;5;241m=\u001b[39m ModelPackage(\n\u001b[1;32m 3\u001b[0m role\u001b[38;5;241m=\u001b[39mrole, model_package_arn\u001b[38;5;241m=\u001b[39mmodel_package_arn, sagemaker_session\u001b[38;5;241m=\u001b[39msagemaker_session\n\u001b[1;32m 4\u001b[0m )\n\u001b[1;32m 6\u001b[0m \u001b[38;5;66;03m# Deploy the model\u001b[39;00m\n\u001b[0;32m----> 7\u001b[0m predictor \u001b[38;5;241m=\u001b[39m \u001b[43mmodel\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdeploy\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mreal_time_inference_instance_type\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mendpoint_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mendpoint_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\n\u001b[1;32m 8\u001b[0m \u001b[43m \u001b[49m\u001b[43mmodel_data_download_timeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m3600\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 9\u001b[0m \u001b[43m \u001b[49m\u001b[43mcontainer_startup_health_check_timeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m600\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 10\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/anaconda3/envs/python3/lib/python3.10/site-packages/sagemaker/model.py:1298\u001b[0m, in \u001b[0;36mModel.deploy\u001b[0;34m(self, initial_instance_count, instance_type, serializer, deserializer, accelerator_type, endpoint_name, tags, kms_key, wait, data_capture_config, async_inference_config, serverless_inference_config, volume_size, model_data_download_timeout, container_startup_health_check_timeout, inference_recommendation_id, explainer_config, **kwargs)\u001b[0m\n\u001b[1;32m 1295\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_explainer_enabled:\n\u001b[1;32m 1296\u001b[0m explainer_config_dict \u001b[38;5;241m=\u001b[39m explainer_config\u001b[38;5;241m.\u001b[39m_to_request_dict()\n\u001b[0;32m-> 1298\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msagemaker_session\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mendpoint_from_production_variants\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1299\u001b[0m \u001b[43m \u001b[49m\u001b[43mname\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mendpoint_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1300\u001b[0m \u001b[43m \u001b[49m\u001b[43mproduction_variants\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[43mproduction_variant\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1301\u001b[0m \u001b[43m \u001b[49m\u001b[43mtags\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtags\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1302\u001b[0m \u001b[43m \u001b[49m\u001b[43mkms_key\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mkms_key\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1303\u001b[0m \u001b[43m \u001b[49m\u001b[43mwait\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mwait\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1304\u001b[0m \u001b[43m \u001b[49m\u001b[43mdata_capture_config_dict\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdata_capture_config_dict\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1305\u001b[0m \u001b[43m \u001b[49m\u001b[43mexplainer_config_dict\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mexplainer_config_dict\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1306\u001b[0m \u001b[43m \u001b[49m\u001b[43masync_inference_config_dict\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43masync_inference_config_dict\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1307\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1309\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpredictor_cls:\n\u001b[1;32m 1310\u001b[0m predictor \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpredictor_cls(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mendpoint_name, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msagemaker_session)\n", "File \u001b[0;32m~/anaconda3/envs/python3/lib/python3.10/site-packages/sagemaker/session.py:4537\u001b[0m, in \u001b[0;36mSession.endpoint_from_production_variants\u001b[0;34m(self, name, production_variants, tags, kms_key, wait, data_capture_config_dict, async_inference_config_dict, explainer_config_dict)\u001b[0m\n\u001b[1;32m 4534\u001b[0m config_options[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mExplainerConfig\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m explainer_config_dict\n\u001b[1;32m 4536\u001b[0m LOGGER\u001b[38;5;241m.\u001b[39minfo(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCreating endpoint-config with name \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, name)\n\u001b[0;32m-> 4537\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msagemaker_client\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcreate_endpoint_config\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mconfig_options\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 4539\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcreate_endpoint(endpoint_name\u001b[38;5;241m=\u001b[39mname, config_name\u001b[38;5;241m=\u001b[39mname, tags\u001b[38;5;241m=\u001b[39mtags, wait\u001b[38;5;241m=\u001b[39mwait)\n", "File \u001b[0;32m~/anaconda3/envs/python3/lib/python3.10/site-packages/botocore/client.py:530\u001b[0m, in \u001b[0;36mClientCreator._create_api_method.._api_call\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 526\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\n\u001b[1;32m 527\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpy_operation_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m() only accepts keyword arguments.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 528\u001b[0m )\n\u001b[1;32m 529\u001b[0m \u001b[38;5;66;03m# The \"self\" in this scope is referring to the BaseClient.\u001b[39;00m\n\u001b[0;32m--> 530\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_make_api_call\u001b[49m\u001b[43m(\u001b[49m\u001b[43moperation_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/anaconda3/envs/python3/lib/python3.10/site-packages/botocore/client.py:960\u001b[0m, in \u001b[0;36mBaseClient._make_api_call\u001b[0;34m(self, operation_name, api_params)\u001b[0m\n\u001b[1;32m 958\u001b[0m error_code \u001b[38;5;241m=\u001b[39m parsed_response\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mError\u001b[39m\u001b[38;5;124m\"\u001b[39m, {})\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCode\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 959\u001b[0m error_class \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mexceptions\u001b[38;5;241m.\u001b[39mfrom_code(error_code)\n\u001b[0;32m--> 960\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m error_class(parsed_response, operation_name)\n\u001b[1;32m 961\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 962\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m parsed_response\n", "\u001b[0;31mClientError\u001b[0m: An error occurred (ValidationException) when calling the CreateEndpointConfig operation: Cannot create already existing endpoint configuration \"arn:aws:sagemaker:us-east-1:057716757052:endpoint-config/contextual-answers\"." ] } ], "source": [ "# create a deployable model from the model package.\n", "model = ModelPackage(\n", " role=role, model_package_arn=model_package_arn, sagemaker_session=sagemaker_session\n", ")\n", "\n", "# Deploy the model\n", "predictor = model.deploy(1, real_time_inference_instance_type, endpoint_name=endpoint_name, \n", " model_data_download_timeout=3600,\n", " container_startup_health_check_timeout=600,\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Once endpoint has been created, you would be able to perform real-time inference." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### B. Interact with the model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**AI21 Studio Contextual Answers model** allows you to access our high-quality question answering technology. It was designed to answer questions based on a specific document context provided by the customer. This avoids any factual issues that language models may have and makes sure the answers it provides are grounded in that context document.\n", "\n", "This model receives document text, serving as a context, and a question and returns an answer based entirely on this context. This means that if the answer to your question is not in the document, the model will indicate it (instead of providing a false answer)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To get a sense of the model's behavior, let's use this toy example of asking what is the Eiffel tower height. Most language models will simply answer according to their training data.\n", "\n", "This model, however, bases its answer solely on the context you provide. Let's use the following [Wikipedia paragraph](https://en.wikipedia.org/wiki/Eiffel_Tower#:~:text=The%20Eiffel%20Tower%20(%2F%CB%88a%C9%AA,from%20the%20Champ%20de%20Mars) as context, with small modifications:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "# Actual paragraph\n", "context = \"The tower is 330 metres (1,083 ft) tall,[6] about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest human-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure in the world to surpass both the 200-metre and 300-metre mark in height. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.\"\n", "\n", "# The paragraph with manual changes of the height\n", "false_context = \"The tower is 3 metres (10 ft) tall,[6] about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest human-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure in the world to surpass both the 200-metre and 300-metre mark in height. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.\"\n", "\n", "# The paragraph with the height omitted\n", "partial_context = \"Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest human-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure in the world to surpass both the 200-metre and 300-metre mark in height. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is what the model will say when asked the same question in each context." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "# True context\n", "response = ai21.Answer.execute(\n", " context=context,\n", " question=\"What is the height of the Eiffel tower?\",\n", " sm_endpoint=endpoint_name\n", ")\n", "\n", "print(response.answer)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "# False context\n", "response = ai21.Answer.execute(\n", " context=false_context,\n", " question=\"What is the height of the Eiffel tower?\",\n", " sm_endpoint=endpoint_name\n", ")\n", "\n", "print(response.answer)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "# Irrelevant context\n", "response = ai21.Answer.execute(\n", " context=partial_context,\n", " question=\"What is the height of the Eiffel tower?\",\n", " sm_endpoint=endpoint_name\n", ")\n", "\n", "print(response.answer)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### C. Ask about financial reports" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The document context should be **no more than 10,000 characters**, and the question can be up to 160 characters." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Imagine you are performing research and rely on financial reports to base your findings. Let's take the following part from [JPMorgan Chase & Co. 2021 annual report](https://www.jpmorganchase.com/content/dam/jpmc/jpmorgan-chase-and-co/investor-relations/documents/annualreport-2021.pdf):" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "financial_context = \"\"\"In 2020 and 2021, enormous QE — approximately $4.4 trillion, or 18%, of 2021 gross domestic product (GDP) — and enormous fiscal stimulus (which has been and always will be inflationary) — approximately $5 trillion, or 21%, of 2021 GDP — stabilized markets and allowed companies to raise enormous amounts of capital. In addition, this infusion of capital saved many small businesses and put more than $2.5 trillion in the hands of consumers and almost $1 trillion into state and local coffers. These actions led to a rapid decline in unemployment, dropping from 15% to under 4% in 20 months — the magnitude and speed of which were both unprecedented. Additionally, the economy grew 7% in 2021 despite the arrival of the Delta and Omicron variants and the global supply chain shortages, which were largely fueled by the dramatic upswing in consumer spending and the shift in that spend from services to goods. Fortunately, during these two years, vaccines for COVID-19 were also rapidly developed and distributed.\n", "In today's economy, the consumer is in excellent financial shape (on average), with leverage among the lowest on record, excellent mortgage underwriting (even though we've had home price appreciation), plentiful jobs with wage increases and more than $2 trillion in excess savings, mostly due to government stimulus. Most consumers and companies (and states) are still flush with the money generated in 2020 and 2021, with consumer spending over the last several months 12% above pre-COVID-19 levels. (But we must recognize that the account balances in lower-income households, smaller to begin with, are going down faster and that income for those households is not keeping pace with rising inflation.)\n", "Today's economic landscape is completely different from the 2008 financial crisis when the consumer was extraordinarily overleveraged, as was the financial system as a whole — from banks and investment banks to shadow banks, hedge funds, private equity, Fannie Mae and many other entities. In addition, home price appreciation, fed by bad underwriting and leverage in the mortgage system, led to excessive speculation, which was missed by virtually everyone — eventually leading to nearly $1 trillion in actual losses.\n", "\"\"\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Rather than reading the entire report, just ask what you want to know:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "question = \"Did the economy shrink after the Omicron variant arrived?\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The model will answer based on the provided report:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "tags": [] }, "outputs": [ { "ename": "NameError", "evalue": "name 'financial_context' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[9], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m response \u001b[38;5;241m=\u001b[39m ai21\u001b[38;5;241m.\u001b[39mAnswer\u001b[38;5;241m.\u001b[39mexecute(\n\u001b[0;32m----> 2\u001b[0m context\u001b[38;5;241m=\u001b[39m\u001b[43mfinancial_context\u001b[49m,\n\u001b[1;32m 3\u001b[0m question\u001b[38;5;241m=\u001b[39mquestion,\n\u001b[1;32m 4\u001b[0m sm_endpoint\u001b[38;5;241m=\u001b[39mendpoint_name\n\u001b[1;32m 5\u001b[0m )\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28mprint\u001b[39m(response\u001b[38;5;241m.\u001b[39manswer)\n", "\u001b[0;31mNameError\u001b[0m: name 'financial_context' is not defined" ] } ], "source": [ "response = ai21.Answer.execute(\n", " context=financial_context,\n", " question=question,\n", " sm_endpoint=endpoint_name\n", ")\n", "\n", "print(response.answer)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In addition, you can ask more complex questions, where the answer requires deductions rather than just extracting the correct sentence from the document context. This will result in abstractive, rather than extractive, answers that draw on several different parts of the document. For example, look at the following question:" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The COVID-19 pandemic had a significant short-term impact on the economy, as it led to shutdowns and layoffs across the country. However, it also had a long-term positive impact by accelerating digital transformation and encouraging innovation.\n" ] } ], "source": [ "harder_question = \"Did COVID-19 eventually help the economy?\"\n", "\n", "response = ai21.Answer.execute(\n", " context=financial_context,\n", " question=harder_question,\n", " sm_endpoint=endpoint_name\n", ")\n", "\n", "print(response.answer)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We now present the model with the following question. You may be confused to answer something based on the last paragraph without delving into the text. However, if you read the provided document context properly, you will discover that the answer does not appear there. The model handles this as expected:" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Answer not in document\n" ] } ], "source": [ "irrelevant_question = \"How did COVID-19 affect the financial crisis of 2008?\"\n", "\n", "response = ai21.Answer.execute(\n", " context=financial_context,\n", " question=irrelevant_question,\n", " sm_endpoint=endpoint_name\n", ")\n", "\n", "print(response.answer)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### D. Translate" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "tags": [] }, "outputs": [], "source": [ "import boto3" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "tags": [] }, "outputs": [], "source": [ "translate = boto3.client(\"translate\")" ] }, { "cell_type": "code", "execution_count": 94, "metadata": { "tags": [] }, "outputs": [], "source": [ "def trans(text, target=\"ko\"):\n", " response = translate.translate_text(\n", " Text=text,\n", " SourceLanguageCode=\"Auto\",\n", " TargetLanguageCode=target\n", " )\n", " \n", " text_translate = response[\"TranslatedText\"]\n", " #print (text_translate)\n", " return text_translate" ] }, { "cell_type": "code", "execution_count": 55, "metadata": { "tags": [] }, "outputs": [], "source": [ "financial_context_ko = \"\"\"2020년과 2021년에는 약 4조 4천억 달러, 즉 2021년 국내 총생산 (GDP) 의 18% 에 달하는 막대한 QE와 2021년 GDP의 약 5조 달러, 즉 21% 에 달하는 막대한 재정 부양책 (지금까지도 인플레이션일 것입니다) 이 시장을 안정시켰고 기업들은 막대한 자본을 조달할 수 있었습니다.또한 이러한 자본 투입을 통해 많은 중소기업을 구했고 소비자에게는 2조 5천억 달러 이상을, 주 및 지방 금고에 거의 1조 달러를 투자했습니다.이러한 조치로 인해 실업률이 20개월 만에 15% 에서 4% 미만으로 급격히 감소했습니다. 그 규모와 속도는 전례 없는 일이었습니다.또한 델타와 오미크론 변종의 출현과 글로벌 공급망 부족에도 불구하고 2021년 경제는 7% 성장했습니다. 이는 주로 소비자 지출의 급격한 증가와 해당 지출의 서비스에서 상품으로의 전환에 힘입은 것입니다.다행히 이 2년 동안 COVID-19 백신도 빠르게 개발되어 배포되었습니다.\n", "오늘날 경제에서 소비자들은 (평균적으로) 우수한 재무 상태를 유지하고 있으며, 레버리지는 사상 최저 수준이며, 주택 가격 상승이 있었음에도 불구하고 우수한 모기지 인수, 임금 인상으로 인한 많은 일자리 및 2조 달러 이상의 초과 저축을 이루고 있습니다. 이는 주로 정부 경기 부양책으로 인한 것입니다.대부분의 소비자와 기업 (및 주) 은 2020년과 2021년에 창출된 자금으로 여전히 넘쳐나고 있으며, 지난 몇 개월 동안의 소비자 지출은 COVID-19 이전 수준보다 12% 높습니다.(그러나 우리는 저소득 가구의 계좌 잔고가 처음에는 규모가 작을수록 더 빠르게 감소하고 있으며 해당 가구의 소득이 인플레이션 상승에 보조를 맞추지 못하고 있다는 점을 인식해야 합니다.)\n", "오늘날의 경제 상황은 2008년 금융 위기와 완전히 달라졌습니다. 은행과 투자 은행에서부터 섀도우 뱅크, 헤지 펀드, 사모펀드, 패니 매 (Fannie Mae) 및 기타 여러 기업에 이르기까지 금융 시스템 전체가 그랬듯이 소비자가 과도하게 레버리지를 받았을 때였습니다.또한 주택 담보 대출 제도의 부실 인수 및 레버리지로 인한 주택 가격 상승은 과도한 투기로 이어져 거의 모든 사람이 이를 놓쳤고 결국 거의 1조 달러에 가까운 실제 손실을 초래했습니다.\"\"\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2020년과 2021년에는 약 4조 4천억 달러, 즉 2021년 국내 총생산 (GDP) 의 18% 에 달하는 막대한 QE와 2021년 GDP의 약 5조 달러, 즉 21% 에 달하는 막대한 재정 부양책 (지금까지도 인플레이션일 것입니다) 이 시장을 안정시켰고 기업들은 막대한 자본을 조달할 수 있었습니다.
\n", "또한 이러한 자본 투입을 통해 많은 중소기업을 구했고 소비자에게는 2조 5천억 달러 이상을, 주 및 지방 금고에 거의 1조 달러를 투자했습니다.
\n", "이러한 조치로 인해 실업률이 20개월 만에 15% 에서 4% 미만으로 급격히 감소했습니다. 그 규모와 속도는 전례 없는 일이었습니다.
\n", "**또한 델타와 오미크론 변종의 출현과 글로벌 공급망 부족에도 불구하고 2021년 경제는 7% 성장했습니다.**
\n", "이는 주로 소비자 지출의 급격한 증가와 해당 지출의 서비스에서 상품으로의 전환에 힘입은 것입니다.
\n", "다행히 이 2년 동안 COVID-19 백신도 빠르게 개발되어 배포되었습니다.
\n", "오늘날 경제에서 소비자들은 (평균적으로) 우수한 재무 상태를 유지하고 있으며, 레버리지는 사상 최저 수준이며, 주택 가격 상승이 있었음에도 불구하고 우수한 모기지 인수, 임금 인상으로 인한 많은 일자리 및 2조 달러 이상의 초과 저축을 이루고 있습니다.
\n", "이는 주로 정부 경기 부양책으로 인한 것입니다.
\n", "대부분의 소비자와 기업 (및 주) 은 2020년과 2021년에 창출된 자금으로 여전히 넘쳐나고 있으며, 지난 몇 개월 동안의 소비자 지출은 COVID-19 이전 수준보다 12% 높습니다.\n", "(그러나 우리는 저소득 가구의 계좌 잔고가 처음에는 규모가 작을수록 더 빠르게 감소하고 있으며 해당 가구의 소득이 인플레이션 상승에 보조를 맞추지 못하고 있다는 점을 인식해야 합니다.)
\n", "오늘날의 경제 상황은 2008년 금융 위기와 완전히 달라졌습니다.
\n", "은행과 투자 은행에서부터 섀도우 뱅크, 헤지 펀드, 사모펀드, 패니 매 (Fannie Mae) 및 기타 여러 기업에 이르기까지 금융 시스템 전체가 그랬듯이 소비자가 과도하게 레버리지를 받았을 때였습니다.
\n", "또한 주택 담보 대출 제도의 부실 인수 및 레버리지로 인한 주택 가격 상승은 과도한 투기로 이어져 거의 모든 사람이 이를 놓쳤고 결국 거의 1조 달러에 가까운 실제 손실을 초래했습니다.
" ] }, { "cell_type": "code", "execution_count": 56, "metadata": { "tags": [] }, "outputs": [], "source": [ "question = \"오미크론 변종이 등장한 후 경제가 위축되었나요?\"" ] }, { "cell_type": "code", "execution_count": 57, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "아니요, 델타와 오미크론 변종의 출현과 글로벌 공급망 부족에도 불구하고 2021년 경제는 7% 성장했습니다.\n" ] } ], "source": [ "response = ai21.Answer.execute(\n", " context=trans(financial_context_ko, target=\"en\"),\n", " question=trans(question, target=\"en\"),\n", " sm_endpoint=endpoint_name\n", ")\n", "response_ko = trans(response.answer)\n", "print(response_ko)" ] }, { "cell_type": "code", "execution_count": 95, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "COVID-19 백신도 이 2년 동안 빠르게 개발 및 보급되었으며, 델타와 오미크론 변종의 출현과 글로벌 공급망 부족에도 불구하고 2021년 경제는 7% 성장했습니다.\n" ] } ], "source": [ "harder_question = \"COVID-19가 결국 경제에 도움이 되었나요?\"\n", "\n", "response = ai21.Answer.execute(\n", " context=trans(financial_context_ko, target=\"en\"),\n", " question=trans(harder_question, target=\"en\"),\n", " sm_endpoint=endpoint_name,\n", " temperature=1.1\n", ")\n", "response_ko = trans(response.answer)\n", "print(response_ko)" ] }, { "cell_type": "code", "execution_count": 91, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "In 2020 and 2021, huge QE of about 4.4 trillion dollars, or 18% of gross domestic product (GDP) in 2021, and huge fiscal stimulus measures of about 5 trillion dollars, or 21% of GDP in 2021 (inflation will still be inflation until now) stabilized the market, and companies were able to raise huge amounts of capital. Furthermore, these capital inputs saved many small and medium-sized enterprises, and invested more than 2.5 trillion dollars in consumers and almost 1 trillion dollars in state and local vaults. The unemployment rate was 20 due to these measures. It declined sharply from 15% to less than 4% in just a month. The scale and pace were unprecedented. Furthermore, the economy grew 7% in 2021 despite the advent of the Delta and Omicron variants and global supply chain shortages. This was mainly driven by a sharp increase in consumer spending and a shift in that spending from services to goods. Fortunately, COVID-19 vaccines were also rapidly developed and distributed during these two years.\n", "In today's economy, consumers are in excellent financial standing (on average), leverage is at an all-time low, and despite rising home prices, excellent mortgage acquisitions, lots of jobs due to wage increases, and more than $2 trillion in excess savings. This is mainly due to government stimulus measures. Most consumers and businesses (and stocks) are still flooded with funds generated in 2020 and 2021, and consumer spending over the past few months is 12% higher than pre-COVID-19 levels. (However, we need to recognize that the account balances of low-income households are declining more rapidly as they are initially smaller, and the income of those households is not keeping pace with rising inflation.)\n", "Today's economic situation is completely different from the 2008 financial crisis. It was a time when consumers were excessively leveraged, as did the entire financial system, from banks and investment banks to shadow banks, hedge funds, private equity, Fannie Mae (Fannie Mae), and many other companies. Also, the rise in housing prices caused by insolvent acquisitions and leverage in mortgage loan schemes led to excessive speculation, which led to excessive speculation, which ended up causing real losses close to 1 trillion dollars.\n", "How did COVID-19 affect the financial crisis of 2008?\n", "답변이 문서에 없음\n", "답변이 문서에 없음\n" ] } ], "source": [ "irrelevant_question = \"How did COVID-19 affect the financial crisis of 2008?\"\n", "\n", "response = ai21.Answer.execute(\n", " context=trans(financial_context_ko, target=\"en\"),\n", " question=trans(irrelevant_question, target=\"en\"),\n", " sm_endpoint=endpoint_name,\n", " temperature=0.7\n", ")\n", "\n", "response_ko = trans(response.answer)\n", "print(response_ko)" ] }, { "cell_type": "code", "execution_count": 68, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "\u001b[0;31mSignature:\u001b[0m \u001b[0mai21\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAnswer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mDocstring:\u001b[0m \n", "\u001b[0;31mFile:\u001b[0m ~/anaconda3/envs/python3/lib/python3.10/site-packages/ai21/modules/resources/nlp_task.py\n", "\u001b[0;31mType:\u001b[0m method" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "ai21.Answer.execute?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Interested in learning more?\n", "Take a look at our [guide](https://docs.ai21.com/docs/contextual-answers-api) to understand all the capabilities of AI21 Contextual Answers model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Clean-up" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### A. Delete the endpoint" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now that you have successfully performed a real-time inference, you do not need the endpoint any more. You can terminate the endpoint to avoid being charged." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model.sagemaker_session.delete_endpoint(endpoint_name)\n", "model.sagemaker_session.delete_endpoint_config(endpoint_name)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### B. Delete the model" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "model.delete_model()" ] } ], "metadata": { "availableInstances": [ { "_defaultOrder": 0, "_isFastLaunch": true, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 4, "name": "ml.t3.medium", "vcpuNum": 2 }, { "_defaultOrder": 1, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 8, "name": "ml.t3.large", "vcpuNum": 2 }, { "_defaultOrder": 2, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.t3.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 3, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.t3.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 4, "_isFastLaunch": true, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 8, "name": "ml.m5.large", "vcpuNum": 2 }, { "_defaultOrder": 5, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.m5.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 6, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.m5.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 7, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.m5.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 8, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.m5.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 9, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.m5.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 10, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.m5.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 11, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 384, "name": "ml.m5.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 12, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 8, "name": "ml.m5d.large", "vcpuNum": 2 }, { "_defaultOrder": 13, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.m5d.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 14, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.m5d.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 15, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.m5d.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 16, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.m5d.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 17, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.m5d.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 18, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.m5d.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 19, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 384, "name": "ml.m5d.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 20, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": true, "memoryGiB": 0, "name": "ml.geospatial.interactive", "supportedImageNames": [ "sagemaker-geospatial-v1-0" ], "vcpuNum": 0 }, { "_defaultOrder": 21, "_isFastLaunch": true, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 4, "name": "ml.c5.large", "vcpuNum": 2 }, { "_defaultOrder": 22, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 8, "name": "ml.c5.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 23, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.c5.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 24, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.c5.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 25, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 72, "name": "ml.c5.9xlarge", "vcpuNum": 36 }, { "_defaultOrder": 26, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 96, "name": "ml.c5.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 27, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 144, "name": "ml.c5.18xlarge", "vcpuNum": 72 }, { "_defaultOrder": 28, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.c5.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 29, "_isFastLaunch": true, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.g4dn.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 30, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.g4dn.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 31, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.g4dn.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 32, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.g4dn.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 33, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 4, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.g4dn.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 34, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.g4dn.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 35, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 61, "name": "ml.p3.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 36, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 4, "hideHardwareSpecs": false, "memoryGiB": 244, "name": "ml.p3.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 37, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 8, "hideHardwareSpecs": false, "memoryGiB": 488, "name": "ml.p3.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 38, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 8, "hideHardwareSpecs": false, "memoryGiB": 768, "name": "ml.p3dn.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 39, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.r5.large", "vcpuNum": 2 }, { "_defaultOrder": 40, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.r5.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 41, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.r5.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 42, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.r5.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 43, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.r5.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 44, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 384, "name": "ml.r5.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 45, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 512, "name": "ml.r5.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 46, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 768, "name": "ml.r5.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 47, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.g5.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 48, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.g5.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 49, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.g5.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 50, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.g5.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 51, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.g5.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 52, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 4, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.g5.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 53, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 4, "hideHardwareSpecs": false, "memoryGiB": 384, "name": "ml.g5.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 54, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 8, "hideHardwareSpecs": false, "memoryGiB": 768, "name": "ml.g5.48xlarge", "vcpuNum": 192 }, { "_defaultOrder": 55, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 8, "hideHardwareSpecs": false, "memoryGiB": 1152, "name": "ml.p4d.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 56, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 8, "hideHardwareSpecs": false, "memoryGiB": 1152, "name": "ml.p4de.24xlarge", "vcpuNum": 96 } ], "instance_type": "ml.t3.medium", "kernelspec": { "display_name": "conda_python3", "language": "python", "name": "conda_python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.8" } }, "nbformat": 4, "nbformat_minor": 4 }