Quickstart

In [1]:
%load_ext autoreload
%autoreload 2
In [2]:
# While the sng package is not installed, add the package's path
# (the parent directory) to the library path:

import os
import sys
sys.path.insert(0, os.path.abspath('../../'))
In [3]:
import sng
Using TensorFlow backend.

Prepare and train the model

Create a Config object to set your own preferences regarding training or simulation:

In [4]:
cfg = sng.Config(
    epochs=50
)
cfg.to_dict()
Out[4]:
{'batch_size': 64,
 'debug': True,
 'epochs': 50,
 'hidden_dim': 50,
 'max_word_len': 12,
 'min_word_len': 4,
 'n_layers': 2,
 'suffix': '',
 'temperature': 1.0,
 'verbose': True}

Choose from one of these builtin wordlists to get started quickly:

In [5]:
sng.show_builtin_wordlists()
Out[5]:
['gallic.txt',
 'english.txt',
 'behemoth.txt',
 'lorem-ipsum.txt',
 'greek.txt',
 'black-speech.txt',
 'german.txt',
 'french.txt',
 'latin.txt',
 'pokemon.txt']

We’ll load the latin wordlist and look at a few sample words:

In [6]:
latin = sng.load_builtin_wordlist('latin.txt')
In [7]:
latin[:5]
Out[7]:
['in', 'nova', 'fert', 'animus', 'mutatas']

Initialize and fit the word generator:

In [8]:
gen = sng.Generator(wordlist=latin, config=cfg)
2973 words

24 characters, including the \n:
['\n', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'x', 'y', 'z']

First two sample words:
['versis\n', 'phoebe\n']
In [9]:
gen.fit()
epoch 0 words: Hgdrahqn, Zrley, Fmdiuus, Ozrhns, loss: 1.5835
epoch 10 words: Lacencumasm, Nococi, Ronse, Xbturuleraet, loss: 1.2565
epoch 20 words: Oacnidao, Crerdene, Raalibei, Gadentis, loss: 1.132
epoch 30 words: Tugonais, Oustis, Aipsa, Tumibes, loss: 1.0799
epoch 40 words: Viss, Rospis, Ursant, Untis, loss: 1.035
In [10]:
gen.simulate(n=4)
Out[10]:
['Matus', 'Ompanta', 'Virgimque', 'Tantae']
In [11]:
gen.config.suffix = ' Software'
In [12]:
gen.simulate(n=4)
Out[12]:
['Inbut Software', 'Lusior Software', 'Ronmaeis Software', 'Hummno Software']

Save and load the model for later

In [13]:
gen.save('my_model', overwrite=True)

Then:

In [14]:
gen2 = sng.Generator.load('my_model')
2973 words

24 characters, including the \n:
['\n', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'x', 'y', 'z']

First two sample words:
['opus\n', 'adorant\n']
In [15]:
gen2.simulate(n=4)
Out[15]:
['Inenterur Software', 'Unpremum Software', 'Astris Software', 'Urne Software']
In [ ]: