deeplotx 0.2.21__tar.gz → 0.3.2__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.
- {deeplotx-0.2.21 → deeplotx-0.3.2}/PKG-INFO +2 -2
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/__init__.py +1 -1
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/encoder/__init__.py +1 -0
- deeplotx-0.3.2/deeplotx/similarity/__init__.py +17 -0
- deeplotx-0.3.2/deeplotx/similarity/distribution.py +32 -0
- deeplotx-0.3.2/deeplotx/similarity/set.py +19 -0
- deeplotx-0.3.2/deeplotx/similarity/vector.py +36 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx.egg-info/PKG-INFO +2 -2
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx.egg-info/SOURCES.txt +4 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx.egg-info/requires.txt +1 -1
- {deeplotx-0.2.21 → deeplotx-0.3.2}/pyproject.toml +15 -15
- {deeplotx-0.2.21 → deeplotx-0.3.2}/LICENSE +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/README.md +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/encoder/bert_encoder.py +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/encoder/long_text_encoder.py +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/encoder/longformer_encoder.py +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/nn/__init__.py +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/nn/base_neural_network.py +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/nn/linear_regression.py +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/nn/logistic_regression.py +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/nn/softmax_regression.py +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/trainer/__init__.py +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/trainer/base_trainer.py +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/trainer/text_binary_classification_trainer.py +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/util/__init__.py +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/util/hash.py +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx/util/read_file.py +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx.egg-info/dependency_links.txt +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/deeplotx.egg-info/top_level.txt +0 -0
- {deeplotx-0.2.21 → deeplotx-0.3.2}/setup.cfg +0 -0
@@ -1,11 +1,11 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: deeplotx
|
3
|
-
Version: 0.2
|
3
|
+
Version: 0.3.2
|
4
4
|
Summary: Easy-2-use long text classifier trainers.
|
5
5
|
Requires-Python: >=3.10
|
6
6
|
Description-Content-Type: text/markdown
|
7
7
|
License-File: LICENSE
|
8
|
-
Requires-Dist:
|
8
|
+
Requires-Dist: hf-xet>=1.0.5
|
9
9
|
Requires-Dist: jupyter>=1.1.1
|
10
10
|
Requires-Dist: numpy>=2.2.5
|
11
11
|
Requires-Dist: python-dotenv>=1.1.0
|
@@ -3,7 +3,7 @@ import os
|
|
3
3
|
|
4
4
|
__ROOT__ = os.path.dirname(os.path.abspath(__file__))
|
5
5
|
|
6
|
-
from .encoder import BertEncoder, LongTextEncoder
|
6
|
+
from .encoder import BertEncoder, LongTextEncoder, LongformerEncoder
|
7
7
|
from .nn import LinearRegression, LogisticRegression, SoftmaxRegression
|
8
8
|
from .trainer import TextBinaryClassifierTrainer
|
9
9
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import numpy as np
|
2
|
+
import torch
|
3
|
+
|
4
|
+
bias = 1e-12
|
5
|
+
|
6
|
+
|
7
|
+
def ndarray_adapter(*args) -> tuple | np.ndarray:
|
8
|
+
args = list(args)
|
9
|
+
for i, arg in enumerate(args):
|
10
|
+
match arg.__class__:
|
11
|
+
case torch.Tensor:
|
12
|
+
args[i] = arg.detach().cpu().numpy()
|
13
|
+
case List:
|
14
|
+
args[i] = np.asarray(arg)
|
15
|
+
if len(args) > 1:
|
16
|
+
return tuple(args)
|
17
|
+
return args[0]
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import numpy as np
|
2
|
+
import torch
|
3
|
+
|
4
|
+
from deeplotx.similarity import bias, ndarray_adapter
|
5
|
+
|
6
|
+
|
7
|
+
def cross_entropy(p: torch.Tensor | np.ndarray, q: torch.Tensor | np.ndarray) -> np.float32:
|
8
|
+
p, q = ndarray_adapter(p, q)
|
9
|
+
q = np.clip(q, bias, 1 - bias)
|
10
|
+
return -1 * (np.sum(p * np.log(q)) / p.shape[0])
|
11
|
+
|
12
|
+
|
13
|
+
def kl_divergence(p: torch.Tensor | np.ndarray, q: torch.Tensor | np.ndarray) -> np.float32:
|
14
|
+
p, q = ndarray_adapter(p, q)
|
15
|
+
q = np.where(q == 0, bias, q)
|
16
|
+
p = p / np.sum(p)
|
17
|
+
q = q / np.sum(q)
|
18
|
+
return np.sum(p * np.log(p / q))
|
19
|
+
|
20
|
+
|
21
|
+
def js_divergence(p: torch.Tensor | np.ndarray, q: torch.Tensor | np.ndarray) -> np.float32:
|
22
|
+
p, q = ndarray_adapter(p, q)
|
23
|
+
m = (p + q) / 2
|
24
|
+
return (kl_divergence(p, m) + kl_divergence(q, m)) / 2
|
25
|
+
|
26
|
+
|
27
|
+
def hellinger_distance(p: torch.Tensor | np.ndarray, q: torch.Tensor | np.ndarray) -> np.float32:
|
28
|
+
p, q = ndarray_adapter(p, q)
|
29
|
+
p = p / np.sum(p)
|
30
|
+
q = q / np.sum(q)
|
31
|
+
squared_diff = (np.sqrt(p) - np.sqrt(q)) ** 2
|
32
|
+
return np.sqrt(np.sum(squared_diff)) / np.sqrt(2)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
from deeplotx.similarity import bias
|
2
|
+
|
3
|
+
|
4
|
+
def jaccard_similarity(set1: set, set2: set) -> float:
|
5
|
+
return (len(set1.intersection(set2)) + bias) / (len(set1.union(set2)) + bias)
|
6
|
+
|
7
|
+
|
8
|
+
def overlap_coefficient(set1: set, set2: set) -> float:
|
9
|
+
return (len(set1.intersection(set2)) + bias) / (min(len(set1), len(set2)) + bias)
|
10
|
+
|
11
|
+
|
12
|
+
def dice_coefficient(set1: set, set2: set) -> float:
|
13
|
+
return (2 * len(set1.intersection(set2)) + bias) / (len(set1) + len(set2) + bias)
|
14
|
+
|
15
|
+
|
16
|
+
def ochiai_similarity(set1: set, set2: set) -> float:
|
17
|
+
intersection = len(set1.intersection(set2))
|
18
|
+
product = len(set1) ** 0.5 * len(set2) ** 0.5
|
19
|
+
return (intersection + bias) / (product + bias)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import numpy as np
|
2
|
+
import torch
|
3
|
+
|
4
|
+
from deeplotx.similarity import ndarray_adapter
|
5
|
+
|
6
|
+
|
7
|
+
def l2_normalize(x: torch.Tensor | np.ndarray) -> np.ndarray:
|
8
|
+
x = ndarray_adapter(x)
|
9
|
+
return x / np.sqrt(np.sum(np.multiply(x, x)))
|
10
|
+
|
11
|
+
|
12
|
+
def z_score_normalize(x: torch.Tensor | np.ndarray) -> np.ndarray:
|
13
|
+
x = ndarray_adapter(x)
|
14
|
+
mean = np.mean(x)
|
15
|
+
std_dev = np.std(x)
|
16
|
+
return (x - mean) / std_dev
|
17
|
+
|
18
|
+
|
19
|
+
def euclidean_similarity(p: torch.Tensor | np.ndarray, q: torch.Tensor | np.ndarray) -> np.float32:
|
20
|
+
p, q = ndarray_adapter(p, q)
|
21
|
+
distance = p - q
|
22
|
+
distance = np.sum(np.multiply(distance, distance))
|
23
|
+
return np.sqrt(distance)
|
24
|
+
|
25
|
+
|
26
|
+
def cosine_similarity(p: torch.Tensor | np.ndarray, q: torch.Tensor | np.ndarray) -> np.float32:
|
27
|
+
p, q = ndarray_adapter(p, q)
|
28
|
+
a = np.matmul(np.transpose(p), q)
|
29
|
+
b = np.sum(np.multiply(p, p))
|
30
|
+
c = np.sum(np.multiply(q, q))
|
31
|
+
return 1 - (a / (np.sqrt(b) * np.sqrt(c)))
|
32
|
+
|
33
|
+
|
34
|
+
def chebyshev_similarity(p: torch.Tensor | np.ndarray, q: torch.Tensor | np.ndarray) -> np.float32:
|
35
|
+
p, q = ndarray_adapter(p, q)
|
36
|
+
return np.max(np.abs(p - q))
|
@@ -1,11 +1,11 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: deeplotx
|
3
|
-
Version: 0.2
|
3
|
+
Version: 0.3.2
|
4
4
|
Summary: Easy-2-use long text classifier trainers.
|
5
5
|
Requires-Python: >=3.10
|
6
6
|
Description-Content-Type: text/markdown
|
7
7
|
License-File: LICENSE
|
8
|
-
Requires-Dist:
|
8
|
+
Requires-Dist: hf-xet>=1.0.5
|
9
9
|
Requires-Dist: jupyter>=1.1.1
|
10
10
|
Requires-Dist: numpy>=2.2.5
|
11
11
|
Requires-Dist: python-dotenv>=1.1.0
|
@@ -16,6 +16,10 @@ deeplotx/nn/base_neural_network.py
|
|
16
16
|
deeplotx/nn/linear_regression.py
|
17
17
|
deeplotx/nn/logistic_regression.py
|
18
18
|
deeplotx/nn/softmax_regression.py
|
19
|
+
deeplotx/similarity/__init__.py
|
20
|
+
deeplotx/similarity/distribution.py
|
21
|
+
deeplotx/similarity/set.py
|
22
|
+
deeplotx/similarity/vector.py
|
19
23
|
deeplotx/trainer/__init__.py
|
20
24
|
deeplotx/trainer/base_trainer.py
|
21
25
|
deeplotx/trainer/text_binary_classification_trainer.py
|
@@ -1,15 +1,15 @@
|
|
1
|
-
[project]
|
2
|
-
name = "deeplotx"
|
3
|
-
version = "0.2
|
4
|
-
description = "Easy-2-use long text classifier trainers."
|
5
|
-
readme = "README.md"
|
6
|
-
requires-python = ">=3.10"
|
7
|
-
dependencies = [
|
8
|
-
"
|
9
|
-
"jupyter>=1.1.1",
|
10
|
-
"numpy>=2.2.5",
|
11
|
-
"python-dotenv>=1.1.0",
|
12
|
-
"torch>=2.7.0",
|
13
|
-
"transformers>=4.51.3",
|
14
|
-
"typing-extensions>=4.13.2",
|
15
|
-
]
|
1
|
+
[project]
|
2
|
+
name = "deeplotx"
|
3
|
+
version = "0.3.2"
|
4
|
+
description = "Easy-2-use long text classifier trainers."
|
5
|
+
readme = "README.md"
|
6
|
+
requires-python = ">=3.10"
|
7
|
+
dependencies = [
|
8
|
+
"hf-xet>=1.0.5",
|
9
|
+
"jupyter>=1.1.1",
|
10
|
+
"numpy>=2.2.5",
|
11
|
+
"python-dotenv>=1.1.0",
|
12
|
+
"torch>=2.7.0",
|
13
|
+
"transformers>=4.51.3",
|
14
|
+
"typing-extensions>=4.13.2",
|
15
|
+
]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|