Building Smart Applications that Learn

Etienne Bernard, Sebastian Bodenstein
Wolfram Research

Join the Conversation #WolframTechConf

City population

Create a web app that:

Returns the population of a city from a natural language input

"paris" -> ...

Quit

form=FormFunction[{"first"->"City"},#first[(EntityProperty["city population", EntityProperty["City","Population"], "EntityProperty[\"City\", \"Population\"]"])] &, "PNG"];

CloudDeploy[form, Permissions->"Public"]

Natural Multiplication

Create a function that multiplies two numbers given by natural language

"multiply three and 4"

GrammarApply

multiplication=CloudDeploy[GrammarRules[{FixedOrder["multiply", a:GrammarToken["SemanticNumber"], "and", b:GrammarToken["SemanticNumber"]] :> a * b}
]
]

GrammarApply[multiplication, "multiply seven and 3"]

Famous Dopelganger

Create a web application that, from a picture of yourself:

Displays the name of your famous dopelganger

Displays a picture of both of you

Try it on your phone

form = FormFunction[
	{"picture"->"Image"},
	Module[{entity},
		entity = Classify["NotablePerson", #picture];
		{#picture, entity, entity[(EntityProperty["image", EntityProperty["Person","Image"], "EntityProperty[\"Person\", \"Image\"]"])]}
	]&,
	"PNG"
];

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

URLShorten[c]

Classify["NotablePerson", ...]

URLShorten

form

LinguisticAssistant

(Entity["Zinédine Zidane", Entity["Person","ZinedineZidane::69k9b"], "Entity[\"Person\", \"ZinedineZidane::69k9b\"]", "person"])[(EntityProperty["image", EntityProperty["Person","Image"], "EntityProperty[\"Person\", \"Image\"]"])]

Color?

Create a web app that, from any picture:

Explains to a human what is the dominant color

Test it on your phone

Try it on the blue-black-white-gold debate colored dress

training={ ->"Red",->"Green",->"Blue",->"Black",->"White",->"Gray",->"Cyan",->"Magenta",->"Yellow",->"Brown",->"Orange",->"Pink",->"Purple"};
training[[All,1]] = Rasterize/@training[[All,1]];

c=Classify[training,Method->"NearestNeighbors"]

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

c[Rasterize[]]

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

URLShorten[co]

ColorData["HTML","ColorRules"]

Wikipedia topics

Using Wikipedia articles, create a web app that:

Identify the topic of a text

An application that truly learns

Goal:

Predict how long the clients of a restaurant will wait in the queue

Clients should be able to see predictions on their smartphone

Solution:

Manage the queue in the cloud

Store the queue history, and create a training set from past data

Train a predictor on the training set

Deploy a visualization program

CloudPut[<||>,"queue"]

trainingset=Import["https://www.dropbox.com/s/5h62xiaq2o48452/TrainingsetQueue.m?dl=1"];

CloudPut[trainingset,"trainingset"]

Add-to-queue form:

addform = FormFunction[
	{
		"Name" -> "String",
		"Group size" -> "Integer",
		"Phone number" -> <|"Interpreter" -> "PhoneNumber", "Required"-> False|>
	}
	,
	Module[
		{data},
		data = CloudGet["queue"];
		data = Append[data, #Name -> <|
			"GroupSize" -> #"Group size", 
			"Day" -> DayName[Now],
			"Time" -> UnixTime[],
			"PhoneNumber" -> #"Phone number",
			"History" -> {Length[data]+1 -> UnixTime[]}
		|>];
		CloudPut[data, "queue"];
		HTTPRedirect["addform"]
	] &
	,
	AppearanceRules -> <|
		"Description" -> "Add to the queue:"
	|>
];

CloudDeploy[addform, "addform"]

Dataset[CloudGet["queue"]]

Remove-from-queue form:

dropform = FormFunction[
	{
		"Name" :> Keys[CloudGet["queue"]]
	}
	,
	Module[
		{data, user, i, example, choice, trainingset, p},
		data = CloudGet["queue"];
		user = data[#Name];
		data = KeyDrop[data, #Name];
		i = 0;
		data = Map[(
			i++;
			MapAt[Append[#, i -> UnixTime[]]&, #, "History"]
		)&, 
			data
		];
		CloudPut[data, "queue"];
		choice = RandomChoice[user["History"]];
		example = user[[{"GroupSize", "Day"}]];
		example = Append[example, "Position" -> choice[[1]]];
		example = example -> UnixTime[] - choice[[2]];
		trainingset = CloudGet["trainingset"];
		trainingset = Append[trainingset, example];
		CloudPut[trainingset, "trainingset"];
		p = Predict[trainingset];
		CloudPut[p, "predictor"];
		HTTPRedirect["dropform"]
	] &
	,
	AppearanceRules -> <|
		"Description" -> "Remove from the queue:"
	|>
];

CloudDeploy[dropform, "dropform"]

Dataset[CloudGet["queue"]]

Visualization object:

visualize = Delayed[Module[
	{data, features, i, p, predictions, plots},
	data = CloudGet["queue"];
	features = data[[All, {"GroupSize", "Day"}]];
	i = 0;
	features = Map[(
		i++;
		Append[#, "Position" -> i]
	)&,
		features
	];
	p = CloudGet["predictor"];
	predictions = p /@ features;
	predictions = Ceiling[UnitConvert[Quantity[#,"Seconds"], "Minutes"]] & 
		/@ predictions;
	plots = Plot[
		PDF[p[#, "Distribution"], x*60],
		{x, 0, 45},
		PlotRange -> {0, Full},
		Filling -> Bottom,
		Ticks -> {Automatic, None}
	] & /@ features;
	ExportForm[
		Pane[Magnify[Grid[
			Transpose@{Keys[predictions], Values[predictions], Values[plots]}
			], 3], {2000, 2000}
		]
		,
		"PNG"
	]
]];

CloudDeploy[visualize, "visualize"]

Conclusion

Natural language input

Built-in knowledge (data & machine-learned function)

Automatic learning functions

Deployment mechanisms (api, form, mobile app)

Continuously being updated...