spec2vec.serialization package¶
Functions for exporting and importing trained Word2Vec
model to and from disk.¶
Functions provide the ability to export and import trained Word2Vec
model to and from disk
without pickling the model. The model can be stored in two files: .json for metadata and .npy for weights.
- class spec2vec.serialization.Word2VecLight(model: dict, weights: Union[ndarray, csr_matrix, csc_matrix])[source]¶
Bases:
object
A lightweight version of
Word2Vec
. The objects of this class follow the interface of the originalWord2Vec
to the point necessary to calculate Spec2Vec scores. The model cannot be used for further training.- __init__(model: dict, weights: Union[ndarray, csr_matrix, csc_matrix])[source]¶
- Parameters
model – A dictionary containing the model’s metadata.
weights – A numpy array or a scipy sparse matrix containing the model’s weights.
- spec2vec.serialization.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
model –
Word2Vec
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.import_model(model_file, weights_file) Word2VecLight [source]¶
Read a lightweight version of a
Word2Vec
model from disk.- Parameters
model_file – A path of json file to load the model.
weights_file – A path of .npy file to load the model’s weights.
- Returns
Word2VecLight
– a lightweight version of aWord2Vec