Skip to main content

Blog

Learn About Our Meetup

5000+ Members

MEETUPS

LEARN, CONNECT, SHARE

Join our meetup, learn, connect, share, and get to know your Toronto AI community. 

JOB POSTINGS

INDEED POSTINGS

Browse through the latest deep learning, ai, machine learning postings from Indeed for the GTA.

CONTACT

CONNECT WITH US

Are you looking to sponsor space, be a speaker, or volunteer, feel free to give us a shout.

Author: torontoai

[D] Threshold for rejecting word embedding similarities

I have a problem where I have certain set of target words and I need to use them to match with other words that are found in new csvs. I was wondering if there are any good approaches to determining the threshold for rejecting word similarities. I was thinking using a random sample of 10k words and plot their similarities (10k*9.99k/2) but I am not sure whether this is the right approach. Or should I use the distribution of the similarities of the target words on a vocabulary and choose a percentile cutoff? Any ideas?

submitted by /u/radcapbill
[link] [comments]

Associating prediction results with input data using Amazon SageMaker Batch Transform

When you run predictions on large datasets, you may want to drop some input attributes before running the predictions. This is because those attributes don’t carry any signal or were not part of the dataset used to train your machine learning (ML) model. Similarly, it can be helpful to map the prediction results to all or part of the input data for analysis after the job is complete.

For example, consider a dataset that comes with an ID attribute. Commonly, an observation ID is a randomly generated or sequential number that carries no signal for a given ML problem. For this reason, it is usually not part of the training data attributes. However, when you make batch predictions, you may want your output to contain both the observation ID and the prediction result as a single record.

The Batch Transform feature in Amazon SageMaker enables you to run predictions on datasets stored in Amazon S3. Previously, you had to filter your input data before creating your batch transform job and join prediction results with desired input fields after the job was complete. Now, you can use Amazon SageMaker Batch Transform to exclude attributes before running predictions. You can also join the prediction results with partial or entire input data attributes when using data that is in CSV, text, or JSON format. This eliminates the need for any additional pre-processing or post-processing and accelerates the overall ML process.

This post demonstrates how you can use this new capability to filter input data for a batch transform job in Amazon SageMaker and join the prediction results with attributes from the input dataset.

Background

Amazon SageMaker is a fully managed service that covers the entire ML workflow. The service labels and prepares your data, chooses an algorithm, trains the model, tunes and optimizes it for deployment, makes predictions, and takes action.

Amazon SageMaker manages the provisioning of resources at the start of batch transform jobs. It releases the resources when the jobs are complete, so you pay only for what was used during the execution of your job. When the job is complete, Amazon SageMaker saves the prediction results in an S3 bucket that you specify.

Batch transform example

Use the public data set for breast cancer detection from UCI and train a binary classification model to detect whether a given tumor is likely to be malignant (1) or benign (0). This dataset comes with an ID attribute for each tumor, which you exclude during training and prediction. However, you bring it back in your final output and record it with the predicted probability of malignancy for each tumor from the batch transform job.

You can also download the companion Jupyter notebook. Each of the following sections in the post corresponds to a notebook section so that you can run the code for each step as you read along.

Setup

First, import common Python libraries for ML such as pandas and NumPy, along with the Amazon SageMaker and Boto3 libraries that you later use to run the training and batch transform jobs.

Also, set up your S3 bucket for uploading your training data, validation data, and the dataset against which you run the batch transform job. Amazon SageMaker stores the model artifact in this bucket, as well as the output of the batch transform job. Use a folder structure to keep the input datasets separate from the model artifacts and job outputs.

import os
import boto3
import sagemaker
import pandas as pd
import numpy as np

role = sagemaker.get_execution_role()
sess = sagemaker.Session()

bucket=sess.default_bucket()
prefix = 'sagemaker/breast-cancer-prediction-xgboost' # place to upload training files within the bucket

Data preparation

Download the public data set onto the notebook instance and look at a sample for preliminary analysis. Although the dataset for this example is small (with 569 observations and 32 columns), you can use the Amazon SageMaker Batch Transform feature on large datasets with petabytes of data.

data = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/wdbc.data', header = None)

# specify columns extracted from wbdc.names
data.columns = ["id","diagnosis","radius_mean","texture_mean","perimeter_mean","area_mean","smoothness_mean",
                "compactness_mean","concavity_mean","concave points_mean","symmetry_mean","fractal_dimension_mean",
                "radius_se","texture_se","perimeter_se","area_se","smoothness_se","compactness_se","concavity_se",
                "concave points_se","symmetry_se","fractal_dimension_se","radius_worst","texture_worst",
                "perimeter_worst","area_worst","smoothness_worst","compactness_worst","concavity_worst",
                "concave points_worst","symmetry_worst","fractal_dimension_worst"] 

In the following table, the first column in your dataset is the ID of the tumors and the second is the diagnosis (M for malignant or B for benign). In the context of supervised learning, this is your target, or what you want to be able to predict. The following attributes are the features also known as predictors.

id diagnosis radius_mean texture_mean perimeter_mean concave points_worst symmetry_worst fractal_dimension_worst
288 8913049 B 11.26 19.96 73.72 0.09314 0.2955 0.07009
375 901303 B 16.17 16.07 106.3 0.1251 0.3153 0.0896
467 9113514 B 9.668 18.1 61.06 0.025 0.3057 0.07875
203 87880 M 13.81 23.75 91.56 0.2013 0.4432 0.1086
148 86973702 B 14.44 15.18 93.97 0.1599 0.2691 0.07683
118 864877 M 15.78 22.91 105.7 0.2034 0.3274 0.1252
224 8813129 B 13.27 17.02 84.55 0.09678 0.2506 0.07623
364 9010877 B 13.4 16.95 85.48 0.06987 0.2741 0.07582

After doing some minimal data preparation, split the data into three sets:

  • A training set consisting of 80% of your original data.
  • A validation set for your algorithm to perform the proper evaluation of the model.
  • A batch set that you set aside for now and use later to run a batch transform job using the new I/O join feature.

To train and validate the model, keep all the features, such as radius_mean, texture_mean, perimeter_mean, and so on. Drop the id attribute, because it has no relevance in determining whether a tumor is malignant.

When you have a trained model in production, you typically want to run predictions against it. One way to do that is to deploy the model for real-time predictions using the Amazon SageMaker hosting services.

However, in your case, you do not need real-time predictions. Instead, you have a backlog of tumors as a .csv file in Amazon S3, which consists of a list of tumors identified by their ID. Use a batch transform job to predict, for each tumor, the probability of being malignant. To create this backlog of tumors here, make a batch set with the id attribute but without the diagnosis attribute. That’s what you’re trying to predict with your batch transform job.

The following code example shows the configuration of data between the three datasets:

# replace the M/B diagnosis with a 1/0 boolean value
data['diagnosis']=data['diagnosis'].apply(lambda x: ((x =="M"))+0) 

# data split in three sets, training, validation and batch inference
rand_split = np.random.rand(len(data))
train_list = rand_split < 0.8
val_list = (rand_split >= 0.8) & (rand_split < 0.9)
batch_list = rand_split >= 0.9

data_train = data[train_list].drop(['id'],axis=1)
data_val = data[val_list].drop(['id'],axis=1)
data_batch = data[batch_list].drop(['diagnosis'],axis=1)

data_train = data[train_list].drop(['id'],axis=1)
data_val = data[val_list].drop(['id'],axis=1)
data_batch = data[batch_list].drop(['diagnosis'],axis=1)

Finally, upload these three datasets to S3.

train_file = 'train_data.csv'
data_train.to_csv(train_file,index=False,header=False)
sess.upload_data(train_file, key_prefix='{}/train'.format(prefix))

validation_file = 'validation_data.csv'
data_val.to_csv(validation_file,index=False,header=False)
sess.upload_data(validation_file, key_prefix='{}/validation'.format(prefix))

batch_file = 'batch_data.csv'
data_batch.to_csv(batch_file,index=False,header=False)
sess.upload_data(batch_file, key_prefix='{}/batch'.format(prefix))  

Training job

Use the Amazon SageMaker XGBoost built-in algorithm to quickly train a model for binary classification based on your training and validation datasets. Set the training objective to binary:logistic, which trains XGBoost to output the probability that an observation belongs to the positive class (malignant in this example), as shown in the following code example:

%%time
from time import gmtime, strftime
from sagemaker.amazon.amazon_estimator import get_image_uri

job_name = 'xgb-' + strftime("%Y-%m-%d-%H-%M-%S", gmtime())
output_location = 's3://{}/{}/output/{}'.format(bucket, prefix, job_name)
image = get_image_uri(boto3.Session().region_name, 'xgboost')

sm_estimator = sagemaker.estimator.Estimator(image,
                                             role,
                                             train_instance_count=1,
                                             train_instance_type='ml.m5.4xlarge',
                                             train_volume_size=50,
                                             input_mode='File',
                                             output_path=output_location,
                                             sagemaker_session=sess)

sm_estimator.set_hyperparameters(objective="binary:logistic",
                                 max_depth=5,
                                 eta=0.2,
                                 gamma=4,
                                 min_child_weight=6,
                                 subsample=0.8,
                                 silent=0,
                                 num_round=100)

train_data = sagemaker.session.s3_input('s3://{}/{}/train'.format(bucket, prefix), distribution='FullyReplicated', 
                                        content_type='text/csv', s3_data_type='S3Prefix')
validation_data = sagemaker.session.s3_input('s3://{}/{}/validation'.format(bucket, prefix), distribution='FullyReplicated', 
                                             content_type='text/csv', s3_data_type='S3Prefix')
data_channels = {'train': train_data, 'validation': validation_data}

# Start training by calling the fit method in the estimator
sm_estimator.fit(inputs=data_channels, logs=True)

Batch transform

Use the Python SDK to kick off the batch transform job to run inferences on your batch dataset and store your inference results in S3.

Your batch dataset contains the id attribute in the first column. As I explained earlier, because this attribute was not used for training, you must use the new input filter capability. Also, before the I/O join feature, the output of the batch transform job would have been a list of probabilities, such as the following:

0.0226082857698

0.987275004387

0.836603999138

0.00795079022646

0.0182465240359

0.995905399323

0.0129367504269

0.961541593075

0.988895177841

It would have required some post-inference logic to map these probabilities to their corresponding input tumor. The Batch Transform filters make this easy.

Specify the input as the join source. Then, specify an output filter to indicate that you do not require the entire input (which is the ID followed by the 30 features). Instead, you want to present the tumor ID and its probability of being malignant. And you only want to show the first (id) and the last (inference result) columns.

The Batch Transform filters use JSONPath expressions to selectively extract the input or output data, based on your needs. For the supported JSONPath operators in Batch Transform, see this link.

JSONPath is developed to work with JSON data. To use it on CSV data, consider a CSV row as a JSON array with a zero-based index. For example, applying ‘$[0,1]’ on a row of ‘8810158, B, 13.110, 22.54, 87.02’ returns the first and second column of the row, which is ‘8810158, B’.

In this example, the input filter is “$[1:]”. You are excluding column 0 (id) before processing the inferences, and keeping everything from column 1 to the last column

(all the features or predictors). The output filter is “$[0,-1].” When presenting the output, you only want to keep column 0 (id) and the last (-1) column (inference_result), which is the probability of a given tumor to be malignant.

You could also consider bringing back input columns other than id. In your current example, where you happen to have the ground truth diagnosis, you could consider bringing it back in your output file next to the prediction. That way, you could do side-by-side comparisons and evaluate your predictions.

%%time

sm_transformer = sm_estimator.transformer(1, 'ml.m4.xlarge', assemble_with = 'Line', accept = 'text/csv')

# start a transform job
input_location = 's3://{}/{}/batch/{}'.format(bucket, prefix, batch_file) # use input data with ID column
sm_transformer.transform(input_location, split_type='Line', content_type='text/csv', input_filter='$[1:]', join_source='Input', output_filter='$[0,-1]')
sm_transformer.wait()

Result

Read the CSV output in S3 at your output location:

import json
import io
from urllib.parse import urlparse

def get_csv_output_from_s3(s3uri, file_name):
    parsed_url = urlparse(s3uri)
    bucket_name = parsed_url.netloc
    prefix = parsed_url.path[1:]
    s3 = boto3.resource('s3')
    obj = s3.Object(bucket_name, '{}/{}'.format(prefix, file_name))
    return obj.get()["Body"].read().decode('utf-8')

output = get_csv_output_from_s3(sm_transformer.output_path, '{}.out'.format(batch_file))
output_df = pd.read_csv(io.StringIO(output), sep=",", header=None)
output_df.sample(10)    

It should show the list of tumors identified by their ID and their corresponding probabilities of being malignant. Your file should look like the following:

844359,0.990931391716 

84458202,0.968179702759 

8510824,0.006071804557 

855138,0.780932843685 

857155,0.0154032697901 

857343,0.0171982143074 

861598,0.540158748627 

86208,0.992102086544 

862261,0.00940885581076 

862989,0.00758415739983 

864292,0.006071804557 

864685,0.0332484431565 

....

Conclusion

This post demonstrated how you can provide input and output filters for your batch transform jobs using the Amazon SageMaker Batch Transform feature. This eliminates the need to pre-process or post-process input and output data respectively. In addition, you can associate prediction results with their corresponding input data with the flexibility of keep all or part of the input data attributes. To learn more about this feature, see the Amazon SageMaker Developer Guide.


About the Authors

Ro Mullier is a Sr. Solutions Architect at AWS helping customers run a variety of applications on AWS and machine learning workloads in particular. In his spare time, he enjoy spending time with family and friends, playing soccer and competing in machine learning competitions.

 

 

 

Han Wang is a Software Development Engineer at AWS AI. She focuses on developing highly scalable and distributed machine learning platforms. In her spare time, she enjoys watching movies, hiking and playing “Zelda: Breath of the wild”.

 

 

 

 

Support for Apache MXNet 1.4 and Model Server in Amazon SageMaker

Apache MXNet is an open-source deep learning software framework used to train and deploy deep neural networks. Data scientists and machine learning (ML) developers love MXNet due to its flexibility and efficiency when building deep learning models. Amazon SageMaker is committed to improving the customer experience for all ML frameworks and libraries, including MXNet. With the latest release of MXNet 1.4, you can use MXNet containers in internet-free mode, and use Model Server for Apache MXNet (MMS) to deploy deep learning models for inference.

Model Server for Apache MXNet (MMS) is an open source toolset that simplifies the task of deploying deep learning models for inference. You can use MMS to serve MXNet and other framework models easily, quickly, and at scale. For more information, see Model Server for Apache MXNet v1.0 release.

The MXNet 1.4 update has several new features, including network isolation, Julia bindings, experimental control flow operators, JVM memory management, graph optimization and quantizations, and usability enhancements. For change log information, see Apache MXNet (incubating) 1.4.0.

Amazon SageMaker training and deployed inference containers are internet-enabled by default. With the new MXNet container, you are able to use containers in internet-free mode, which enables running training jobs inside a secure and isolated environment. If you do not want Amazon SageMaker to provide external network access to your training or inference containers, you can enable network isolation when you create your training job or model.

The MXNet 1.4 update is accompanied by the Python 3.6 support. You can now use Python 3.6 when building and deploying deep neural networks with the MXNet framework. For more information, see What’s New In Python 3.6.

With the latest release, the Keras version for MXNet is now 2.2.4.1. Keras 2.2.4.1 adds bug and usability fixes on top of the API completeness and usability improvements introduced in the Keras 2.2.3 release. For release notes, see the Keras 2.2.4 GitHub repo.

Another update is the 1.4.1 release of ONNX. 1.4.1 comes with several big features, including support for large models, ability to store the data externally, and control flow operators. It also adds a test driver for ONNXIFI enabling C++ tests.

OpenBlas, an optimized BLAS (Basic Linear Algebra Subprograms) library, is no longer available in MXNet 1.4. MXNet now offers MKL pip packages that are much faster when running on Intel hardware.

With MKL BLAS, performance improves with variable range, depending on the computation load of the models. MKL DNN uses a BLAS library internally and supports linking with MKLML or MKL for additional performance. For more information, see Build/Install MXNet with MKL-DNN.

Get started with Amazon SageMaker

The new enhancements to built-in containers are now available in all AWS Regions where Amazon SageMaker is available. We recommend that you update your Python SDK version to use this release of MXNet and MMS. You can do this by running the following command:

pip install --upgrade sagemaker

For more information about using pre-configured containers within Amazon SageMaker, see Use Apache MXNet with Amazon SageMaker. To learn more about how to produce Docker images for serving MXNet on Amazon SageMaker, visit the GitHub page for SageMaker MXNet Serving Container.

 


About the Author

Erkan Tas is a Sr. Product Manager for Amazon SageMaker. He is on a mission to make Artificial Intelligence easy, accessible, and scalable. He is also a sailor, overlander, science and nature admirer, Go and Stratocaster player.

[D] How much can we change a paper before the camera ready version?

In preparation for author rebuttal for a conference, we have conducted additional experiments and significantly improved our paper already (of course the reviewers can’t see this yet, we may mention it during author rebuttal if the changes relate to any of their comments).

I’m wondering if this is an issue and does the final version of the paper have to be very close to the initial submission, and only improve upon what the reviewers mention? Or can we add other improvements as long as they are high quality and don’t detract from the original submission?

submitted by /u/AnonMLstudent
[link] [comments]

[D] Contract Data Science/ML gig at Microsoft: Good idea or bad idea?

Asking for a friend who is not on Reddit:

Friend has been looking to break out of engineering and into more DS/ML based work. Has lots of dev experience + good knowledge of ML learning from Kaggle, Coursera certifications etc….

Was offered a role as DS at MSFT, but through a vendor. Is wondering whether its a good idea or not:

Pros: Hiring manager and scientists from Vendor who interviewed him seemed like good people with strong backgrounds (He hasn’t any visibility to the MSFT FTEs he will be working with, only the vendor). Job is exactly what he wants to be doing. Would get exposure to some pretty cool systems.

Cons: A couple of his connections within MSFT are saying that it is a bad idea, vendors don’t get treated well. Chances are the work isn’t as interesting as the hiring manager makes it out to be, otherwise it wouldn’t be handed to vendor. For the same reason, won’t look good on resume either.

Anybody have any experience or input on this?

submitted by /u/AlexSnakeKing
[link] [comments]

[P] Albumentations, an image augmentation library version 0.3 released. New weather augmentations, serialization support for reproducible machine learning pipelines, and speedup improvements

[P] Albumentations, an image augmentation library version 0.3 released. New weather augmentations, serialization support for reproducible machine learning pipelines, and speedup improvements

You can download the library from PyPI using pip install -U albumentations or clone the latest version from https://github.com/albu/albumentations

New features

Weather augmentations.

We’ve added weather augmentations such as RandomRain, RandomSnow, RandomSunFlare, RandomShadow, RandomFog.

https://i.redd.it/4x2y4nty5q731.jpg

Pipeline serialization.

Now we can define transformations in the code and serialize them in python dictionary, json and yaml files. A Jupyter notebook with examples.

New transformations.

Lambda, GaussianBlur, ChannelDropout, CoarseDropout.

The full release notes are available at https://github.com/albu/albumentations/releases/tag/0.3.0

submitted by /u/alexparinov
[link] [comments]

[D] Boundary element method for Differential Equations

Boundary element methods can be used to solve differential equations, where for some of the elements (boundary elements), the solution value is given/ fixed. Boundary element methods have been used in ML, example being solving image blending task using poisson equation with given boundary elements.

https://en.wikipedia.org/wiki/Discrete_Poisson_equation

My question is: What is the effect of sparsity of boundary elements on the solution of the differential equation ?

submitted by /u/WillingCucumber
[link] [comments]

[D] Jeff Hawkins: Thousand Brains Theory of Intelligence | Artificial Intelligence Podcast

[D] Jeff Hawkins: Thousand Brains Theory of Intelligence | Artificial Intelligence Podcast

Jeff Hawkins is the founder of Redwood Center for Theoretical Neuroscience in 2002 and Numenta in 2005. In his 2004 book titled On Intelligence, and in his research before and after, he and his team have worked to reverse-engineer the neocortex and propose artificial intelligence architectures, approaches, and ideas that are inspired by the human brain. These ideas include Hierarchical Temporal Memory (HTM) from 2004 and The Thousand Brains Theory of Intelligence from 2017.

Video: https://www.youtube.com/watch?v=-EVqrDlAqYo

https://i.redd.it/xig86isqop731.png

Outline:

0:00 – Introduction

1:28 – Understanding how the human brain works

5:44 – Parts of the brain

11:05 – How much do we understand?

14:20 – Nature of time in the brain

20:22 – Building a theory of intelligence

34:29 – Thousand brains theory of intelligence

40:06 – Ensembles and sensor fusion

44:00 – Concepts and language

45:38 – Memory palace and method of loci

50:20 – Reference frames

57:33 – Open problems

59:00 – Context

1:01:50 – Introspective thinking about the brain

1:04:19 – Deep learning

1:23:09 – Benchmarks

1:27:07 – Brain learning process

1:34:33 – How far are we from solving intelligence

1:38:37 – Possibility of AI winter

1:39:58 – Consciousness and intelligence

1:49:16 – Mortality

1:53:49 – Will understanding intelligence make us happy?

1:55:19 – Existential threats of AI

2:01:45 – Super-human intelligence and our future

submitted by /u/UltraMarathonMan
[link] [comments]

[P] Heuristical keyword extraction from documents and encoding for training GPT-2 to generate texts based on user-specified keywords (+ parallelized spaCy)

https://github.com/minimaxir/gpt-2-keyword-generation

A couple weeks ago I posted a Reddit title generator app based on GPT-2 to this subreddit which allows the user to generate Reddit titles based on a subreddit and also allows the user to specify the keywords to condition the title generation upon. There were a few comments asking how I handled the keywords, so here it is.

The heuristics the script uses is outlined in the README. It’s not the most mathematically-rigorous option, but it’s hard to argue with the results.

When working with the Reddit data, I found that spaCy was too slow to encode hundreds of thousands of texts (would have taken 24+ hours on my first pass). So I used ray to parallelize it, which resulted in a 11x speedup that’s more reasonable. That may end up being of more interest to this subreddit.

Speaking of the Reddit API, now that the keyword generation is open sourced, I have open-sourced the Reddit API itself (sans the model since that’s hard to distribute), with a mini howto on how I built it.

submitted by /u/minimaxir
[link] [comments]