Modules — Startup Name Generator (sng) 0.3 documentation

# Modules

## Config

The Config module. It defines the Config class.

class `sng.Config.` `Config`(**kwargs)

  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`()

    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)

  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`()

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

  classmethod `load`(directory)

    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)

    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)

    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

`sng.wordlists.wordlists.` `load_builtin_wordlist`(name)

  Load and process one of the wordlists that ship with the sng package.

  name : str
    A file name of one of the files in the wordlists/ directory. Call `show_builtin_wordlists()` to see a list of available names. Choose one of these.
  list : a list of strings
    A wordlist. Literally, a list of words in the text corpus. It’s not yet preprocessed, so there are still duplicates etc. in there. This is taken care of by `sng.Generator`’s `__init__` method.

`sng.wordlists.wordlists.` `show_builtin_wordlists`()

  Returns a list of all builtin wordlists’ filenames.

  Use one of them as an argument to `load_builtin_wordlist()` and get back a ready-to-go wordlist.