def evaluate(args, embedding, vocab, global_step, eval_analogy=False):
if '<STR_LIT>' not in globals():<EOL><INDENT>global eval_tokens<EOL>eval_tokens_set = evaluation.get_tokens_in_evaluation_datasets(args)<EOL>if not args.no_eval_analogy:<EOL><INDENT>eval_tokens_set.update(vocab.idx_to_token)<EOL><DEDENT>if not args.ngram_buckets:<EOL><INDENT>eval_tokens_set = filter(lambda t: t in vocab, eval_tokens_set)<EOL><DEDENT>eval_tokens = list(eval_tokens_set)<EOL><DEDENT>if not os.path.isdir(args.logdir):<EOL><INDENT>os.makedirs(args.logdir)<EOL><DEDENT>context = get_context(args)<EOL>mx.nd.waitall()<EOL>token_embedding = nlp.embedding.TokenEmbedding(unknown_token=None,<EOL>allow_extend=True)<EOL>token_embedding[eval_tokens] = embedding[eval_tokens]<EOL>results = evaluation.evaluate_similarity(<EOL>args, token_embedding, context[<NUM_LIT:0>], logfile=os.path.join(<EOL>args.logdir, '<STR_LIT>'), global_step=global_step)<EOL>if eval_analogy:<EOL><INDENT>assert not args.no_eval_analogy<EOL>results += evaluation.evaluate_analogy(<EOL>args, token_embedding, context[<NUM_LIT:0>], logfile=os.path.join(<EOL>args.logdir, '<STR_LIT>'))<EOL><DEDENT>return results<EOL>
Evaluation helper