Machine Learning in the Wolfram Language

Etienne Bernard
Wolfram Research
etienneb@wolfram.com

The Wolfram Language™

Mathematica®

At first, math software:

Solve[x^2+a x+1==0,x]

Plot3D[Sin[x+y^2],{x,-3,3},{y,-2,2}]

Nowadays, much more...

(2014) “The Wolfram Language” = Language of Mathematica

The Wolfram Language—Overview

High level

Can do a lot with a small amount of code

Symbolic

Everything is an expression:

Sin[Exp[x+2]*y+z]

FullForm[%]

TreeForm[%]

Surprisingly powerful paradigm

Mostly functional

No side effects (easier to debug)

Many built-in functions (~ 5000)

Span most domains (http://reference.wolfram.com/language)

Carefully documented

Direct access to data

Byproduct of Wolfram|Alpha®:

DateListPlot[(Entity["Apple", Entity["Financial","NASDAQ:AAPL"], "Entity[\"Financial\", \"NASDAQ:AAPL\"]", "financial entity"])[]]

Deployment mechanisms

Transform any code into an API

One example:

BlurFaces[img_] := Module[
	{faces, mask, blur},
	faces = FindFaces[img];
	mask = createMask[faces, img];
	blur = Max[Abs[#2 - #1] & @@@ faces]/5;
	ImageCompose[
		img,
		SetAlphaChannel[
			Blur[img, blur],
			ColorNegate @ Blur[mask, blur]
		]
	]
];
createMask[faces_, img_] := Graphics[
	Disk[Mean[##], First@Differences[##]/2] & /@ faces,
	PlotRange -> Transpose[{{0, 0}, ImageDimensions[img]}], 
	ImageSize -> 1->1
];

Dynamic[BlurFaces[CurrentImage[]]]

form=FormFunction[{"picture"->"Image"}, BlurFaces[#picture] &,"PNG"]

co=CloudDeploy[form,Permissions->"Public"]

Machine Learning?

Computer “Learns” a Model from Data

model = program with tunable parameters

learning = tuning parameters to fit data

⟶

{ ->cat, ->dog,...}	⟶

Typical Tasks

Classification of images, sound, text, etc.

->cat, ->dog,...

Prediction of a variable in a dataset

(6 yo, female) -> 1.15 m, (11 yo, male) -> 1.48 m, ...

Text translation

“the house is blue” -> “la maison est bleue”

Prediction of a time series

Anomaly detection

Data clustering

Robot learning how to walk

Learning Paradigms

Supervised learning

Input -> output mapping from examples

Most common paradigm

Unsupervised learning

Only inputs

On the rise

Reinforcement learning

Active agent, feedback from environment

Not much used yet (but a lot of research)

In the Wolfram Language

Automatic Machine Learning Framework

Functions:

Classify & Predict

ClusterClassify, FindClusters, etc.

DimensionReduction, FeatureExtraction

FindDistribution, FindFormula

Very easy to use

Task oriented

Automatic

Wide range of data types (numerical, images, text, etc.)

Neural Network Framework

Model oriented

High flexibility

High performance

GPU training

Out-of-core training

NetGraph[{Ramp,LogisticSigmoid,CatenateLayer[]},{1->2,{1,2}->3}]

Developed Using Machine Learning

Built-in classifiers, ImageIdentify, TextCases, etc.

Built-in Machine Learning

Built-in Classifiers

cl=Classify["Language"]

cl["Quelle est cette langue?"]

cl["What is this language?","TopProbabilities"]

ImageIdentify

ImageIdentify[]

ImageIdentify[]

TextStructure

str=TextStructure["The house is blue. My dog is fast."]

TextCases

moon=WikipediaData["Moon"];

TextCases[moon,"Quantity"->"Interpretation"]

TakeLargest[Counts[TextCases[moon,"Noun"]],10]

NetModel["Inception V3 Trained on ImageNet Competition Data"]

Dataset of Images

characters={"Rocket Racoon","Groot","Gamora","Star-Lord"};

characterimages=WebImageSearch[#, "Thumbnails",MaxItems->20] & /@ characters;

images=RandomSample[Flatten[characterimages]];

FeatureSpacePlot

FeatureSpacePlot[images]

FeatureExtraction

fe=FeatureExtraction[images]

fe[]

FeatureExtract[{{"the cat is grey",,(DateObject["Mon 5 May 2014 09:53:06", DateObject[{2014,5,5},TimeObject[{9,53,6.301579`}]]])},{"what a nice dog",,(DateObject["Sat 1 Jan 2000 00:00:00", DateObject[{2000,1,1},TimeObject[{0,0,0.`}]]])},{"my cat is fast",,(DateObject["Dec 2006", DateObject[{2006,12}]])},{"this dog is scary",,(DateObject["Mon 4 Apr 2016 15:59:18""GMT"-4.`, DateObject[{2016,4,4},TimeObject[{15,59,18.273754`},TimeZone->-4.`],TimeZone->-4.`]])}}]

Search System

Length[images]

searchdataset=images[[;;70]];
images[[71;;]]

nf=FeatureNearest[searchdataset]

nf[]

nf[]

Classification

dataset=Thread/@Thread[characterimages->characters];
dataset = RandomSample[Flatten[dataset]];

trainingset=dataset[[;;60]];
testset=dataset[[61;;]];

c=Classify[trainingset]

c[]

c[,"Probabilities"]

cm=ClassifierMeasurements[c,testset]

cm["Accuracy"]

cm["ConfusionMatrixPlot"]

cm["Examples"->{"Star-Lord","Gamora"}]

cm["WorstClassifiedExamples"->3]

cm["BestClassifiedExamples"->3]

Topic Classification

topics=Get["~/Presentations/2016_SXSW/Dataset/topic.m"];

RandomSample[topics,1]

training=topics[[;;100000]];

c=Classify[training]

text="";
Column@{InputField[Dynamic[text],String,ContinuousAction->True],Dynamic[Column@c[text,{"TopProbabilities",3}]]}

Prediction

data=ResourceData["Sample Data: Boston Homes"]

ResourceData["Sample Data: Boston Homes","ColumnDescriptions"]

data=RandomSample[data];
trainingdata=data[[;;400]];
testdata=data[[401;;]];

p=Predict[trainingdata->"MEDV", PerformanceGoal->"Quality"]

pm=PredictorMeasurements[p,testdata->"MEDV" ]

pm["ComparisonPlot"]

pm["Examples"->{{0,10},{10,20}}]

pm["StandardDeviation"]

pm["StandardDeviation","Uncertainty" -> True]

Other Functions

ClusterClassify

FindFormula

ActiveClassification

BayesianMaximization