Commit
•
a982981
1
Parent(s):
1832ae9
:construction: wip
Browse files
model.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from typing import Tuple
|
2 |
import torch
|
3 |
from torch import nn
|
@@ -59,7 +60,23 @@ class Autoencoder(nn.Module):
|
|
59 |
|
60 |
|
61 |
class MessageModel:
|
|
|
62 |
def __init__(self, msg='hello, world'):
|
63 |
self.msg = msg
|
|
|
64 |
def __call__(self):
|
65 |
print(self.msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
from typing import Tuple
|
3 |
import torch
|
4 |
from torch import nn
|
|
|
60 |
|
61 |
|
62 |
class MessageModel:
|
63 |
+
|
64 |
def __init__(self, msg='hello, world'):
|
65 |
self.msg = msg
|
66 |
+
|
67 |
def __call__(self):
|
68 |
print(self.msg)
|
69 |
+
|
70 |
+
@classmethod
|
71 |
+
def from_pretrained(cls, path):
|
72 |
+
path = Path(path)
|
73 |
+
msg_file_path = path / 'message.txt'
|
74 |
+
assert msg_file_path.exists()
|
75 |
+
msg = msg_file_path.read_text()
|
76 |
+
return cls(msg)
|
77 |
+
|
78 |
+
def save_pretrained(self, path):
|
79 |
+
path = Path(path)
|
80 |
+
path.mkdir(exist_ok=True, parents=True)
|
81 |
+
msg_file_path = path / 'message.txt'
|
82 |
+
msg_file_path.write_text(self.msg)
|