spec2vec.serialization.model_exporting module

spec2vec.serialization.model_exporting.export_model(model: Word2Vec, output_model_file: Union[str, PathLike], output_weights_file: Union[str, PathLike])[source]

Write a lightweight version of a Word2Vec model to disk. Such a model can be read to calculate scores but is not capable of further training.

Parameters
  • modelWord2Vec trained model.

  • output_model_file – A path of json file to save the model.

  • output_weights_file – A path of .npy file to save the model’s weights.

spec2vec.serialization.model_exporting.extract_keyedvectors(model: Word2Vec) dict[source]

Extract KeyedVectors object from the model, convert it to a dictionary and remove redundant keys.

Parameters

modelWord2Vec trained model.

Returns

Dictionary representation of KeyedVectors without redundant keys.

Return type

keyedvectors

spec2vec.serialization.model_exporting.get_weights_format(weights: Union[ndarray, csr_matrix, csc_matrix]) str[source]

Get the array format of the model’s weights.

Parameters

weights – Model’s weights.

Returns

Format of the model’s weights.

Return type

weights_format

spec2vec.serialization.model_exporting.save_model(keyedvectors: dict, output_model_file: Union[str, PathLike])[source]

Write model’s metadata to disk in json format.

spec2vec.serialization.model_exporting.save_weights(weights: Union[ndarray, csr_matrix, csc_matrix], output_weights_file: Union[str, PathLike])[source]

Write model’s weights to disk in .npy dense array format. If the weights are sparse, they are converted to dense prior to saving.