-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext_freq_classifier.py
64 lines (54 loc) · 1.95 KB
/
text_freq_classifier.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
In order to see how good GPT-3 classification is, this is a classifier which
I though of in a few seconds, which classifies numbers by taking their first
digit into consideration, and then doing statistics/voting based on it.
Note that, while seemingly only working on pattern matching digits,
this classifier actually implicitly computes some (statistics of)
distances as well.
"""
import json
from collections import defaultdict
from statistics import mean
experiment_names = [f'2d_class_type_{x}_rstate_' for x in range(1,10)]
results = dict()
rstates = ['42', '55', '93']
with open('experiments_log.json', 'r') as file:
experiments = json.loads(file.read())
accuracies2 = []
for name in experiment_names:
accuracies = []
for rstate in rstates:
experiment = experiments[name + rstate]
train = experiment['input_train']
labels = experiment['output_train']
train_reduced = []
for it in train:
x, y = it
x, y = x // 10, y // 10
train_reduced.append([x,y])
test_reduced = []
test = experiment['input_test']
for it in test:
x, y = it
x, y = x // 10, y // 10
test_reduced.append([x,y])
predictions = []
for it in test_reduced:
class_ = defaultdict(int)
x, y = it
for ix, itt in enumerate(train_reduced):
xx, yy = itt
if xx == x:
class_[labels[ix]] += 1
if yy == y:
class_[labels[ix]] +=1
if class_[0] > class_[1]:
predictions.append(0)
else:
predictions.append(1)
accurate = [1 if x==y else 0
for x, y in zip(predictions, experiment['output_test'])]
accuracies.append(sum(accurate)/len(accurate))
print(name, mean(accuracies))
accuracies2.append(mean(accuracies))
print(mean(accuracies2))