@classmethod<EOL><INDENT>def deserialize(cls, file_path, **kwargs):<DEDENT>
<EOL>npz_dict = np.load(file_path, allow_pickle=True)<EOL>unknown_token = npz_dict['<STR_LIT>']<EOL>if not unknown_token:<EOL><INDENT>unknown_token = None<EOL><DEDENT>else:<EOL><INDENT>if isinstance(unknown_token, np.ndarray):<EOL><INDENT>if unknown_token.dtype.kind == '<STR_LIT:S>':<EOL><INDENT>unknown_token = unknown_token.tobytes().decode()<EOL><DEDENT>else:<EOL><INDENT>unknown_token = str(unknown_token)<EOL><DEDENT><DEDENT><DEDENT>idx_to_token = npz_dict['<STR_LIT>'].tolist()<EOL>idx_to_vec = nd.array(npz_dict['<STR_LIT>'])<EOL>embedding = cls(unknown_token=unknown_token, **kwargs)<EOL>if unknown_token:<EOL><INDENT>assert unknown_token == idx_to_token[C.UNK_IDX]<EOL>embedding._token_to_idx = DefaultLookupDict(C.UNK_IDX)<EOL><DEDENT>else:<EOL><INDENT>embedding._token_to_idx = {}<EOL><DEDENT>embedding._idx_to_token = idx_to_token<EOL>embedding._idx_to_vec = idx_to_vec<EOL>embedding._token_to_idx.update((token, idx) for idx, token in enumerate(idx_to_token))<EOL>return embedding<EOL>
Create a new TokenEmbedding from a serialized one.

        TokenEmbedding is serialized by converting the list of tokens, the
        array of word embeddings and other metadata to numpy arrays, saving all
        in a single (optionally compressed) Zipfile. See
        https://docs.scipy.org/doc/numpy-1.14.2/neps/npy-format.html for more
        information on the format.


        Parameters
        ----------
        file_path : str or file
            The path to a file that holds the serialized TokenEmbedding.
        kwargs : dict
            Keyword arguments are passed to the TokenEmbedding initializer.
            Useful for attaching unknown_lookup.