DeepLearning
A substantial effort was put into Deep Learning for Maple 2021, including offering a variety of new specialty forms of neural networks.
with⁡DeepLearning:
New commands
Examples
Details
These commands are new for Maple 2021:
BidirectionalLayer
EmbeddingLayer
LongShortTermMemoryLayer
ConvolutionLayer
FlattenLayer
MaxPoolLayer
DenseLayer
GatedRecurrentUnitLayer
Sequential
DropoutLayer
GetEagerExecution
SetEagerExecution
New types of neural networks
The addition of Layer objects offers an easy mechanism for building specialized types of neural networks, including the following:
Convolutional neural networks: using ConvolutionLayer. These networks are often used for tasks such as image and video recognition.
Recurrent neural networks: using GatedRecurrentUnitLayer or LongShortTermMemoryLayer. These networks are often used for text processing or classification.
The new Sequential command allows one or more Layers to be stacked together, feeding the output from one layer into the next as input. This allows you to build sophisticated special-purpose neural networks by composing layers of different types.
Both Layer objects and the composite models created by the Sequential command are examples of Model objects. A Model can be fed new data to generate predictions and can also be saved to a file in the standard HDF5 file format.
Sequential Model: The Pima Diabetes Dataset
In this example we build a Sequential model with DenseLayers to model the Pima diabetes dataset, generating predictions about whether individuals will be diagnosed with a diabetes based on other diagnostic measurements included in the dataset.
This dataset is originally from the United States National Institute of Diabetes and Digestive and Kidney Diseases. All patients here are females at least 21 years old of Pima Indian heritage.
Source: Pima Indian Diabetes Database, https://www.kaggle.com/uciml/pima-indians-diabetes-database. Data originally published in:
Smith, J.W., Everhart, J.E., Dickson, W.C., Knowler, W.C., & Johannes, R.S. (1988). Using the ADAP learning algorithm to forecast the onset of diabetes mellitus. In Proceedings of the Symposium on Computer Applications and Medical Care (pp. 261--265). IEEE Computer Society Press.
We first load the data into a DataFrame:
dataset≔Import⁡datasets/pima-epidemiology-diabetes.csv,base=datadir
As before, we divide the dataset into training and test data. We are attempting to predict the last column, Outcome.
training_data,test_data≔dataset1..600,..,dataset601..−1,..
We define a neural network using the Sequential command which stacks one or more neural network layers.
model≔Sequential⁡DenseLayer⁡12,activation=relu,DenseLayer⁡8,activation=relu,DenseLayer⁡1,activation=sigmoid
model≔DeepLearning Model<tensorflow.python.keras.engine.sequential.Sequential object at 0x138244bb0>
model:-Compile⁡loss=binary_crossentropy,optimizer=adam,metrics=accuracy
Python:−None
We can train the data easily with the Fit command:
model:-Fit⁡training_data..,1..8,training_dataOutcome,epochs=150,batchsize=10
<Python object: <tensorflow.python.keras.callbacks.History object at 0x13838f430>>
We now have a trained model whose accuracy we can test against the test data or against any new data. The accuracy is not especially high but nevertheless useful for predictive purposes.
model:-Evaluate⁡test_data..,1..8,test_dataOutcome
loss=0.613269329071045,accuracy=0.690476179122925
To get a sense of what how this model behaves on individuals within the dataset, we can take a slice from the test data and compare the observed vs. predicted outcome.
predictions≔model:-Predict⁡test_data760..768,1..8
predictions≔0.2222759127616880.1320905089378360.5618885755538940.1092223823070530.3004200160503390.2347947061061860.2265433967113490.1627641916275020.144395038485527
test_data760..768,Outcome,predictions
760176107621763076407650766076717680,0.2222759127616880.1320905089378360.5618885755538940.1092223823070530.3004200160503390.2347947061061860.2265433967113490.1627641916275020.144395038485527
The DeepLearning package is implemented using Google TensorFlow™ and now provides access to a subset of the TensorFlow Python API, version 2.2.0.
The DeepLearning package is currently not supported on the following platforms: Macs powered by Apple's M1 chip (Apple Silicon).
Download Help Document