-
Notifications
You must be signed in to change notification settings - Fork 19
/
avg.py
40 lines (32 loc) · 999 Bytes
/
avg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
__author__ = 'rtownsend'
from util import list_files_with_extension
from tag import IDENT
import matplotlib.pyplot as plt
import pickle
import logging
import numpy as np
if __name__ == "__main__":
logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.DEBUG)
# Data
X = [[] for _ in range(len(IDENT))]
labels = [x for x in IDENT]
for f in list_files_with_extension("Data", "pkl"):
logging.info("Loading %s...", f)
with open(f, 'r') as fin:
data = pickle.load(fin)
for t in data:
X[t.tag].append(len(t.word))
# Plot
plt.figure()
for label, x in zip(labels, X):
if len(x) == 0:
continue
print x
plt.hist(x, bins=20, histtype='stepfilled', label=label)
plt.title('POS-tag/length histogram')
plt.xlabel('Length')
plt.ylabel('probability')
plt.legend()
plt.show()