In [18]:
import json
from collections import Counter

In [19]:
with open('runs/1500578799/prediction.json') as f:
    results = json.load(f)

In [24]:
count = Counter(result['category'] for result in results)
final_result = dict(count)
replace = { -1 : 'unknown', 0 : 'law', 1 : 'social-and-behavioral-sciences', 2 : 'arts-and-humanities', 3 : 'education', 4 : 'medicine-and-health-sciences', \
     5 : 'life-sciences', 6 : 'physical-sciences-and-mathematics', 7 : 'engineering', 8 : 'business', 9 : 'architecture'}

for old_key in range(-1, 10):
    final_result[replace[old_key]] = final_result.pop(old_key)

In [26]:
with open('final_result.json', 'w') as f:
    json.dump(final_result, f)

In [27]:
print(final_result)


{'unknown': 464, 'law': 257, 'social-and-behavioral-sciences': 273, 'arts-and-humanities': 1145, 'education': 712, 'medicine-and-health-sciences': 990, 'life-sciences': 540, 'physical-sciences-and-mathematics': 1777, 'engineering': 266, 'business': 897, 'architecture': 62}