Model_Memory_and_Popularity / config_json_utils.py
brwillia's picture
Upload folder using huggingface_hub
7ff7aab verified
from pathlib import Path
import json
from collections import Counter
import operator
import numpy as np
import matplotlib.pyplot as plt
from string import ascii_lowercase as alc
from string import ascii_uppercase as auc
# assign directory
directory = 'HFFiles'
arch_list = []
invalid_counter = 0
# iterate over files in directory
files = Path(directory).glob('*.json')
for file in files:
f = open(file)
try:
data = json.load(f)
except:
# print(str(file) + " does not look like valid JSON.")
invalid_counter += 1
continue
try:
for i in data['architectures']:
# print(i)
arch_list.append(i[0])
except:
# print(str(file) + " does not contain architectures key.")
invalid_counter += 1
f.close()
my_dict = Counter(arch_list)
# print(my_dict)
print("\n")
print(str(invalid_counter) + " JSON files are invalid.")
for i in alc:
del my_dict[i]
for i in auc:
del my_dict[i]
causal_dict = {k:v for (k,v) in my_dict.items() if "Causal" in k}
sorted_causal_dict = dict(sorted(causal_dict.items(),key=operator.itemgetter(1),reverse=True))
sorted_causal_dict = {key:val for key, val in sorted_causal_dict.items() if val != 1}
print(sorted_causal_dict)
labels, values = zip(*sorted_causal_dict.items())
indexes = np.arange(len(labels))
width = 1
plt.figure(figsize=(16,9))
plt.bar(indexes, values, width)
plt.xticks(indexes + width * 0.5, labels)
plt.xticks(rotation=90)
plt.show()