Input/output functions

These functions help writing to and reading from files

dynn.io.load(filename, ignore_invalid_names=False)

Load a ParameterCollection from a .npz file.

This will recover the subcollection structure.

Parameters:
  • filename (str) – File to load from.
  • ignore_invalid_names (bool, optional) – Ignore elements with invalid parameter names in the .npz without raising an exception. This is useful if for some reason the .npz contains other arrays.
Returns:

Loaded ParameterCollection

Return type:

dynet.ParameterCollection

dynn.io.loadtxt(filename, encoding='utf-8')

Read text from a file

dynn.io.populate(pc, filename, ignore_shape_mismatch=False)

Populate a ParameterCollection from a .npz file

Parameters:
  • pc (dynet.ParameterCollection) – Parameter collection to populate.
  • filename (str) – File to populate from.
  • ignore_shape_mismatch (bool, optional) – Silently ignore shape mismatch between the parameter and the value in the .npz file (just don’t load the parameter and move on)
dynn.io.save(pc, filename, compressed=True)

Save a ParameterCollection as a .npz archive.

Each parameter is an entry in the archive and its name describes the subcollection it lives in.

Parameters:
  • pc (dynet.ParameterCollection) – Parameter collection to save.
  • filename (str) – Target filename. The .npz extension will be appended to the file name if it is not already there.
  • compressed (bool, optional) – Compressed .npz (slower but smaller on disk)
dynn.io.savetxt(filename, txt, encoding='utf-8')

Save text to a file