Skip to content

Upgrade minimum python version from 3.8 to 3.10 #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/basic_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8"]
python-version: ["3.10"]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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+

Expand Down
3 changes: 2 additions & 1 deletion docs/cli/nn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.csie.ntu.edu.tw/~cjlin/papers/parameter_selection/acl2021_parameter_selection.pdf>`_". Here we leverage `Ray Tune <https://docs.ray.io/en/master/tune/index.html>`__, 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 <https://www.csie.ntu.edu.tw/~cjlin/papers/parameter_selection/acl2021_parameter_selection.pdf>`_".
Here we leverage `Ray Tune <https://docs.ray.io/en/master/tune/index.html>`__, which is a python library for hyper-parameter tuning, to select parameters. Install the related packages with::

pip3 install -Ur requirements_parameter_search.txt

Expand Down
4 changes: 2 additions & 2 deletions docs/cli/ov_data_format.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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+

Expand All @@ -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 <https://github.com/ntumlgroup/LibMultiLabel>`_.
Expand Down
2 changes: 1 addition & 1 deletion docs/readme
Original file line number Diff line number Diff line change
@@ -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
Expand Down
22 changes: 18 additions & 4 deletions libmultilabel/linear/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -458,7 +472,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)
Expand Down Expand Up @@ -532,7 +546,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")
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ numba
pandas>1.3.0
PyYAML
scikit-learn
scipy<1.14.0
scipy
tqdm
psutil
6 changes: 3 additions & 3 deletions requirements_nn.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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
torchtext
transformers
# https://github.com/huggingface/transformers/issues/38464
transformers<=4.51.3
12 changes: 6 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = libmultilabel
version = 0.7.4
version = 0.8.0
author = LibMultiLabel Team
license = MIT License
license_file = LICENSE
Expand All @@ -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:
Expand All @@ -30,20 +30,20 @@ install_requires =
pandas>1.3.0
PyYAML
scikit-learn
scipy<1.14.0
scipy
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
torchtext
transformers
transformers<=4.51.3


[options.packages.find]
Expand Down