Skip to content

Commit

Permalink
Merge pull request #796 from NatLibFi/update-dependencies-v1.2
Browse files Browse the repository at this point in the history
Update dependencies for v1.2 release
  • Loading branch information
juhoinkinen authored Sep 30, 2024
2 parents 24485af + 2d7509d commit 8f2e905
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
# download the small English pretrained spaCy model needed by spacy analyzer
poetry run python -m spacy download en_core_web_sm --upgrade-strategy only-if-needed
fi
poetry run python -m nltk.downloader punkt
poetry run python -m nltk.downloader punkt_tab
- name: Test with pytest
run: |
poetry run pytest --cov=./ --cov-report xml
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN echo "Installing dependencies for optional features: $optional_dependencies"
&& rm -rf /root/.cache/pypoetry # No need for cache because of poetry.lock

# Download nltk data
RUN python -m nltk.downloader punkt -d /usr/share/nltk_data
RUN python -m nltk.downloader punkt_tab -d /usr/share/nltk_data

# Download spaCy models, if the optional feature was selected
ARG spacy_models=en_core_web_sm
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The recommended way is to install Annif from

You will also need NLTK data files:

python -m nltk.downloader punkt
python -m nltk.downloader punkt_tab

Start up the application:

Expand Down Expand Up @@ -115,7 +115,7 @@ Enter the virtual environment:

You will also need NLTK data files:

python -m nltk.downloader punkt
python -m nltk.downloader punkt_tab

Start up the application:

Expand Down
4 changes: 2 additions & 2 deletions annif/backend/nn_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from typing import TYPE_CHECKING, Any

import joblib
import keras.backend as K
import keras
import lmdb
import numpy as np
from keras.layers import Add, Dense, Dropout, Flatten, Input, Layer
Expand Down Expand Up @@ -99,7 +99,7 @@ class MeanLayer(Layer):
"""Custom Keras layer that calculates mean values along the 2nd axis."""

def call(self, inputs: EagerTensor) -> EagerTensor:
return K.mean(inputs, axis=2)
return keras.ops.mean(inputs, axis=2)


class NNEnsembleBackend(backend.AnnifLearningBackend, ensemble.BaseEnsembleBackend):
Expand Down
24 changes: 12 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,33 @@ classifiers = [
[tool.poetry.dependencies]
python = ">=3.9,<3.13"

connexion = { version = "~3.0.5", extras = ["flask", "uvicorn", "swagger-ui"] }
connexion = { version = "~3.1.0", extras = ["flask", "uvicorn", "swagger-ui"] }
click = "8.1.*"
click-log = "0.4.*"
joblib = "1.4.*"
nltk = "3.8.*"
nltk = "~3.9.1"
gensim = "4.3.*"
scikit-learn = "1.4.*"
scipy = "1.12.*"
scikit-learn = "~1.5.1"
scipy = "~1.13.1"
rdflib = "7.0.*"
requests = "2.31.*"
gunicorn = "22.0.*"
requests = "~2.32.3"
gunicorn = "~23.0.0"
numpy = "1.26.*"
optuna = "3.6.*"
optuna = "~4.0.0"
python-dateutil = "2.9.*"
tomli = { version = "2.0.*", python = "<3.11" }
simplemma = "~1.1.1"
jsonschema = "4.21.*"
huggingface-hub = "0.22.*"
jsonschema = "~4.23.0"
huggingface-hub = "~0.25.1"

fasttext-wheel = { version = "0.9.2", optional = true }
voikko = { version = "0.5.*", optional = true }
tensorflow-cpu = { version = "2.15.*", optional = true, python = "<3.12" }
lmdb = { version = "1.4.1", optional = true }
tensorflow-cpu = { version = "~2.17.0", optional = true }
lmdb = { version = "~1.5.1", optional = true }
omikuji = { version = "0.5.*", optional = true }
yake = { version = "0.4.8", optional = true }
spacy = { version = "3.7.*", optional = true }
stwfsapy = { version = "0.4.*", optional = true, python = "<3.12" }
stwfsapy = { version = "~0.5.0", optional = true }

[tool.poetry.dev-dependencies]
py = "*"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_backend_nn_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_nn_ensemble_can_set_lr(registry):
project=project,
)
nn_ensemble._create_model(["dummy-en"])
assert nn_ensemble._model.optimizer.learning_rate.value() == 0.002
assert nn_ensemble._model.optimizer.learning_rate.value == 0.002


def test_set_lmdb_map_size(registry, tmpdir):
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_nn_ensemble_train_and_learn(registry, tmpdir):
nn_ensemble.train(document_corpus)

# check adam default learning_rate:
assert nn_ensemble._model.optimizer.learning_rate.value() == 0.001
assert nn_ensemble._model.optimizer.learning_rate.value == 0.001

datadir = py.path.local(project.datadir)
assert datadir.join("nn-model.keras").exists()
Expand Down
8 changes: 4 additions & 4 deletions tests/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ def test_false_negatives():

# DCG@6 example from https://en.wikipedia.org/wiki/Discounted_cumulative_gain
def test_dcg():
y_true = csr_array([3, 2, 3, 0, 1, 2])
y_pred = csr_array([6, 5, 4, 3, 2, 1])
y_true = csr_array([[3, 2, 3, 0, 1, 2]])
y_pred = csr_array([[6, 5, 4, 3, 2, 1]])
dcg = annif.eval.dcg_score(y_true, y_pred, 6)
assert dcg > 6.86
assert dcg < 6.87


# iDCG@6 example from https://en.wikipedia.org/wiki/Discounted_cumulative_gain
def test_dcg_ideal():
y_true = csr_array([3, 3, 3, 2, 2, 2, 1, 0])
y_pred = csr_array([8, 7, 6, 5, 4, 3, 2, 1])
y_true = csr_array([[3, 3, 3, 2, 2, 2, 1, 0]])
y_pred = csr_array([[8, 7, 6, 5, 4, 3, 2, 1]])
dcg = annif.eval.dcg_score(y_true, y_pred, 6)
assert dcg > 8.74
assert dcg < 8.75
Expand Down
17 changes: 9 additions & 8 deletions tests/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import schemathesis
from hypothesis import settings

schema = schemathesis.from_path("annif/openapi/annif.yaml")
import annif

cxapp = annif.create_app(config_name="annif.default_config.TestingConfig")
schema = schemathesis.from_path("annif/openapi/annif.yaml", app=cxapp)


@schemathesis.hook("filter_path_parameters")
Expand All @@ -18,18 +21,16 @@ def filter_path_parameters(context, path_parameters):

@schema.parametrize()
@settings(max_examples=10)
def test_openapi_fuzzy(case, cxapp):
response = case.call_asgi(cxapp)
case.validate_response(response)
def test_openapi_fuzzy(case):
case.call_and_validate()


@pytest.mark.slow
@schema.parametrize(endpoint="/v1/projects/{project_id}")
@schema.include(path_regex="/v1/projects/{project_id}").parametrize()
@settings(max_examples=50)
def test_openapi_fuzzy_target_dummy_fi(case, cxapp):
def test_openapi_fuzzy_target_dummy_fi(case):
case.path_parameters = {"project_id": "dummy-fi"}
response = case.call_asgi(cxapp)
case.validate_response(response)
case.call_and_validate()


def test_openapi_cors(app_client):
Expand Down

0 comments on commit 8f2e905

Please sign in to comment.