deeplotx 0.3.2__py3-none-any.whl → 0.4.2__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/__init__.py CHANGED
@@ -4,7 +4,13 @@ import os
4
4
  __ROOT__ = os.path.dirname(os.path.abspath(__file__))
5
5
 
6
6
  from .encoder import BertEncoder, LongTextEncoder, LongformerEncoder
7
- from .nn import LinearRegression, LogisticRegression, SoftmaxRegression
7
+ from .nn import (
8
+ LinearRegression,
9
+ LogisticRegression,
10
+ SoftmaxRegression,
11
+ RecursiveSequential,
12
+ AutoRegression
13
+ )
8
14
  from .trainer import TextBinaryClassifierTrainer
9
15
 
10
16
  __AUTHOR__ = '吴子豪 / Vortez Wohl'
deeplotx/nn/__init__.py CHANGED
@@ -1,3 +1,5 @@
1
1
  from .linear_regression import LinearRegression
2
2
  from .logistic_regression import LogisticRegression
3
3
  from .softmax_regression import SoftmaxRegression
4
+ from .recursive_sequential import RecursiveSequential
5
+ from .auto_regression import AutoRegression
@@ -0,0 +1,9 @@
1
+ from deeplotx.nn import RecursiveSequential
2
+
3
+
4
+ class AutoRegression(RecursiveSequential):
5
+ def __init__(self, feature_dim: int, hidden_dim: int | None = None,
6
+ recursive_layers: int = 2, model_name: str | None = None):
7
+ super().__init__(input_dim=feature_dim, output_dim=feature_dim,
8
+ hidden_dim=hidden_dim, recursive_layers=recursive_layers,
9
+ model_name=model_name)
@@ -31,7 +31,7 @@ class BaseNeuralNetwork(nn.Module):
31
31
  return alpha * (rho * self.l1(_lambda=1.) + (1 - rho) * self.l2(_lambda=1.))
32
32
 
33
33
  @abstractmethod
34
- def forward(self, x) -> torch.Tensor: ...
34
+ def forward(self, *args, **kwargs) -> torch.Tensor: ...
35
35
 
36
36
  def predict(self, x) -> torch.Tensor:
37
37
  __train = self.training
@@ -0,0 +1,30 @@
1
+ from typing_extensions import override
2
+
3
+ import torch
4
+ from torch import nn
5
+
6
+ from deeplotx.nn.base_neural_network import BaseNeuralNetwork
7
+ from deeplotx.nn import LinearRegression
8
+
9
+
10
+ class RecursiveSequential(BaseNeuralNetwork):
11
+ def __init__(self, input_dim: int, output_dim: int,
12
+ hidden_dim: int | None = None, recursive_layers: int = 2,
13
+ model_name: str | None = None):
14
+ super().__init__(model_name=model_name)
15
+ if hidden_dim is None:
16
+ hidden_dim = input_dim
17
+ self.lstm = nn.LSTM(input_size=input_dim, hidden_size=hidden_dim,
18
+ num_layers=recursive_layers, batch_first=True,
19
+ bias=True, bidirectional=True)
20
+ self.regressive_head = LinearRegression(input_dim=hidden_dim * 2, output_dim=output_dim)
21
+
22
+ def initial_state(self, batch_size: int = 1) -> tuple[torch.Tensor, torch.Tensor]:
23
+ zeros = torch.zeros(self.lstm.num_layers * 2, batch_size, self.lstm.hidden_size)
24
+ return zeros, zeros
25
+
26
+ @override
27
+ def forward(self, x, state: tuple[torch.Tensor, torch.Tensor]) -> tuple[torch.Tensor, tuple[torch.Tensor, torch.Tensor]]:
28
+ x, (hidden_state, cell_state) = self.lstm(x, state)
29
+ x = self.regressive_head(x[:, -1, :])
30
+ return x, (hidden_state, cell_state)
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deeplotx
3
- Version: 0.3.2
4
- Summary: Easy-2-use long text classifier trainers.
3
+ Version: 0.4.2
4
+ Summary: Easy-2-use long text NLP toolkit.
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
7
7
  License-File: LICENSE
@@ -14,7 +14,7 @@ Requires-Dist: transformers>=4.51.3
14
14
  Requires-Dist: typing-extensions>=4.13.2
15
15
  Dynamic: license-file
16
16
 
17
- # DeepLoTX: Easy2UseLongTextClassifierTrainers
17
+ # DeepLoTX: Easy2UseLongTextNLPToolkit
18
18
 
19
19
  ## Installation
20
20
 
@@ -38,7 +38,7 @@ Dynamic: license-file
38
38
 
39
39
  ## Quick Start
40
40
 
41
- To train a binary classifier for text files:
41
+ To train a binary classifier from text files:
42
42
 
43
43
  ```python
44
44
  from deeplotx.util import get_files, read_file
@@ -1,12 +1,14 @@
1
- deeplotx/__init__.py,sha256=C6N717chqnk3jqh9nuh9oM5hPldX9mCusCn-LqGWJJg,935
1
+ deeplotx/__init__.py,sha256=wMN_AI14V-0BPbQghYpvd2y7eUGfhr7jKTTuur-5Upg,1002
2
2
  deeplotx/encoder/__init__.py,sha256=EM-xrTsHoGaiiFpj-iFAxilMHXC_sQKWYrcq1qCnI3U,138
3
3
  deeplotx/encoder/bert_encoder.py,sha256=A-B7Gj94xv6UhvsFTBH7tnkAdGHRhfUZA2QjSnTKB6c,1970
4
4
  deeplotx/encoder/long_text_encoder.py,sha256=V6VxaHW6bMMaZHgU1UZ8n19UfSIV2f2sarWXquiFffQ,3018
5
5
  deeplotx/encoder/longformer_encoder.py,sha256=mZpC5TrGHQo98-ydGtVQQ9KRHgCGl1sRoxcQs7r4SSo,1409
6
- deeplotx/nn/__init__.py,sha256=9gh8rhKqVWtJyvryU_wHPTLEQIorwOBhAQRc0DtNamM,153
7
- deeplotx/nn/base_neural_network.py,sha256=Rkwu58mXXcuusf-59yLX89MywQx-EvTsSXOvlzUptRE,1621
6
+ deeplotx/nn/__init__.py,sha256=oQ-vYXyuaGelfCOs2im_gZXAiiBlCCVXh1uw9yjvRMs,253
7
+ deeplotx/nn/auto_regression.py,sha256=o82C9TREZbhGdj2knSVGTXhjJne0LGEqc7BllByJJWE,449
8
+ deeplotx/nn/base_neural_network.py,sha256=xWKG4FX6Jzdlrfc1HOW1aO9uh0Af3D-dB5Jl7eCxsAk,1635
8
9
  deeplotx/nn/linear_regression.py,sha256=D4mEWVOq6q1Fm2otm57rgZ_E06HJLZBV5k636PprAf4,1520
9
10
  deeplotx/nn/logistic_regression.py,sha256=QAtZp2oyqOW8-1pJWVcahsSM83bzfA68EHObg-wSHHY,463
11
+ deeplotx/nn/recursive_sequential.py,sha256=Nj5B4iPAq7SUCKepextZbHWvGPxHo3w9UXEsEg_nFi4,1352
10
12
  deeplotx/nn/softmax_regression.py,sha256=eUn3mVNlye9ewVdw3McPHZuKbUvvaamsUgFIJMVMgBU,487
11
13
  deeplotx/similarity/__init__.py,sha256=JA1om2zeDcQVS1R04nDMdP6yegxdLJ14WF63pSTL3oo,418
12
14
  deeplotx/similarity/distribution.py,sha256=wQGouuuW531pZeBRKBujXsdsoz4fDnPw7_GW81jwepc,1066
@@ -18,8 +20,8 @@ deeplotx/trainer/text_binary_classification_trainer.py,sha256=5O-5dwVMCj5EDX9gjJ
18
20
  deeplotx/util/__init__.py,sha256=JxqAK_WOOHcYVSTHBT1-WuBwWrPEVDTV3titeVWvNUM,74
19
21
  deeplotx/util/hash.py,sha256=wwsC6kOQvbpuvwKsNQOARd78_wePmW9i3oaUuXRUnpc,352
20
22
  deeplotx/util/read_file.py,sha256=ptzouvEQeeW8KU5BrWNJlXw-vFXVrpS9SkAUxsu6A8A,612
21
- deeplotx-0.3.2.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
22
- deeplotx-0.3.2.dist-info/METADATA,sha256=H-P7HtzfZTYmsnNQHVLP4GuyxSDGAlY7nWoi13HQQRg,1598
23
- deeplotx-0.3.2.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
24
- deeplotx-0.3.2.dist-info/top_level.txt,sha256=hKg4pVDXZ-WWxkRfJFczRIll1Sv7VyfKCmzHLXbuh1U,9
25
- deeplotx-0.3.2.dist-info/RECORD,,
23
+ deeplotx-0.4.2.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
24
+ deeplotx-0.4.2.dist-info/METADATA,sha256=9P9wwwclwBpMBg3K6tXB6uJA_K6nkXct6XK8tnXR_IE,1583
25
+ deeplotx-0.4.2.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
26
+ deeplotx-0.4.2.dist-info/top_level.txt,sha256=hKg4pVDXZ-WWxkRfJFczRIll1Sv7VyfKCmzHLXbuh1U,9
27
+ deeplotx-0.4.2.dist-info/RECORD,,