Skip to content

Instantly share code, notes, and snippets.

@kindleton
Created March 1, 2016 23:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kindleton/be141f9eacd3cb38c3b2 to your computer and use it in GitHub Desktop.
Save kindleton/be141f9eacd3cb38c3b2 to your computer and use it in GitHub Desktop.
Calculate accuracy for CRF++ output file
import sys
f1 = open(sys.argv[1])
count = 0
true = 0
false = 0
sentences = 0
for line in f1:
if line == '\n' or line.split()==[]:
sentences+=1
continue
count = count + 1
x = line.strip().split()
if(x[-1]==x[-2]):
true=true+1
else:
false = false+1
print '#true', '#false', '#total_words', '#sentences'
print true, false, count, sentences
print 'accuracy = ', (100.0*true/count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment