From a77054d65399288ad27281a211035d3f03a12e81 Mon Sep 17 00:00:00 2001 From: Eleven Liu Date: Thu, 17 Jul 2025 17:04:57 +0800 Subject: [PATCH 1/5] Change python version to 3.10, update corresponding sys setup files, docs, and pkgs (np, lightning). --- .github/workflows/basic_test.yml | 2 +- .github/workflows/python-publish.yml | 2 +- README.md | 2 +- docs/cli/nn.rst | 3 ++- docs/cli/ov_data_format.rst | 4 ++-- docs/readme | 2 +- libmultilabel/linear/linear.py | 4 ++-- requirements_nn.txt | 3 +-- setup.cfg | 8 ++++---- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/basic_test.yml b/.github/workflows/basic_test.yml index 76a7a6dc..c786801f 100644 --- a/.github/workflows/basic_test.yml +++ b/.github/workflows/basic_test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8"] + python-version: ["3.10"] steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index fe1b5a25..6dcacefd 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -22,7 +22,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: '3.8' + python-version: '3.10' - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/README.md b/README.md index cb21a68c..33240b65 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ LibMultiLabel is a library for binary, multi-class, and multi-label classificati This is an on-going development so many improvements are still being made. Comments are very welcome. ## Environments -- Python: 3.8+ +- Python: 3.10+ - CUDA: 11.8, 12.1 (if training neural networks by GPU) - Pytorch: 2.0.1+ diff --git a/docs/cli/nn.rst b/docs/cli/nn.rst index e5a1fec8..efe2f5f2 100644 --- a/docs/cli/nn.rst +++ b/docs/cli/nn.rst @@ -133,7 +133,8 @@ To deploy/evaluate a model (i.e., a pre-obtained checkpoint), you can predict a Hyper-parameter Search ^^^^^^^^^^^^^^^^^^^^^^ -Parameter selection is known to be extremely important in machine learning practice; see a powerful reminder in "`this paper `_". Here we leverage `Ray Tune `__, which is a python library for hyper-parameter tuning, to select parameters. Due to the dependency of Ray Tune, first make sure your python version is not greater than 3.8. Then, install the related packages with:: +Parameter selection is known to be extremely important in machine learning practice; see a powerful reminder in "`this paper `_". +Here we leverage `Ray Tune `__, which is a python library for hyper-parameter tuning, to select parameters. Install the related packages with:: pip3 install -Ur requirements_parameter_search.txt diff --git a/docs/cli/ov_data_format.rst b/docs/cli/ov_data_format.rst index 2e7ae85c..f813d8c2 100644 --- a/docs/cli/ov_data_format.rst +++ b/docs/cli/ov_data_format.rst @@ -24,7 +24,7 @@ Install LibMultiLabel from Source * Environment - * Python: 3.8+ + * Python: 3.10+ * CUDA: 11.8, 12.1 (if training neural networks by GPU) * Pytorch 2.0.1+ @@ -37,7 +37,7 @@ and then create a virtual enviroment as follows. .. code-block:: bash - conda create -n LibMultiLabel python=3.8 + conda create -n LibMultiLabel python=3.10 conda activate LibMultiLabel * Clone `LibMultiLabel `_. diff --git a/docs/readme b/docs/readme index 03187eb1..d5bb426c 100644 --- a/docs/readme +++ b/docs/readme @@ -1,4 +1,4 @@ -To build the documentation, please set up Python 3.8 and: +To build the documentation, please set up Python 3.10 and: pip install -r ../requirements.txt pip install -r ../requirements_nn.txt pip install -r requirements.txt diff --git a/libmultilabel/linear/linear.py b/libmultilabel/linear/linear.py index 578ae18a..25859979 100644 --- a/libmultilabel/linear/linear.py +++ b/libmultilabel/linear/linear.py @@ -458,7 +458,7 @@ def _cost_sensitive_one_label(y: np.ndarray, x: sparse.csr_matrix, options: str) param_space = [1, 1.33, 1.8, 2.5, 3.67, 6, 13] - bestScore = -np.Inf + bestScore = -np.inf for a in param_space: cv_options = f"{options} -w1 {a}" pred = _cross_validate(y, x, cv_options, perm) @@ -532,7 +532,7 @@ def train_cost_sensitive_micro( l = y.shape[0] perm = np.random.permutation(l) param_space = [1, 1.33, 1.8, 2.5, 3.67, 6, 13] - bestScore = -np.Inf + bestScore = -np.inf if verbose: logging.info(f"Training cost-sensitive model for Micro-F1 on {num_class} labels") diff --git a/requirements_nn.txt b/requirements_nn.txt index f527d380..f0df8de3 100644 --- a/requirements_nn.txt +++ b/requirements_nn.txt @@ -1,6 +1,5 @@ nltk -# wait for https://github.com/Lightning-AI/pytorch-lightning/pull/19191 -lightning==2.0.9 +lightning # https://github.com/pytorch/text/releases torch<=2.3 torchmetrics==0.10.3 diff --git a/setup.cfg b/setup.cfg index c338b0bc..a76e5d82 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = libmultilabel -version = 0.7.4 +version = 0.8.0 author = LibMultiLabel Team license = MIT License license_file = LICENSE @@ -20,7 +20,7 @@ classifiers = License :: OSI Approved :: MIT License Operating System :: OS Independent Programming Language :: Python :: 3 - Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.10 [options] packages = find: @@ -34,11 +34,11 @@ install_requires = tqdm psutil -python_requires = >=3.8 +python_requires = >=3.10 [options.extras_require] nn = - lightning==2.0.9 + lightning nltk torch<=2.3 torchmetrics==0.10.3 From 17503257e008877ffd84125767d2dfc1cd51f0be Mon Sep 17 00:00:00 2001 From: Eleven Liu Date: Fri, 18 Jul 2025 00:02:28 +0800 Subject: [PATCH 2/5] Add maximum version of transformers. --- requirements_nn.txt | 3 ++- setup.cfg | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/requirements_nn.txt b/requirements_nn.txt index f0df8de3..2c0da6a4 100644 --- a/requirements_nn.txt +++ b/requirements_nn.txt @@ -4,4 +4,5 @@ lightning torch<=2.3 torchmetrics==0.10.3 torchtext -transformers +# https://github.com/huggingface/transformers/issues/38464 +transformers<=4.51.3 diff --git a/setup.cfg b/setup.cfg index a76e5d82..de848ea5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -43,7 +43,7 @@ nn = torch<=2.3 torchmetrics==0.10.3 torchtext - transformers + transformers<=4.51.3 [options.packages.find] From 7fa373400b86defa3bd2a82a0e758521d939620f Mon Sep 17 00:00:00 2001 From: Eleven Liu Date: Fri, 18 Jul 2025 14:55:57 +0800 Subject: [PATCH 3/5] free scipy --- requirements.txt | 2 +- setup.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0625c0f4..fdff2e2e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,6 +3,6 @@ numba pandas>1.3.0 PyYAML scikit-learn -scipy<1.14.0 +scipy tqdm psutil diff --git a/setup.cfg b/setup.cfg index de848ea5..a676ce91 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,7 +30,7 @@ install_requires = pandas>1.3.0 PyYAML scikit-learn - scipy<1.14.0 + scipy tqdm psutil From 814e066a66d09590a84f4872c5d9d3127f4948aa Mon Sep 17 00:00:00 2001 From: Eleven Liu Date: Sat, 19 Jul 2025 17:37:38 +0800 Subject: [PATCH 4/5] Add transition function to deprecated scipy .A --- libmultilabel/linear/linear.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libmultilabel/linear/linear.py b/libmultilabel/linear/linear.py index 25859979..963b4d57 100644 --- a/libmultilabel/linear/linear.py +++ b/libmultilabel/linear/linear.py @@ -27,7 +27,7 @@ class FlatModel: def __init__( self, name: str, - weights: np.matrix, + weights: np.matrix | sparse.csr_matrix, bias: float, thresholds: float | np.ndarray, multiclass: bool, @@ -69,7 +69,21 @@ def predict_values(self, x: sparse.csr_matrix) -> np.ndarray: "csr", ) - return (x * self.weights).A + self.thresholds + return self._to_dense_array(x * self.weights) + self.thresholds + + def _to_dense_array(self, matrix: np.matrix | sparse.csr_matrix) -> np.ndarray: + """Convert a numpy or scipy matrix to a dense ndarray. + + Args: + matrix (np.matrix | sparse.csr_matrix): A numpy or scipy sparse matrix. + + Returns: + np.ndarray: A dense ndarray of `matrix`. + """ + if sparse.issparse(matrix): + return matrix.toarray() + elif isinstance(matrix, np.matrix): + return matrix.A def train_1vsrest( From 044c95066d74fd30ee584e2cbb808bf4ab8ae461 Mon Sep 17 00:00:00 2001 From: Eleven Liu Date: Mon, 21 Jul 2025 20:13:42 +0800 Subject: [PATCH 5/5] Use full name: matrix.A to np.assarray(A) --- libmultilabel/linear/linear.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmultilabel/linear/linear.py b/libmultilabel/linear/linear.py index 963b4d57..82591831 100644 --- a/libmultilabel/linear/linear.py +++ b/libmultilabel/linear/linear.py @@ -83,7 +83,7 @@ def _to_dense_array(self, matrix: np.matrix | sparse.csr_matrix) -> np.ndarray: if sparse.issparse(matrix): return matrix.toarray() elif isinstance(matrix, np.matrix): - return matrix.A + return np.asarray(matrix) def train_1vsrest(