22
|
Machine Learning
So far in this book, when we’ve wanted the Wolfram Language to do something, we’ve written code to tell it exactly what to do. But the Wolfram Language is also set up to be able to learn what to do just by looking at examples, using the idea of machine learning.
We’ll talk about how to train the language yourself. But first let’s look at some built-in functions that have already been trained on huge numbers of examples.
LanguageIdentify
takes pieces of text, and identifies what human language they’re in.
Identify the language each phrase is in:
LanguageIdentify[{"thank you","merci","dar las gracias","感謝","благодарить"}]
Out[1]=

English
,
French
,
Spanish
,
Chinese
,
Russian

The Wolfram Language can also do the considerably more difficult “artificial intelligence” task of identifying what an image is of.
Identify what an image is of:
ImageIdentify[
]
Out[2]=
cheetah
There’s a general function
Classify
, which has been taught various kinds of classification. One example is classifying the “sentiment” of text.
Upbeat text is classified as having positive sentiment:
Classify["Sentiment","I'm so excited to be programming"]
Out[3]=
Positive
Downbeat text is classified as having negative sentiment:
Classify["Sentiment","math can be really hard"]
Out[4]=
Negative
You can also train
Classify
yourself. Here’s a simple example of classifying handwritten digits as 0 or 1. You give
Classify
a collection of training examples, followed by a particular handwritten digit. Then it’ll tell you whether the digit you give is a 0 or 1.
With training examples,
Classify
correctly identifies a handwritten 0:
Classify[{
0,
1,
0,
1,
1,
0,
0,
1,
1,
0,
0,
0,
1,
0,
1,
0,
1,
1,
1},​​
]
Find what number in the list is nearest to 22:
Find the nearest three numbers:
Find the 3 colors in the list that are nearest to the color you give:
It also works on words.
Find the 10 words nearest to “good” in the list of words:
(For the following evaluation to work, you must be signed in to the Wolfram Cloud.)
Create an image of the word “hello”, then blur it:
Recognize text in the image:
Generate a sequence of progressively more blurred pieces of text:
Progressively blur a picture of a cheetah:
Collect “clusters” of similar colors into separate lists:
Create a graph of connections based on nearness in “color space”:
Show nearby colors successively grouped together:
Make a rasterized image of each letter in the alphabet:
Vocabulary
Q&A
How come I’m getting different results from the ones shown here?
It’s based on artificial neural networks inspired by the way brains seem to work. It’s been trained with millions of example images, from which it’s progressively learned to make distinctions. And a bit like in the game of “twenty questions”, by using enough of these distinctions it can eventually determine what an image is of.
At least 10,000—which is more than a typical human. (There are about 5000 “picturable nouns” in English.)
If the general area (like everyday images) is one it already knows well, then as few as a hundred. But in areas that are new, it can take many millions of examples to achieve good results.
Can a single graph have several disconnected parts?
Absolutely. An example is the last graph in this section.
There’s no easy answer. When it’s given a collection of things, it’ll learn features that distinguish them—though it’s typically primed by having seen many other things of the same general type (like images).
Tech Notes
◼
The Wolfram Language stores its latest machine learning classifiers in the cloud—but if you’re using a desktop system, they’ll automatically be downloaded, and then they’ll run locally.
More to Explore