courses/machine_learning/deepdive/09_sequence/word2vec/word2vec.py
def eval(self):
    """Evaluate analogy questions and reports accuracy."""

    # How many questions we get right at precision@1.
    correct = 0

    try:
      total = self._analogy_questions.shape[0]
    except AttributeError as e:
      raise AttributeError("Need to read analogy questions.")

    start = 0
    while start < total:
      limit = start + 2500
      sub = self._analogy_questions[start:limit, :]
      idx = self._predict(sub)
      start = limit
      for question in xrange(sub.shape[0]):
        for j in xrange(4):
          if idx[question, j] == sub[question, 3]:
            # Bingo! We predicted correctly. E.g., [italy, rome, france, paris].
            correct += 1
            break
          elif idx[question, j] in sub[question, :3]:
            # We need to skip words already in the question.
            continue
          else:
            # The correct label is not the precision@1
            break
    print()
    print("Eval %4d/%d accuracy = %4.1f%%" % (correct, total,
                                              correct * 100.0 / total))
Evaluate analogy questions and reports accuracy.
Evaluate analogy questions and reports accuracy.
Evaluate analogy questions and reports accuracy .
def eval(self):
    correct = 0
    try:
      total = self._analogy_questions.shape[0]
    except AttributeError as e:
      raise AttributeError("Need to read analogy questions.")
    start = 0
    while start < total:
      limit = start + 2500
      sub = self._analogy_questions[start:limit, :]
      idx = self._predict(sub)
      start = limit
      for question in xrange(sub.shape[0]):
        for j in xrange(4):
          if idx[question, j] == sub[question, 3]:
            correct += 1
            break
          elif idx[question, j] in sub[question, :3]:
            continue
          else:
            break
    print()
    print("Eval %4d/%d accuracy = %4.1f%%" % (correct, total,
                                              correct * 100.0 / total))
def eval ( self ) : correct = 0 try : total = self . _analogy_questions . shape [ 0 ] except AttributeError as e : raise AttributeError ( "Need to read analogy questions." ) start = 0 while start < total : limit = start + 2500 sub = self . _analogy_questions [ start : limit , : ] idx = self . _predict ( sub ) start = limit for question in xrange ( sub . shape [ 0 ] ) : for j in xrange ( 4 ) : if idx [ question , j ] == sub [ question , 3 ] : correct += 1 break elif idx [ question , j ] in sub [ question , : 3 ] : continue else : break print ( ) print ( "Eval %4d/%d accuracy = %4.1f%%" % ( correct , total , correct * 100.0 / total ) )
Evaluate analogy questions and reports accuracy.
Evaluate analogy questions and reports accuracy .
"""Evaluate analogy questions and reports accuracy.""" # How many questions we get right at precision@1. # Bingo! We predicted correctly. E.g., [italy, rome, france, paris]. # We need to skip words already in the question. # The correct label is not the precision@1
self