def read_analogies_file(eval_file='questions-words.txt', word2id={}):
 questions = []
 questions_skipped = 0
 with open(eval_file, 'rb') as analogy_f:
  for line in analogy_f:
   if line.startswith(':'):
    continue
   words = line.strip().lower().split(' ')
   ids = [word2id.get(w.strip()) for w in words]
   if ((None in ids) or (len(ids) != 4)):
    questions_skipped += 1
   else:
    questions.append(np.array(ids))
 print ('Eval analogy file: ', eval_file)
 print ('Questions: ', len(questions))
 print ('Skipped: ', questions_skipped)
 analogy_questions = np.array(questions, dtype=np.int32)
 return analogy_questions

def read_analogies_file ( eval_file = 'questions-words.txt' , word2id = { } ) : questions = [ ] questions_skipped = 0 with open ( eval_file , 'rb' ) as analogy_f : for line in analogy_f : if line . startswith ( ':' ) : continue words = line . strip ( ) . lower ( ) . split ( ' ' ) ids = [ word2id . get ( w . strip ( ) ) for w in words ] if ( ( None in ids ) or ( len ( ids ) != 4 ) ) : questions_skipped += 1 else : questions . append ( np . array ( ids ) ) print ( 'Eval analogy file: ' , eval_file ) print ( 'Questions: ' , len ( questions ) ) print ( 'Skipped: ' , questions_skipped ) analogy_questions = np . array ( questions , dtype = np . int32 ) return analogy_questions
reads through an analogy question file .