Datasets:
Add some plots
Browse files- .gitignore +0 -1
- assets/full-test.png +3 -0
- assets/full-train.png +3 -0
- scripts/dsbuild.py +56 -0
- scripts/generate_plot.py +31 -0
.gitignore
CHANGED
@@ -4,4 +4,3 @@ original
|
|
4 |
# Generated data
|
5 |
resources/gen
|
6 |
*.pyc
|
7 |
-
scripts
|
|
|
4 |
# Generated data
|
5 |
resources/gen
|
6 |
*.pyc
|
|
assets/full-test.png
ADDED
Git LFS Details
|
assets/full-train.png
ADDED
Git LFS Details
|
scripts/dsbuild.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gzip
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
|
5 |
+
from matplotlib import pyplot as plt
|
6 |
+
|
7 |
+
|
8 |
+
def load_stats(path: str) -> dict:
|
9 |
+
stats: dict = {}
|
10 |
+
for filename in os.listdir(path):
|
11 |
+
file_path: str = os.path.join(path, filename)
|
12 |
+
if os.path.isdir(filename):
|
13 |
+
continue
|
14 |
+
data: dict
|
15 |
+
if filename.endswith('.gz'):
|
16 |
+
with gzip.open(file_path, mode='rt') as file:
|
17 |
+
data = json.loads(file.read())
|
18 |
+
else:
|
19 |
+
with open(file_path, mode='rt') as file:
|
20 |
+
data = json.loads(file.read())
|
21 |
+
print(f'Loaded stats from {file_path}')
|
22 |
+
stats.update(**data)
|
23 |
+
return stats
|
24 |
+
|
25 |
+
|
26 |
+
def stat_filter(stats: dict, deviation_cutoff=(1.0, 0.0), clamp=(200.0, 2048.0), min_messages=4) -> list[dict]:
|
27 |
+
cutoff_threshold: (float, float) = (
|
28 |
+
stats['wordsStdDev'] * deviation_cutoff[0], stats['wordsStdDev'] * deviation_cutoff[1])
|
29 |
+
if cutoff_threshold[1] <= 0:
|
30 |
+
cutoff_threshold = (cutoff_threshold[0], stats['wordsMax'])
|
31 |
+
cutoff_min: float = max(max(clamp[0], cutoff_threshold[0]), stats['wordsMean'] - cutoff_threshold[0])
|
32 |
+
cutoff_max: float = stats['wordsMean'] + cutoff_threshold[1]
|
33 |
+
if clamp[1] > 0:
|
34 |
+
cutoff_max = min(clamp[1], cutoff_max)
|
35 |
+
|
36 |
+
conversations: list[dict] = [v for k, v in stats['conversations'].items() if
|
37 |
+
v['wordsMax'] <= cutoff_max and v['wordsMin'] >= cutoff_min and v[
|
38 |
+
'messagesCount'] >= min_messages]
|
39 |
+
print(
|
40 |
+
f'Min: {cutoff_min:0.0f}\tMax: {cutoff_max:0.0f}\n'
|
41 |
+
f'Clamped from {cutoff_threshold[0]:0.0f}, {cutoff_threshold[1]:0.0f}')
|
42 |
+
print(f'{len(conversations)} conversations')
|
43 |
+
|
44 |
+
return conversations
|
45 |
+
|
46 |
+
|
47 |
+
def build_mean_word_plot(conv_stats: list[float], title: str = 'Conversation Message Mean Words', xlabel: str = 'Mean',
|
48 |
+
ylabel: str = 'Conversations', text: str = '',
|
49 |
+
**kwargs):
|
50 |
+
fig, ax = plt.subplots(figsize=(5, 2.7), layout='constrained')
|
51 |
+
n, bins, patches = ax.hist(conv_stats, density=True,
|
52 |
+
facecolor='C0', alpha=0.75, **kwargs)
|
53 |
+
ax.set_title(title)
|
54 |
+
ax.set_xlabel(xlabel)
|
55 |
+
ax.set_ylabel(ylabel)
|
56 |
+
plt.figtext(0, 0.95, text)
|
scripts/generate_plot.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
|
5 |
+
import dsbuild
|
6 |
+
|
7 |
+
stats_path: list[str] = ['../stats/full/test/', '../stats/full/train']
|
8 |
+
|
9 |
+
|
10 |
+
def __plot_mean_word_counts(path: list[str], show: bool = False, save: bool = False):
|
11 |
+
for p in path:
|
12 |
+
p: str = os.path.normpath(p)
|
13 |
+
split_name: str = p.split(os.sep)[-1]
|
14 |
+
config_name: str = p.split(os.sep)[-2]
|
15 |
+
|
16 |
+
stats: dict = dsbuild.load_stats(p)
|
17 |
+
conversations: list[float] = [conversation['wordsMean'] for _, conversation in stats['conversations'].items()]
|
18 |
+
dsbuild.build_mean_word_plot(conversations, f'Mean Words ({config_name}-{split_name})',
|
19 |
+
text=f'{len(conversations)} total')
|
20 |
+
if save:
|
21 |
+
plt.savefig(f'../assets/{config_name}-{split_name}.png')
|
22 |
+
if show:
|
23 |
+
plt.show()
|
24 |
+
|
25 |
+
|
26 |
+
def main():
|
27 |
+
__plot_mean_word_counts(stats_path, show=True, save=True)
|
28 |
+
|
29 |
+
|
30 |
+
if __name__ == '__main__':
|
31 |
+
main()
|