### Resource retrieval

Get the pre-trained network:

Out[1]= | |

### Basic usage

Predict the next character of a given sequence:

Out[2]= | |

Get the top 15 probabilities:

Out[3]= | |

Plot the top 15 probabilities:

Out[4]= | |

### Generation

Generate text efficiently with NetStateObject. A built-in option for temperature sampling is available in Wolfram Language 12.0, while it has to be implemented explicitly in earlier versions.

Generate for 100 steps using “#ifdef” as an initial string:

Out[6]= | |

The third optional argument is a “temperature” parameter that scales the input to the final softmax. A high temperature flattens the distribution from which characters are sampled, increasing the probability of extracting less likely characters:

Out[7]= | |

Decreasing the temperature sharpens the peaks of the sampling distribution, further decreasing the probability of extracting less likely characters:

Out[8]= | |

Very high temperature settings are equivalent to random sampling:

Out[9]= | |

Very low temperature settings are equivalent to always picking the character with maximum probability. It is typical for sampling to “get stuck in a loop”:

Out[10]= | |

### Inspection of predictions

Define a function that takes a string and guesses the next character as it reads, showing the predictions in a grid. The input string is shown on top, while the top 5 predictions are aligned below each character, starting from more likely guesses. For each prediction, the intensity of the color is proportional to the probability:

Out[12]= | |

### Net information

Inspect the sizes of all arrays in the net:

Out[13]= | |

Obtain the total number of parameters:

Out[14]= | |

Obtain the layer type counts:

Out[15]= | |

Display the summary graphic:

Out[16]= | |

### Export to MXNet

Export the net into a format that can be opened in MXNet:

Out[17]= | |

Export also creates a net.params file containing parameters:

Out[18]= | |

Get the size of the parameter file:

Out[19]= | |

The size is similar to the byte count of the resource object:

Out[20]= | |