def load_embedding_from_path(args):
if args.embedding_path.endswith('<STR_LIT>'):<EOL><INDENT>with utils.print_time('<STR_LIT>'):<EOL><INDENT>model =nlp.model.train.FasttextEmbeddingModel.load_fasttext_format(<EOL>args.embedding_path)<EOL><DEDENT>idx_to_token = sorted(model._token_to_idx, key=model._token_to_idx.get)<EOL>embedding = nlp.embedding.TokenEmbedding(<EOL>unknown_token=None, unknown_lookup=model, allow_extend=True)<EOL>if not args.analogy_datasets:<EOL><INDENT>idx_to_token = []<EOL><DEDENT>elif args.analogy_datasets and args.analogy_max_vocab_size:<EOL><INDENT>idx_to_token = idx_to_token[:args.analogy_max_vocab_size]<EOL><DEDENT>embedding['<STR_LIT>'] = mx.nd.zeros(model.weight.shape[<NUM_LIT:1>])<EOL>if idx_to_token:<EOL><INDENT>with utils.print_time('<STR_LIT>'<EOL>'<STR_LIT>'.format(len(idx_to_token))):<EOL><INDENT>embedding[idx_to_token] = model[idx_to_token]<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>embedding = nlp.embedding.TokenEmbedding.from_file(args.embedding_path)<EOL><DEDENT>return embedding<EOL>
Load a TokenEmbedding.