feat: model --> ready to test train

This commit is contained in:
Robin Meersman 2025-11-08 20:55:05 +01:00
parent 63d1b6f5ae
commit b58682cb49
8 changed files with 382 additions and 17 deletions

20
CNN-model/utils.py Normal file
View file

@ -0,0 +1,20 @@
import torch
from torch.utils.data import TensorDataset
import matplotlib.pyplot as plt
def make_context_pairs(data: bytes, context_length: int) -> TensorDataset:
data = torch.tensor(list(data), dtype=torch.long)
sample_count = data.shape[0] - context_length
x = data.unfold(0, context_length, 1)[:sample_count]
y = data[context_length:]
return TensorDataset(x, y)
def print_distribution(from_to: tuple[int, int], probabilities: list[float]):
plt.hist(range(from_to[0], from_to[1]), weights=probabilities)
plt.show()
def load_data(path: str) -> bytes:
with open(path, "rb") as f:
return f.read()