This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from graphviz import Digraph | |
| import torch | |
| from torch.autograd import Variable, Function | |
| def iter_graph(root, callback): | |
| queue = [root] | |
| seen = set() | |
| while queue: | |
| fn = queue.pop() | |
| if fn in seen: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re, collections | |
| def get_stats(vocab): | |
| pairs = collections.defaultdict(int) | |
| for word, freq in vocab.items(): | |
| symbols = word.split() | |
| for i in range(len(symbols)-1): | |
| pairs[symbols[i],symbols[i+1]] += freq | |
| return pairs |
OlderNewer