deeplotx 0.2.18__py3-none-any.whl → 0.2.20__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- deeplotx/nn/base_neural_network.py +4 -4
- deeplotx/trainer/text_binary_classification_trainer.py +3 -10
- {deeplotx-0.2.18.dist-info → deeplotx-0.2.20.dist-info}/METADATA +1 -1
- {deeplotx-0.2.18.dist-info → deeplotx-0.2.20.dist-info}/RECORD +7 -7
- {deeplotx-0.2.18.dist-info → deeplotx-0.2.20.dist-info}/WHEEL +0 -0
- {deeplotx-0.2.18.dist-info → deeplotx-0.2.20.dist-info}/licenses/LICENSE +0 -0
- {deeplotx-0.2.18.dist-info → deeplotx-0.2.20.dist-info}/top_level.txt +0 -0
@@ -23,10 +23,10 @@ class BaseNeuralNetwork(nn.Module):
|
|
23
23
|
for param in self.parameters():
|
24
24
|
l2_reg += (torch.pow(param, exponent=2.)).sum()
|
25
25
|
return l2_reg
|
26
|
-
return _lambda * _l2()
|
26
|
+
return _lambda * _l2() / 2.
|
27
27
|
|
28
28
|
def elastic_net(self, alpha: float = 1e-4, rho: float = 0.5) -> torch.Tensor:
|
29
|
-
return alpha * rho * self.l1(_lambda=1.) +
|
29
|
+
return alpha * (rho * self.l1(_lambda=1.) + (1 - rho) * self.l2(_lambda=1.))
|
30
30
|
|
31
31
|
def forward(self, x) -> torch.Tensor: ...
|
32
32
|
|
@@ -39,9 +39,9 @@ class BaseNeuralNetwork(nn.Module):
|
|
39
39
|
return res
|
40
40
|
|
41
41
|
def save(self):
|
42
|
-
torch.save(self.state_dict(), f'{self._model_name}.deeplotx
|
42
|
+
torch.save(self.state_dict(), f'{self._model_name}.deeplotx')
|
43
43
|
return self
|
44
44
|
|
45
45
|
def load(self):
|
46
|
-
self.load_state_dict(torch.load(f'{self._model_name}.deeplotx
|
46
|
+
self.load_state_dict(torch.load(f'{self._model_name}.deeplotx'))
|
47
47
|
return self
|
@@ -21,8 +21,7 @@ class TextBinaryClassifierTrainer(BaseTrainer):
|
|
21
21
|
def train(self, positive_texts: list[str], negative_texts: list[str],
|
22
22
|
num_epochs: int, learning_rate: float = 2e-5, balancing_dataset: bool = True,
|
23
23
|
train_loss_threshold: float = 0.0, valid_loss_threshold: float = 0.0,
|
24
|
-
alpha: float = 1e-4, rho: float = 0.2
|
25
|
-
lambda_l1: float = 1e-4, lambda_l2: float = 1e-4) -> LogisticRegression:
|
24
|
+
alpha: float = 1e-4, rho: float = 0.2) -> LogisticRegression:
|
26
25
|
if balancing_dataset:
|
27
26
|
min_length = min(len(positive_texts), len(negative_texts))
|
28
27
|
positive_texts = positive_texts[:min_length]
|
@@ -52,10 +51,7 @@ class TextBinaryClassifierTrainer(BaseTrainer):
|
|
52
51
|
total_loss = 0.0
|
53
52
|
for batch_texts, batch_labels in train_loader:
|
54
53
|
outputs = self.model.forward(batch_texts)
|
55
|
-
loss = loss_function(outputs, batch_labels) + self.model.elastic_net(
|
56
|
-
alpha=alpha, rho=rho,
|
57
|
-
lambda_l1=lambda_l1, lambda_l2=lambda_l2
|
58
|
-
)
|
54
|
+
loss = loss_function(outputs, batch_labels) + self.model.elastic_net(alpha=alpha, rho=rho)
|
59
55
|
optimizer.zero_grad()
|
60
56
|
loss.backward()
|
61
57
|
optimizer.step()
|
@@ -66,10 +62,7 @@ class TextBinaryClassifierTrainer(BaseTrainer):
|
|
66
62
|
with torch.no_grad():
|
67
63
|
self.model.eval()
|
68
64
|
outputs = self.model.forward(batch_texts)
|
69
|
-
loss = loss_function(outputs, batch_labels) + self.model.elastic_net(
|
70
|
-
alpha=alpha, rho=rho,
|
71
|
-
lambda_l1=lambda_l1, lambda_l2=lambda_l2
|
72
|
-
)
|
65
|
+
loss = loss_function(outputs, batch_labels) + self.model.elastic_net(alpha=alpha, rho=rho)
|
73
66
|
total_valid_loss += loss.item()
|
74
67
|
self.model.train()
|
75
68
|
logger.debug(f"Epoch {epoch + 1}/{num_epochs} | "
|
@@ -3,18 +3,18 @@ deeplotx/encoder/__init__.py,sha256=x7k8IE0FXvDl7kCJGWPsetOHFdvNCiCXHbYOdvo7_JQ,
|
|
3
3
|
deeplotx/encoder/bert_encoder.py,sha256=rdT8YgZzvRoqYqtzPW95ilagSQTAQgUl7mMVetGKxCY,1822
|
4
4
|
deeplotx/encoder/long_text_encoder.py,sha256=yEEtTVZYHJ0W3OSbh7BHm6xI33nJmVYlSrgD5RVcJLY,2967
|
5
5
|
deeplotx/nn/__init__.py,sha256=9gh8rhKqVWtJyvryU_wHPTLEQIorwOBhAQRc0DtNamM,153
|
6
|
-
deeplotx/nn/base_neural_network.py,sha256=
|
6
|
+
deeplotx/nn/base_neural_network.py,sha256=MXuID5bagdHyrFOkoybW1oiXAY2d4FGnzZoR37LZfUI,1566
|
7
7
|
deeplotx/nn/linear_regression.py,sha256=D4mEWVOq6q1Fm2otm57rgZ_E06HJLZBV5k636PprAf4,1520
|
8
8
|
deeplotx/nn/logistic_regression.py,sha256=QAtZp2oyqOW8-1pJWVcahsSM83bzfA68EHObg-wSHHY,463
|
9
9
|
deeplotx/nn/softmax_regression.py,sha256=eUn3mVNlye9ewVdw3McPHZuKbUvvaamsUgFIJMVMgBU,487
|
10
10
|
deeplotx/trainer/__init__.py,sha256=Fl5DR9UecQc5VtBcczU9sx_HtPNoFohpuELOh-Jrsks,77
|
11
11
|
deeplotx/trainer/base_trainer.py,sha256=z0MeAT-rRYmjeBXt0ckt7J1itYArR0Cx02wHesXUoZE,385
|
12
|
-
deeplotx/trainer/text_binary_classification_trainer.py,sha256=
|
12
|
+
deeplotx/trainer/text_binary_classification_trainer.py,sha256=5O-5dwVMCj5EDX9gjJwCA468OR4UozJ7V8b-JxeUB0s,4080
|
13
13
|
deeplotx/util/__init__.py,sha256=JxqAK_WOOHcYVSTHBT1-WuBwWrPEVDTV3titeVWvNUM,74
|
14
14
|
deeplotx/util/hash.py,sha256=wwsC6kOQvbpuvwKsNQOARd78_wePmW9i3oaUuXRUnpc,352
|
15
15
|
deeplotx/util/read_file.py,sha256=ptzouvEQeeW8KU5BrWNJlXw-vFXVrpS9SkAUxsu6A8A,612
|
16
|
-
deeplotx-0.2.
|
17
|
-
deeplotx-0.2.
|
18
|
-
deeplotx-0.2.
|
19
|
-
deeplotx-0.2.
|
20
|
-
deeplotx-0.2.
|
16
|
+
deeplotx-0.2.20.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
|
17
|
+
deeplotx-0.2.20.dist-info/METADATA,sha256=NQgRWucDSAI4awAJNf9984IujFRo9PurR1qrqpmWIzA,1573
|
18
|
+
deeplotx-0.2.20.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
19
|
+
deeplotx-0.2.20.dist-info/top_level.txt,sha256=hKg4pVDXZ-WWxkRfJFczRIll1Sv7VyfKCmzHLXbuh1U,9
|
20
|
+
deeplotx-0.2.20.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|