def _load_embedding_txt(self, pretrained_file_path, elem_delim, encoding='<STR_LIT:utf8>'):
vec_len = None<EOL>all_elems = []<EOL>tokens = set()<EOL>loaded_unknown_vec = None<EOL>with io.open(pretrained_file_path, '<STR_LIT:rb>') as f:<EOL><INDENT>for line_num, line in enumerate(f):<EOL><INDENT>try:<EOL><INDENT>line = line.decode(encoding)<EOL><DEDENT>except ValueError:<EOL><INDENT>warnings.warn('<STR_LIT>'<EOL>.format(line_num, pretrained_file_path))<EOL>continue<EOL><DEDENT>elems = line.rstrip().split(elem_delim)<EOL>assert len(elems) > <NUM_LIT:1>, '<STR_LIT>'.format(<EOL>line_num, pretrained_file_path)<EOL>token, elems = elems[<NUM_LIT:0>], [float(i) for i in elems[<NUM_LIT:1>:]]<EOL>if token == self.unknown_token and loaded_unknown_vec is None:<EOL><INDENT>loaded_unknown_vec = elems<EOL>tokens.add(self.unknown_token)<EOL><DEDENT>elif token in tokens:<EOL><INDENT>warnings.warn('<STR_LIT>'<EOL>'<STR_LIT>'.format(line_num, pretrained_file_path,<EOL>token))<EOL><DEDENT>elif len(elems) == <NUM_LIT:1> and line_num == <NUM_LIT:0>:<EOL><INDENT>warnings.warn('<STR_LIT>'<EOL>.format(line_num, pretrained_file_path))<EOL><DEDENT>else:<EOL><INDENT>if not vec_len:<EOL><INDENT>vec_len = len(elems)<EOL>if self.unknown_token:<EOL><INDENT>all_elems.extend([<NUM_LIT:0>] * vec_len)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>assert len(elems) == vec_len,'<STR_LIT>''<STR_LIT>'.format(line_num,<EOL>pretrained_file_path,<EOL>token, vec_len, len(elems))<EOL><DEDENT>all_elems.extend(elems)<EOL>self._idx_to_token.append(token)<EOL>self._token_to_idx[token] = len(self._idx_to_token) - <NUM_LIT:1><EOL>tokens.add(token)<EOL><DEDENT><DEDENT><DEDENT>self._idx_to_vec = nd.array(all_elems).reshape((-<NUM_LIT:1>, vec_len))<EOL>if self.unknown_token:<EOL><INDENT>if loaded_unknown_vec is None:<EOL><INDENT>self._idx_to_vec[C.UNK_IDX] = self._init_unknown_vec(shape=vec_len)<EOL><DEDENT>else:<EOL><INDENT>self._idx_to_vec[C.UNK_IDX] = nd.array(loaded_unknown_vec)<EOL><DEDENT><DEDENT>
Load embedding vectors from a pre-trained token embedding file.

        For every unknown token, if its representation `self.unknown_token` is encountered in the
        pre-trained token embedding file, index 0 of `self.idx_to_vec` maps to the pre-trained token
        embedding vector loaded from the file; otherwise, index 0 of `self.idx_to_vec` maps to the
        text embedding vector initialized by `self._init_unknown_vec`.

        If a token is encountered multiple times in the pre-trained text embedding file, only the
        first-encountered token embedding vector will be loaded and the rest will be skipped.