Modules

Config

The Config module. It defines the Config class.

class sng.Config.Config(**kwargs)[source]

Configuration options for model training and name generation

**kwargs:
Keyword arguments that will overwrite the default config options.

To create a Config object that results in simulating names between 6 and 10 letters:

cfg = sng.Config(
    min_word_len=6,
    max_word_len=10
)

To quickly inspect all values:

cfg.to_dict()
batch_size = None

int: The batch size for training the RNN

debug = None

bool: If true, methods will add some additional attributes to a Generator object’s debug dict.

epochs = None

int: How many epochs to train the RNN for?

hidden_dim = None

int: Number of hidden units per LSTM layer

max_word_len = None

int: How long should simulated words be maximum?

min_word_len = None

int: How long should simulated words be at least?

n_layers = None

int: How many LSTM layers in the model?

suffix = None

str: A suffix to append to the suggested names.

Choose e.g. ” Software” (with a leading space!) to see how your company name would look with the word Software at the end.

temperature = None

float: Sampling temperature. Lower values are “colder”, i.e. sampling probabilities will be more conservative.

to_dict()[source]

Convert Config object to dictionary.

verbose = None

bool: If true, prints helpful messages on what is happening.

Generator

class sng.Generator.Generator(config=<sng.Config.Config object>, wordlist_file=None, wordlist=None)[source]

Main class that holds the config, wordlist, and the trained model.

config : sng.Config, optional
A Config instance specifying training and simulation parameters. If not supplied, a default configuration will be created.
wordlist_file : str
Path to a textfile holding the text corpus you want to use.
wordlist : list of strings
Alternatively to wordlist_file, you can provide the already processed wordlist, a list of (ideally unique) strings.
config : sng.Config
The Config object supplied, or a default object if none was supplied at initialization.
wordlist : list of strings
A processed list of unique words, each ending in a newline. This is the input to the neural network.

You can create a word generator like this:

import sng
cfg = sng.Config()

# Folder for pre-installed wordlists:
wordlist_folder = os.path.join(
    os.path.dirname(os.path.abspath(sng.__file__)), 'wordlists')
sample_wordlist = os.path.join(wordlist_folder, 'latin.txt')

# Create a Generator object with some wordlist:
gen = sng.Generator(wordlist_file=sample_wordlist, config=cfg)

# Train the model:
gen.fit()

# Get a few name suggestions:
gen.simulate(n=5)
fit()[source]

Fit the model. Adds the ‘model’ attribute to itself.

classmethod load(directory)[source]

Create a Generator object from a stored folder.

directory : str
Folder where you used Generator.save() to store the contents in.
save(directory, overwrite=False)[source]

Save the model into a folder.

directory : str
The folder to store the generator in. Should be non-existing.
overwrite : bool
If True, the folder contents will be overwritten if it already exists. Not recommended, though.
simulate(n=10, temperature=None, min_word_len=None, max_word_len=None)[source]

Use the trained model to simulate a few name suggestions.

n : int
The number of name suggestions to simulate
temperature : float or None
Sampling temperature. Lower values are “colder”, i.e. sampling probabilities will be more conservative. If None, will use the value specified in self.config.
min_word_len : int or None
Minimum word length of the simulated names. If None, will use the value specified in self.config.
max_word_len : int or None
Maximum word length of the simulated names. If None, will use the value specified in self.config.

Wordlists