libmultilabel 0.7.4__tar.gz → 0.8.0__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 (34) hide show
  1. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/PKG-INFO +9 -7
  2. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/README.md +1 -1
  3. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/linear/linear.py +18 -4
  4. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/linear/tree.py +23 -22
  5. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel.egg-info/PKG-INFO +9 -7
  6. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel.egg-info/requires.txt +4 -3
  7. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/setup.cfg +7 -6
  8. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/LICENSE +0 -0
  9. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/__init__.py +0 -0
  10. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/common_utils.py +0 -0
  11. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/linear/__init__.py +0 -0
  12. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/linear/data_utils.py +0 -0
  13. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/linear/metrics.py +0 -0
  14. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/linear/preprocessor.py +0 -0
  15. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/linear/utils.py +0 -0
  16. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/logging.py +0 -0
  17. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/nn/__init__.py +0 -0
  18. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/nn/attentionxml.py +0 -0
  19. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/nn/data_utils.py +0 -0
  20. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/nn/metrics.py +0 -0
  21. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/nn/model.py +0 -0
  22. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/nn/networks/__init__.py +0 -0
  23. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/nn/networks/bert.py +0 -0
  24. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/nn/networks/bert_attention.py +0 -0
  25. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/nn/networks/caml.py +0 -0
  26. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/nn/networks/kim_cnn.py +0 -0
  27. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/nn/networks/labelwise_attention_networks.py +0 -0
  28. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/nn/networks/modules.py +0 -0
  29. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/nn/networks/xml_cnn.py +0 -0
  30. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel/nn/nn_utils.py +0 -0
  31. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel.egg-info/SOURCES.txt +0 -0
  32. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel.egg-info/dependency_links.txt +0 -0
  33. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/libmultilabel.egg-info/top_level.txt +0 -0
  34. {libmultilabel-0.7.4 → libmultilabel-0.8.0}/pyproject.toml +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: libmultilabel
3
- Version: 0.7.4
3
+ Version: 0.8.0
4
4
  Summary: A library for multi-class and multi-label classification
5
5
  Home-page: https://github.com/ASUS-AICS/LibMultiLabel
6
6
  Author: LibMultiLabel Team
@@ -16,23 +16,25 @@ Classifier: Intended Audience :: Science/Research
16
16
  Classifier: License :: OSI Approved :: MIT License
17
17
  Classifier: Operating System :: OS Independent
18
18
  Classifier: Programming Language :: Python :: 3
19
- Classifier: Programming Language :: Python :: 3.8
20
- Requires-Python: >=3.8
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Requires-Python: >=3.10
21
21
  License-File: LICENSE
22
22
  Requires-Dist: liblinear-multicore>=2.49.0
23
23
  Requires-Dist: numba
24
24
  Requires-Dist: pandas>1.3.0
25
25
  Requires-Dist: PyYAML
26
26
  Requires-Dist: scikit-learn
27
- Requires-Dist: scipy<1.14.0
27
+ Requires-Dist: scipy
28
28
  Requires-Dist: tqdm
29
29
  Requires-Dist: psutil
30
+ Requires-Dist: sparsekmeans
30
31
  Provides-Extra: nn
31
- Requires-Dist: lightning==2.0.9; extra == "nn"
32
+ Requires-Dist: lightning; extra == "nn"
32
33
  Requires-Dist: nltk; extra == "nn"
33
34
  Requires-Dist: torch<=2.3; extra == "nn"
34
35
  Requires-Dist: torchmetrics==0.10.3; extra == "nn"
35
36
  Requires-Dist: torchtext; extra == "nn"
36
- Requires-Dist: transformers; extra == "nn"
37
+ Requires-Dist: transformers<=4.51.3; extra == "nn"
38
+ Dynamic: license-file
37
39
 
38
40
  See documentation here: https://www.csie.ntu.edu.tw/~cjlin/libmultilabel
@@ -9,7 +9,7 @@ LibMultiLabel is a library for binary, multi-class, and multi-label classificati
9
9
  This is an on-going development so many improvements are still being made. Comments are very welcome.
10
10
 
11
11
  ## Environments
12
- - Python: 3.8+
12
+ - Python: 3.10+
13
13
  - CUDA: 11.8, 12.1 (if training neural networks by GPU)
14
14
  - Pytorch: 2.0.1+
15
15
 
@@ -27,7 +27,7 @@ class FlatModel:
27
27
  def __init__(
28
28
  self,
29
29
  name: str,
30
- weights: np.matrix,
30
+ weights: np.matrix | sparse.csr_matrix,
31
31
  bias: float,
32
32
  thresholds: float | np.ndarray,
33
33
  multiclass: bool,
@@ -69,7 +69,21 @@ class FlatModel:
69
69
  "csr",
70
70
  )
71
71
 
72
- return (x * self.weights).A + self.thresholds
72
+ return self._to_dense_array(x * self.weights) + self.thresholds
73
+
74
+ def _to_dense_array(self, matrix: np.matrix | sparse.csr_matrix) -> np.ndarray:
75
+ """Convert a numpy or scipy matrix to a dense ndarray.
76
+
77
+ Args:
78
+ matrix (np.matrix | sparse.csr_matrix): A numpy or scipy sparse matrix.
79
+
80
+ Returns:
81
+ np.ndarray: A dense ndarray of `matrix`.
82
+ """
83
+ if sparse.issparse(matrix):
84
+ return matrix.toarray()
85
+ elif isinstance(matrix, np.matrix):
86
+ return np.asarray(matrix)
73
87
 
74
88
 
75
89
  def train_1vsrest(
@@ -458,7 +472,7 @@ def _cost_sensitive_one_label(y: np.ndarray, x: sparse.csr_matrix, options: str)
458
472
 
459
473
  param_space = [1, 1.33, 1.8, 2.5, 3.67, 6, 13]
460
474
 
461
- bestScore = -np.Inf
475
+ bestScore = -np.inf
462
476
  for a in param_space:
463
477
  cv_options = f"{options} -w1 {a}"
464
478
  pred = _cross_validate(y, x, cv_options, perm)
@@ -532,7 +546,7 @@ def train_cost_sensitive_micro(
532
546
  l = y.shape[0]
533
547
  perm = np.random.permutation(l)
534
548
  param_space = [1, 1.33, 1.8, 2.5, 3.67, 6, 13]
535
- bestScore = -np.Inf
549
+ bestScore = -np.inf
536
550
 
537
551
  if verbose:
538
552
  logging.info(f"Training cost-sensitive model for Micro-F1 on {num_class} labels")
@@ -4,7 +4,7 @@ from typing import Callable
4
4
 
5
5
  import numpy as np
6
6
  import scipy.sparse as sparse
7
- import sklearn.cluster
7
+ from sparsekmeans import LloydKmeans, ElkanKmeans
8
8
  import sklearn.preprocessing
9
9
  from tqdm import tqdm
10
10
  import psutil
@@ -101,7 +101,7 @@ class TreeModel:
101
101
  self.subtree_models = []
102
102
  for i in range(len(self.root.children)):
103
103
  subtree_weights_start = self.node_ptr[self.root.children[i].index]
104
- subtree_weights_end = self.node_ptr[self.root.children[i+1].index] if i+1 < len(self.root.children) else -1
104
+ subtree_weights_end = self.node_ptr[self.root.children[i+1].index] if i+1 < len(self.root.children) else self.node_ptr[-1]
105
105
  slice = np.s_[:, subtree_weights_start:subtree_weights_end]
106
106
  subtree_flatmodel = linear.FlatModel(
107
107
  name="subtree-flattened-tree",
@@ -274,28 +274,29 @@ def _build_tree(label_representation: sparse.csr_matrix, label_map: np.ndarray,
274
274
  Returns:
275
275
  Node: Root of the (sub)tree built from label_representation.
276
276
  """
277
- if d >= dmax or label_representation.shape[0] <= K:
278
- return Node(label_map=label_map, children=[])
279
-
280
- metalabels = (
281
- sklearn.cluster.KMeans(
282
- K,
283
- random_state=np.random.randint(2**31 - 1),
284
- n_init=1,
285
- max_iter=300,
286
- tol=0.0001,
287
- algorithm="elkan",
277
+ children = []
278
+ if d < dmax and label_representation.shape[0] > K:
279
+ if label_representation.shape[0] > 10000:
280
+ kmeans_algo = ElkanKmeans
281
+ else:
282
+ kmeans_algo = LloydKmeans
283
+
284
+ kmeans = kmeans_algo(
285
+ n_clusters=K, max_iter=300, tol=0.0001, random_state=np.random.randint(2**31 - 1), verbose=True
288
286
  )
289
- .fit(label_representation)
290
- .labels_
291
- )
287
+ metalabels = kmeans.fit(label_representation)
292
288
 
293
- children = []
294
- for i in range(K):
295
- child_representation = label_representation[metalabels == i]
296
- child_map = label_map[metalabels == i]
297
- child = _build_tree(child_representation, child_map, d + 1, K, dmax)
298
- children.append(child)
289
+ unique_labels = np.unique(metalabels)
290
+ if len(unique_labels) == K:
291
+ create_child_node = lambda i: _build_tree(
292
+ label_representation[metalabels == i], label_map[metalabels == i], d + 1, K, dmax
293
+ )
294
+ else:
295
+ create_child_node = lambda i: Node(label_map=label_map[metalabels == i], children=[])
296
+
297
+ for i in range(K):
298
+ child = create_child_node(i)
299
+ children.append(child)
299
300
 
300
301
  return Node(label_map=label_map, children=children)
301
302
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: libmultilabel
3
- Version: 0.7.4
3
+ Version: 0.8.0
4
4
  Summary: A library for multi-class and multi-label classification
5
5
  Home-page: https://github.com/ASUS-AICS/LibMultiLabel
6
6
  Author: LibMultiLabel Team
@@ -16,23 +16,25 @@ Classifier: Intended Audience :: Science/Research
16
16
  Classifier: License :: OSI Approved :: MIT License
17
17
  Classifier: Operating System :: OS Independent
18
18
  Classifier: Programming Language :: Python :: 3
19
- Classifier: Programming Language :: Python :: 3.8
20
- Requires-Python: >=3.8
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Requires-Python: >=3.10
21
21
  License-File: LICENSE
22
22
  Requires-Dist: liblinear-multicore>=2.49.0
23
23
  Requires-Dist: numba
24
24
  Requires-Dist: pandas>1.3.0
25
25
  Requires-Dist: PyYAML
26
26
  Requires-Dist: scikit-learn
27
- Requires-Dist: scipy<1.14.0
27
+ Requires-Dist: scipy
28
28
  Requires-Dist: tqdm
29
29
  Requires-Dist: psutil
30
+ Requires-Dist: sparsekmeans
30
31
  Provides-Extra: nn
31
- Requires-Dist: lightning==2.0.9; extra == "nn"
32
+ Requires-Dist: lightning; extra == "nn"
32
33
  Requires-Dist: nltk; extra == "nn"
33
34
  Requires-Dist: torch<=2.3; extra == "nn"
34
35
  Requires-Dist: torchmetrics==0.10.3; extra == "nn"
35
36
  Requires-Dist: torchtext; extra == "nn"
36
- Requires-Dist: transformers; extra == "nn"
37
+ Requires-Dist: transformers<=4.51.3; extra == "nn"
38
+ Dynamic: license-file
37
39
 
38
40
  See documentation here: https://www.csie.ntu.edu.tw/~cjlin/libmultilabel
@@ -3,14 +3,15 @@ numba
3
3
  pandas>1.3.0
4
4
  PyYAML
5
5
  scikit-learn
6
- scipy<1.14.0
6
+ scipy
7
7
  tqdm
8
8
  psutil
9
+ sparsekmeans
9
10
 
10
11
  [nn]
11
- lightning==2.0.9
12
+ lightning
12
13
  nltk
13
14
  torch<=2.3
14
15
  torchmetrics==0.10.3
15
16
  torchtext
16
- transformers
17
+ transformers<=4.51.3
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = libmultilabel
3
- version = 0.7.4
3
+ version = 0.8.0
4
4
  author = LibMultiLabel Team
5
5
  license = MIT License
6
6
  license_file = LICENSE
@@ -20,7 +20,7 @@ classifiers =
20
20
  License :: OSI Approved :: MIT License
21
21
  Operating System :: OS Independent
22
22
  Programming Language :: Python :: 3
23
- Programming Language :: Python :: 3.8
23
+ Programming Language :: Python :: 3.10
24
24
 
25
25
  [options]
26
26
  packages = find:
@@ -30,19 +30,20 @@ install_requires =
30
30
  pandas>1.3.0
31
31
  PyYAML
32
32
  scikit-learn
33
- scipy<1.14.0
33
+ scipy
34
34
  tqdm
35
35
  psutil
36
- python_requires = >=3.8
36
+ sparsekmeans
37
+ python_requires = >=3.10
37
38
 
38
39
  [options.extras_require]
39
40
  nn =
40
- lightning==2.0.9
41
+ lightning
41
42
  nltk
42
43
  torch<=2.3
43
44
  torchmetrics==0.10.3
44
45
  torchtext
45
- transformers
46
+ transformers<=4.51.3
46
47
 
47
48
  [options.packages.find]
48
49
  exclude =
File without changes