def __setitem__(self, tokens, new_embedding):
if not isinstance(tokens, (list, tuple)):<EOL><INDENT>tokens = [tokens]<EOL><DEDENT>if ((self.allow_extend or all(t in self.token_to_idx for t in tokens))<EOL>and self._idx_to_vec is None):<EOL><INDENT>assert C.UNK_IDX == <NUM_LIT:0><EOL>self._idx_to_vec = self._init_unknown_vec(<EOL>shape=(<NUM_LIT:1>, new_embedding.shape[-<NUM_LIT:1>]))<EOL><DEDENT>tokens = self._check_vector_update(tokens, new_embedding)<EOL>if self.allow_extend:<EOL><INDENT>for token in filter(lambda t: t not in self._token_to_idx, tokens):<EOL><INDENT>idx = len(self._token_to_idx)<EOL>self._token_to_idx[token] = idx<EOL>self._idx_to_token.append(token)<EOL><DEDENT>num_extended = len(self._token_to_idx) - self.idx_to_vec.shape[<NUM_LIT:0>]<EOL>if num_extended == <NUM_LIT:1>:<EOL><INDENT>warnings.warn(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>idx_to_vec = nd.zeros(shape=(len(self._token_to_idx),<EOL>self.idx_to_vec.shape[<NUM_LIT:1>]))<EOL>idx_to_vec[:self.idx_to_vec.shape[<NUM_LIT:0>]] = self._idx_to_vec<EOL>self._idx_to_vec = idx_to_vec<EOL><DEDENT>indices = []<EOL>for token in tokens:<EOL><INDENT>if token in self._token_to_idx:<EOL><INDENT>indices.append(self._token_to_idx[token])<EOL><DEDENT>else:<EOL><INDENT>if self.unknown_token:<EOL><INDENT>raise KeyError(('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>').format(token, self._idx_to_token[C.UNK_IDX]))<EOL><DEDENT>else:<EOL><INDENT>raise KeyError(('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>').format(token))<EOL><DEDENT><DEDENT><DEDENT>self._idx_to_vec[nd.array(indices)] = new_embedding<EOL>
Updates embedding vectors for tokens.

        If self.allow_extend is True, vectors for previously unknown tokens can be introduced.

        Parameters
        ----------
        tokens : hashable object or a list or tuple of hashable objects
            A token or a list of tokens whose embedding vector are to be updated.
        new_embedding : mxnet.ndarray.NDArray
            An NDArray to be assigned to the embedding vectors of `tokens`. Its length must be equal
            to the number of `tokens` and its width must be equal to the dimension of embedding of
            the glossary. If `tokens` is a singleton, it must be 1-D or 2-D. If `tokens` is a list
            of multiple strings, it must be 2-D.