deeplotx 0.8.3__tar.gz → 0.8.5__tar.gz

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.
Files changed (40) hide show
  1. {deeplotx-0.8.3 → deeplotx-0.8.5}/PKG-INFO +2 -1
  2. {deeplotx-0.8.3 → deeplotx-0.8.5}/README.md +1 -0
  3. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/__init__.py +1 -0
  4. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/nn/__init__.py +1 -0
  5. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/nn/auto_regression.py +2 -2
  6. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/nn/linear_regression.py +5 -4
  7. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/nn/logistic_regression.py +4 -4
  8. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/nn/long_context_recursive_sequential.py +2 -3
  9. deeplotx-0.8.5/deeplotx/nn/multi_head_feed_forward.py +32 -0
  10. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/nn/recursive_sequential.py +5 -5
  11. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/nn/softmax_regression.py +4 -4
  12. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/trainer/text_binary_classification_trainer.py +6 -5
  13. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx.egg-info/PKG-INFO +2 -1
  14. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx.egg-info/SOURCES.txt +1 -0
  15. {deeplotx-0.8.3 → deeplotx-0.8.5}/pyproject.toml +17 -17
  16. {deeplotx-0.8.3 → deeplotx-0.8.5}/LICENSE +0 -0
  17. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/encoder/__init__.py +0 -0
  18. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/encoder/encoder.py +0 -0
  19. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/encoder/long_text_encoder.py +0 -0
  20. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/encoder/longformer_encoder.py +0 -0
  21. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/nn/attention.py +0 -0
  22. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/nn/base_neural_network.py +0 -0
  23. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/nn/feed_forward.py +0 -0
  24. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/nn/long_context_auto_regression.py +0 -0
  25. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/nn/multi_head_attention.py +0 -0
  26. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/nn/roformer_encoder.py +0 -0
  27. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/nn/rope.py +0 -0
  28. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/similarity/__init__.py +0 -0
  29. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/similarity/distribution.py +0 -0
  30. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/similarity/set.py +0 -0
  31. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/similarity/vector.py +0 -0
  32. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/trainer/__init__.py +0 -0
  33. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/trainer/base_trainer.py +0 -0
  34. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/util/__init__.py +0 -0
  35. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/util/hash.py +0 -0
  36. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx/util/read_file.py +0 -0
  37. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx.egg-info/dependency_links.txt +0 -0
  38. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx.egg-info/requires.txt +0 -0
  39. {deeplotx-0.8.3 → deeplotx-0.8.5}/deeplotx.egg-info/top_level.txt +0 -0
  40. {deeplotx-0.8.3 → deeplotx-0.8.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deeplotx
3
- Version: 0.8.3
3
+ Version: 0.8.5
4
4
  Summary: Easy-2-use long text NLP toolkit.
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -168,6 +168,7 @@ Dynamic: license-file
168
168
  ```python
169
169
  from deeplotx import (
170
170
  FeedForward, # 前馈神经网络
171
+ MultiHeadFeedForward, # 多头前馈神经网络
171
172
  LinearRegression, # 线性回归
172
173
  LogisticRegression, # 逻辑回归 / 二分类 / 多标签分类
173
174
  SoftmaxRegression, # Softmax 回归 / 多分类
@@ -150,6 +150,7 @@
150
150
  ```python
151
151
  from deeplotx import (
152
152
  FeedForward, # 前馈神经网络
153
+ MultiHeadFeedForward, # 多头前馈神经网络
153
154
  LinearRegression, # 线性回归
154
155
  LogisticRegression, # 逻辑回归 / 二分类 / 多标签分类
155
156
  SoftmaxRegression, # Softmax 回归 / 多分类
@@ -6,6 +6,7 @@ __ROOT__ = os.path.dirname(os.path.abspath(__file__))
6
6
  from .encoder import Encoder, LongTextEncoder, LongformerEncoder
7
7
  from .nn import (
8
8
  FeedForward,
9
+ MultiHeadFeedForward,
9
10
  LinearRegression,
10
11
  LogisticRegression,
11
12
  SoftmaxRegression,
@@ -1,5 +1,6 @@
1
1
  from .base_neural_network import BaseNeuralNetwork
2
2
  from .feed_forward import FeedForward
3
+ from .multi_head_feed_forward import MultiHeadFeedForward
3
4
  from .linear_regression import LinearRegression
4
5
  from .logistic_regression import LogisticRegression
5
6
  from .softmax_regression import SoftmaxRegression
@@ -7,8 +7,8 @@ class AutoRegression(RecursiveSequential):
7
7
  def __init__(self, feature_dim: int, bias: bool = True,
8
8
  recursive_layers: int = 1, recursive_hidden_dim: int | None = None,
9
9
  ffn_layers: int = 1, ffn_expansion_factor: int | float = 2, dropout_rate: float = 0.05,
10
- model_name: str | None = None, device: str | None = None, dtype: torch.dtype | None = None):
10
+ model_name: str | None = None, device: str | None = None, dtype: torch.dtype | None = None, **kwargs):
11
11
  super().__init__(input_dim=feature_dim, output_dim=feature_dim, bias=bias,
12
12
  recursive_layers=recursive_layers, recursive_hidden_dim=recursive_hidden_dim,
13
13
  ffn_layers=ffn_layers, ffn_expansion_factor=ffn_expansion_factor,
14
- dropout_rate=dropout_rate, model_name=model_name, device=device, dtype=dtype)
14
+ dropout_rate=dropout_rate, model_name=model_name, device=device, dtype=dtype, **kwargs)
@@ -4,16 +4,17 @@ import torch
4
4
  from torch import nn
5
5
 
6
6
  from deeplotx.nn.base_neural_network import BaseNeuralNetwork
7
- from deeplotx.nn.feed_forward import FeedForward
7
+ from deeplotx.nn.multi_head_feed_forward import MultiHeadFeedForward
8
8
 
9
9
 
10
10
  class LinearRegression(BaseNeuralNetwork):
11
- def __init__(self, input_dim: int, output_dim: int, num_layers: int = 1,
11
+ def __init__(self, input_dim: int, output_dim: int, num_heads: int = 1, num_layers: int = 1,
12
12
  expansion_factor: int | float = 1.5, bias: bool = True, dropout_rate: float = 0.1,
13
13
  model_name: str | None = None, device: str | None = None, dtype: torch.dtype | None = None):
14
14
  super().__init__(in_features=input_dim, out_features=output_dim, model_name=model_name, device=device, dtype=dtype)
15
- self.ffn = FeedForward(feature_dim=input_dim, num_layers=num_layers, expansion_factor=expansion_factor,
16
- bias=bias, dropout_rate=dropout_rate, device=self.device, dtype=self.dtype)
15
+ self.ffn = MultiHeadFeedForward(feature_dim=input_dim, num_heads=num_heads,
16
+ num_layers=num_layers, expansion_factor=expansion_factor,
17
+ bias=bias, dropout_rate=dropout_rate, device=self.device, dtype=self.dtype)
17
18
  self.proj = nn.Linear(in_features=input_dim, out_features=output_dim,
18
19
  bias=bias, device=self.device, dtype=self.dtype)
19
20
 
@@ -6,10 +6,10 @@ from deeplotx.nn.linear_regression import LinearRegression
6
6
 
7
7
 
8
8
  class LogisticRegression(LinearRegression):
9
- def __init__(self, input_dim: int, output_dim: int = 1, num_layers: int = 1, expansion_factor: int | float = 1.5,
10
- bias: bool = True, dropout_rate: float = 0.1, model_name: str | None = None,
11
- device: str | None = None, dtype: torch.dtype | None = None):
12
- super().__init__(input_dim=input_dim, output_dim=output_dim, num_layers=num_layers,
9
+ def __init__(self, input_dim: int, output_dim: int = 1, num_heads: int = 1, num_layers: int = 1,
10
+ expansion_factor: int | float = 1.5, bias: bool = True, dropout_rate: float = 0.1,
11
+ model_name: str | None = None, device: str | None = None, dtype: torch.dtype | None = None):
12
+ super().__init__(input_dim=input_dim, output_dim=output_dim, num_heads=num_heads, num_layers=num_layers,
13
13
  expansion_factor=expansion_factor, bias=bias, dropout_rate=dropout_rate,
14
14
  model_name=model_name, device=device, dtype=dtype)
15
15
 
@@ -12,12 +12,11 @@ class LongContextRecursiveSequential(RecursiveSequential):
12
12
  def __init__(self, input_dim: int, output_dim: int, bias: bool = True,
13
13
  encoder_layers: int = 1, attn_heads: int = 1, recursive_layers: int = 2, recursive_hidden_dim: int | None = None,
14
14
  ffn_layers: int = 1, ffn_expansion_factor: int | float = 2, dropout_rate: float = 0.05,
15
- model_name: str | None = None, device: str | None = None, dtype: torch.dtype | None = None,
16
- **kwargs):
15
+ model_name: str | None = None, device: str | None = None, dtype: torch.dtype | None = None, **kwargs):
17
16
  super().__init__(input_dim=input_dim, output_dim=output_dim, bias=bias,
18
17
  recursive_layers=recursive_layers, recursive_hidden_dim=recursive_hidden_dim,
19
18
  ffn_layers=ffn_layers, ffn_expansion_factor=ffn_expansion_factor, dropout_rate=dropout_rate,
20
- model_name=model_name, device=device, dtype=dtype)
19
+ model_name=model_name, device=device, dtype=dtype, **kwargs)
21
20
  self.roformer_encoders = nn.ModuleList([RoFormerEncoder(feature_dim=input_dim, attn_heads=attn_heads, bias=bias,
22
21
  ffn_layers=kwargs.get('encoder_ffn_layers', ffn_layers),
23
22
  ffn_expansion_factor=kwargs.get('encoder_expansion_factor', ffn_expansion_factor),
@@ -0,0 +1,32 @@
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.feed_forward import FeedForward
8
+
9
+
10
+ class MultiHeadFeedForward(BaseNeuralNetwork):
11
+ def __init__(self, feature_dim: int, num_heads: int = 1, num_layers: int = 1, expansion_factor: int | float = 2,
12
+ bias: bool = True, dropout_rate: float = 0.05, model_name: str | None = None,
13
+ device: str | None = None, dtype: torch.dtype | None = None):
14
+ super().__init__(in_features=feature_dim, out_features=feature_dim, model_name=model_name,
15
+ device=device, dtype=dtype)
16
+ self._num_heads = num_heads
17
+ self.expand_proj = nn.Linear(in_features=feature_dim, out_features=feature_dim * self._num_heads, bias=bias,
18
+ device=self.device, dtype=self.dtype)
19
+ self.ffn_heads = nn.ModuleList([FeedForward(feature_dim=feature_dim, num_layers=num_layers,
20
+ expansion_factor=expansion_factor, bias=bias,
21
+ dropout_rate=dropout_rate, device=self.device,
22
+ dtype=self.dtype) for _ in range(self._num_heads)])
23
+ self.out_proj = nn.Linear(in_features=feature_dim * self._num_heads, out_features=feature_dim, bias=bias,
24
+ device=self.device, dtype=self.dtype)
25
+
26
+ @override
27
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
28
+ x = self.ensure_device_and_dtype(x, device=self.device, dtype=self.dtype)
29
+ x = self.expand_proj(x)
30
+ x_heads = x.split(self.in_features, dim=-1)
31
+ head_outs = [self.ffn_heads[_](x_heads[_]) for _ in range(self._num_heads)]
32
+ return self.out_proj(torch.concat(head_outs, dim=-1))
@@ -4,14 +4,14 @@ import torch
4
4
  from torch import nn
5
5
 
6
6
  from deeplotx.nn.base_neural_network import BaseNeuralNetwork
7
- from deeplotx.nn.feed_forward import FeedForward
7
+ from deeplotx.nn.multi_head_feed_forward import MultiHeadFeedForward
8
8
 
9
9
 
10
10
  class RecursiveSequential(BaseNeuralNetwork):
11
11
  def __init__(self, input_dim: int, output_dim: int, bias: bool = True,
12
12
  recursive_layers: int = 1, recursive_hidden_dim: int | None = None,
13
13
  ffn_layers: int = 1, ffn_expansion_factor: int | float = 2, dropout_rate: float = 0.05,
14
- model_name: str | None = None, device: str | None = None, dtype: torch.dtype | None = None):
14
+ model_name: str | None = None, device: str | None = None, dtype: torch.dtype | None = None, **kwargs):
15
15
  super().__init__(in_features=input_dim, out_features=output_dim, model_name=model_name,
16
16
  device=device, dtype=dtype)
17
17
  if recursive_hidden_dim is None:
@@ -20,9 +20,9 @@ class RecursiveSequential(BaseNeuralNetwork):
20
20
  num_layers=recursive_layers, batch_first=True,
21
21
  bias=True, bidirectional=True, device=self.device,
22
22
  dtype=self.dtype)
23
- self.ffn = FeedForward(feature_dim=recursive_hidden_dim * 2, num_layers=ffn_layers,
24
- expansion_factor=ffn_expansion_factor, bias=bias, dropout_rate=dropout_rate,
25
- device=self.device, dtype=self.dtype)
23
+ self.ffn = MultiHeadFeedForward(feature_dim=recursive_hidden_dim * 2, num_heads=kwargs.get('ffn_heads', 1),
24
+ num_layers=ffn_layers, expansion_factor=ffn_expansion_factor,
25
+ bias=bias, dropout_rate=dropout_rate, device=self.device, dtype=self.dtype)
26
26
  self.__proj = nn.Linear(in_features=recursive_hidden_dim * 2, out_features=output_dim, bias=bias,
27
27
  device=self.device, dtype=self.dtype)
28
28
 
@@ -6,10 +6,10 @@ from deeplotx.nn.linear_regression import LinearRegression
6
6
 
7
7
 
8
8
  class SoftmaxRegression(LinearRegression):
9
- def __init__(self, input_dim: int, output_dim: int, num_layers: int = 1, expansion_factor: int | float = 1.5,
10
- bias: bool = True, dropout_rate: float = 0.1, model_name: str | None = None,
11
- device: str | None = None, dtype: torch.dtype | None = None):
12
- super().__init__(input_dim=input_dim, output_dim=output_dim, num_layers=num_layers,
9
+ def __init__(self, input_dim: int, output_dim: int, num_heads: int = 1, num_layers: int = 1,
10
+ expansion_factor: int | float = 1.5, bias: bool = True, dropout_rate: float = 0.1,
11
+ model_name: str | None = None, device: str | None = None, dtype: torch.dtype | None = None):
12
+ super().__init__(input_dim=input_dim, output_dim=output_dim, num_heads=num_heads, num_layers=num_layers,
13
13
  expansion_factor=expansion_factor, bias=bias, dropout_rate=dropout_rate,
14
14
  model_name=model_name, device=device, dtype=dtype)
15
15
 
@@ -49,6 +49,7 @@ class TextBinaryClassifierTrainer(BaseTrainer):
49
49
  logger.warning("The dimension of features doesn't match. A new model instance will be created.")
50
50
  self.model = None
51
51
  if self.model is None:
52
+ ffn_heads = kwargs.get('ffn_heads', 2)
52
53
  ffn_layers = kwargs.get('ffn_layers', 5)
53
54
  ffn_expansion_factor = kwargs.get('ffn_expansion_factor', 2)
54
55
  bias = kwargs.get('bias', True)
@@ -63,11 +64,11 @@ class TextBinaryClassifierTrainer(BaseTrainer):
63
64
  self.model = LongContextRecursiveSequential(input_dim=feature_dim, output_dim=1, bias=bias,
64
65
  encoder_layers=encoder_layers, attn_heads=attn_heads,
65
66
  recursive_layers=recursive_layers, recursive_hidden_dim=recursive_hidden_dim,
66
- ffn_layers=ffn_layers, ffn_expansion_factor=ffn_expansion_factor, dropout_rate=dropout_rate,
67
- encoder_ffn_layers=encoder_ffn_layers, encoder_expansion_factor=encoder_expansion_factor,
68
- encoder_dropout_rate=encoder_dropout_rate, attn_ffn_layers=attn_ffn_layers,
69
- attn_expansion_factor=attn_expansion_factor, attn_dropout_rate=attn_dropout_rate,
70
- theta=theta).initialize_weights()
67
+ ffn_layers=ffn_layers, ffn_heads=ffn_heads, ffn_expansion_factor=ffn_expansion_factor,
68
+ dropout_rate=dropout_rate, encoder_ffn_layers=encoder_ffn_layers,
69
+ encoder_expansion_factor=encoder_expansion_factor, encoder_dropout_rate=encoder_dropout_rate,
70
+ attn_ffn_layers=attn_ffn_layers, attn_expansion_factor=attn_expansion_factor,
71
+ attn_dropout_rate=attn_dropout_rate, theta=theta).initialize_weights()
71
72
  logger.debug(f'Training Model: \n{self.model}')
72
73
  loss_function = nn.BCELoss()
73
74
  optimizer = optim.Adamax(self.model.parameters(), lr=learning_rate)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: deeplotx
3
- Version: 0.8.3
3
+ Version: 0.8.5
4
4
  Summary: Easy-2-use long text NLP toolkit.
5
5
  Requires-Python: >=3.10
6
6
  Description-Content-Type: text/markdown
@@ -168,6 +168,7 @@ Dynamic: license-file
168
168
  ```python
169
169
  from deeplotx import (
170
170
  FeedForward, # 前馈神经网络
171
+ MultiHeadFeedForward, # 多头前馈神经网络
171
172
  LinearRegression, # 线性回归
172
173
  LogisticRegression, # 逻辑回归 / 二分类 / 多标签分类
173
174
  SoftmaxRegression, # Softmax 回归 / 多分类
@@ -21,6 +21,7 @@ deeplotx/nn/logistic_regression.py
21
21
  deeplotx/nn/long_context_auto_regression.py
22
22
  deeplotx/nn/long_context_recursive_sequential.py
23
23
  deeplotx/nn/multi_head_attention.py
24
+ deeplotx/nn/multi_head_feed_forward.py
24
25
  deeplotx/nn/recursive_sequential.py
25
26
  deeplotx/nn/roformer_encoder.py
26
27
  deeplotx/nn/rope.py
@@ -1,17 +1,17 @@
1
- [project]
2
- name = "deeplotx"
3
- version = "0.8.3"
4
- description = "Easy-2-use long text NLP toolkit."
5
- readme = "README.md"
6
- requires-python = ">=3.10"
7
- dependencies = [
8
- "hf-xet",
9
- "jupyter",
10
- "numpy",
11
- "protobuf",
12
- "python-dotenv",
13
- "torch",
14
- "transformers",
15
- "typing-extensions",
16
- "vortezwohl>=0.0.8",
17
- ]
1
+ [project]
2
+ name = "deeplotx"
3
+ version = "0.8.5"
4
+ description = "Easy-2-use long text NLP toolkit."
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ dependencies = [
8
+ "hf-xet",
9
+ "jupyter",
10
+ "numpy",
11
+ "protobuf",
12
+ "python-dotenv",
13
+ "torch",
14
+ "transformers",
15
+ "typing-extensions",
16
+ "vortezwohl>=0.0.8",
17
+ ]
File without changes
File without changes
File without changes
File without changes