Skip to content

Commit b2a51ac

Browse files
authored
Merge pull request aws#43 from awslabs/arpin_advanced_functionality
Updated: advanced_functionality notebooks Pushing to prepare for Monday's meeting.
2 parents b599537 + eebf646 commit b2a51ac

File tree

12 files changed

+399
-846
lines changed

12 files changed

+399
-846
lines changed

advanced_functionality/data_distribution_types/AmazonAIAlgorithmsIO_pb2.py

-101
This file was deleted.

advanced_functionality/data_distribution_types/convert_data.py

-90
This file was deleted.

advanced_functionality/data_distribution_types/data_distribution_types.ipynb

+31-13
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"---\n",
3232
"# Setup\n",
3333
"\n",
34-
"_This notebook was created and tested on an ml.m4xlarge notebook instance._\n",
34+
"_This notebook was created and tested on an ml.m4.xlarge notebook instance._\n",
3535
"\n",
3636
"Let's start by specifying:\n",
3737
"\n",
@@ -78,11 +78,12 @@
7878
"import matplotlib.pyplot as plt\n",
7979
"from IPython.display import display\n",
8080
"import io\n",
81-
"import convert_data\n",
8281
"import time\n",
8382
"import copy\n",
8483
"import json\n",
85-
"import sys"
84+
"import sys\n",
85+
"import sagemaker.amazon.common as smac\n",
86+
"import os"
8687
]
8788
},
8889
{
@@ -160,7 +161,7 @@
160161
"metadata": {},
161162
"source": [
162163
"We can see:\n",
163-
"- `EventCode` is pretty unevently distributed, with some events making up 7%+ of the observations and others being a thousandth of a percent.\n",
164+
"- `EventCode` is pretty unevenly distributed, with some events making up 7%+ of the observations and others being a thousandth of a percent.\n",
164165
"- `AvgTone` seems to be reasonably smoothly distributed, while `NumArticles` has a long tail, and `Actor` geo features have suspiciously large spikes near 0.\n",
165166
"\n",
166167
"Let's remove the (0, 0) lat-longs, one hot encode `EventCode`, and prepare our data for a machine learning model. For this example we'll keep things straightforward and try to predict `AvgTone`, using the other variables in our dataset as features.\n",
@@ -193,12 +194,10 @@
193194
"outputs": [],
194195
"source": [
195196
"def write_to_s3(bucket, prefix, channel, file_prefix, X, y):\n",
196-
" f = io.BytesIO()\n",
197-
" feature_size = X.shape[1]\n",
198-
" for features, target in zip(X, y):\n",
199-
" convert_data.write_recordio(f, convert_data.list_to_record_bytes(features, label=target, feature_size=feature_size))\n",
200-
" f.seek(0)\n",
201-
" boto3.Session().resource('s3').Bucket(bucket).Object(os.path.join(prefix, channel, file_prefix + '.data')).upload_fileobj(f)\n",
197+
" buf = io.BytesIO()\n",
198+
" smac.write_numpy_to_dense_tensor(buf, X.astype('float32'), y.astype('float32'))\n",
199+
" buf.seek(0)\n",
200+
" boto3.Session().resource('s3').Bucket(bucket).Object(os.path.join(prefix, channel, file_prefix + '.data')).upload_fileobj(buf)\n",
202201
"\n",
203202
"def transform_gdelt(df, events=None):\n",
204203
" df = df[['AvgTone', 'EventCode', 'NumArticles', 'Actor1Geo_Lat', 'Actor1Geo_Long', 'Actor2Geo_Lat', 'Actor2Geo_Long']]\n",
@@ -649,7 +648,7 @@
649648
"cell_type": "markdown",
650649
"metadata": {},
651650
"source": [
652-
"Next, because POST requests to our endpoint are limited to ~6MB, we'll setup a small function to split our test data up into mini-batches, loop through and invoke our endpoint to get predictions, and gather them into a single array."
651+
"Next, because POST requests to our endpoint are limited to ~6MB, we'll setup a small function to split our test data up into mini-batches that are each about 5MB, loop through and invoke our endpoint to get predictions for those mini-batches, and gather them into a single array."
653652
]
654653
},
655654
{
@@ -714,10 +713,28 @@
714713
"\n",
715714
"Different algorithms can be expected to show variation in which distribution mechanism is most effective at achieving optimal compute spend per point of model accuracy. The message remains the same though, that the process of finding the right distribution type is another experiment in optimizing model training times."
716715
]
716+
},
717+
{
718+
"cell_type": "markdown",
719+
"metadata": {},
720+
"source": [
721+
"### (Optional) Clean-up\n",
722+
"\n",
723+
"If you're ready to be done with this notebook, please uncomment and run the cell below. This will remove the hosted endpoints you created and avoid any charges from a stray instance being left on."
724+
]
725+
},
726+
{
727+
"cell_type": "code",
728+
"execution_count": null,
729+
"metadata": {},
730+
"outputs": [],
731+
"source": [
732+
"#sm.delete_endpoint(EndpointName=sharded_endpoint)\n",
733+
"#sm.delete_endpoint(EndpointName=replicated_endpoint)"
734+
]
717735
}
718736
],
719737
"metadata": {
720-
"notice": "Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.",
721738
"kernelspec": {
722739
"display_name": "Environment (conda_python3)",
723740
"language": "python",
@@ -734,7 +751,8 @@
734751
"nbconvert_exporter": "python",
735752
"pygments_lexer": "ipython3",
736753
"version": "3.6.3"
737-
}
754+
},
755+
"notice": "Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License."
738756
},
739757
"nbformat": 4,
740758
"nbformat_minor": 2

0 commit comments

Comments
 (0)