import json import numpy as np import sys def save_json(data, filepath): with open(filepath, "w") as f: json.dump(data, f) def save_json_pretty(data, filepath): with open(filepath, "w") as f: f.write(json.dumps(data, indent=4, sort_keys=True)) def get_ngrams(words_pred, unigrams, bigrams, trigrams, fourgrams): # N=1 for w in words_pred: if w not in unigrams: unigrams[w] = 0 unigrams[w] += 1 # N=2 for i, w in enumerate(words_pred): if i