chore: import upstream snapshot with attribution
Docs Tests / Check for file changes (push) Has been cancelled
Docs Tests / Test Documentation (push) Has been cancelled
Docs Tests / Documentation Linting Checks (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-policies) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.10) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.8) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.9) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.10) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.8) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.9) (push) Has been cancelled
Continuous Integration / Check for file changes (push) Has been cancelled
Continuous Integration / Wait for docs tests (push) Has been cancelled
Continuous Integration / Code Quality (push) Has been cancelled
Continuous Integration / Check for changelog (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Upload coverage reports to codeclimate (push) Has been cancelled
Continuous Integration / Run Non-Sequential Integration Tests (push) Has been cancelled
Continuous Integration / Run Broker Integration Tests (push) Has been cancelled
Continuous Integration / Run Sequential Integration Tests (push) Has been cancelled
Continuous Integration / Build Docker base images and setup environment (push) Has been cancelled
Continuous Integration / Build Docker (default) (push) Has been cancelled
Continuous Integration / Build Docker (full) (push) Has been cancelled
Continuous Integration / Build Docker (mitie-en) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-de) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-en) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-it) (push) Has been cancelled
Continuous Integration / Deploy to PyPI (push) Has been cancelled
Continuous Integration / Notify Slack & Publish Release Notes (push) Has been cancelled
Publish Documentation / Evaluate release tag (push) Has been cancelled
Publish Documentation / Prebuild Docs (push) Has been cancelled
Publish Documentation / Preview Docs (push) Has been cancelled
Publish Documentation / Check for file changes (push) Has been cancelled
Publish Documentation / Publish Docs (push) Has been cancelled
Automatic PR Merger / mergepal (push) Has been cancelled
CI Github Actions / Run Tests (push) Has been cancelled
Semgrep / Semgrep Workflow Security Scan (push) Has been cancelled
Docs Tests / Check for file changes (push) Has been cancelled
Docs Tests / Test Documentation (push) Has been cancelled
Docs Tests / Documentation Linting Checks (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-policies) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.10) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.8) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.9) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.10) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.8) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.9) (push) Has been cancelled
Continuous Integration / Check for file changes (push) Has been cancelled
Continuous Integration / Wait for docs tests (push) Has been cancelled
Continuous Integration / Code Quality (push) Has been cancelled
Continuous Integration / Check for changelog (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Upload coverage reports to codeclimate (push) Has been cancelled
Continuous Integration / Run Non-Sequential Integration Tests (push) Has been cancelled
Continuous Integration / Run Broker Integration Tests (push) Has been cancelled
Continuous Integration / Run Sequential Integration Tests (push) Has been cancelled
Continuous Integration / Build Docker base images and setup environment (push) Has been cancelled
Continuous Integration / Build Docker (default) (push) Has been cancelled
Continuous Integration / Build Docker (full) (push) Has been cancelled
Continuous Integration / Build Docker (mitie-en) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-de) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-en) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-it) (push) Has been cancelled
Continuous Integration / Deploy to PyPI (push) Has been cancelled
Continuous Integration / Notify Slack & Publish Release Notes (push) Has been cancelled
Publish Documentation / Evaluate release tag (push) Has been cancelled
Publish Documentation / Prebuild Docs (push) Has been cancelled
Publish Documentation / Preview Docs (push) Has been cancelled
Publish Documentation / Check for file changes (push) Has been cancelled
Publish Documentation / Publish Docs (push) Has been cancelled
Automatic PR Merger / mergepal (push) Has been cancelled
CI Github Actions / Run Tests (push) Has been cancelled
Semgrep / Semgrep Workflow Security Scan (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,204 @@
|
||||
import pytest
|
||||
|
||||
import scipy.sparse
|
||||
import numpy as np
|
||||
|
||||
from rasa.utils.tensorflow.model_data import (
|
||||
ragged_array_to_ndarray,
|
||||
FeatureArray,
|
||||
RasaModelData,
|
||||
)
|
||||
from rasa.utils.tensorflow.data_generator import (
|
||||
RasaDataGenerator,
|
||||
RasaBatchDataGenerator,
|
||||
)
|
||||
|
||||
|
||||
def test_data_generator_with_increasing_batch_size(model_data: RasaModelData):
|
||||
epochs = 2
|
||||
|
||||
data_generator = RasaBatchDataGenerator(
|
||||
model_data,
|
||||
batch_size=[1, 2],
|
||||
epochs=epochs,
|
||||
batch_strategy="balanced",
|
||||
shuffle=True,
|
||||
)
|
||||
|
||||
expected_batch_sizes = [[1, 1, 1, 1, 1], [2, 2, 1]]
|
||||
|
||||
for _epoch in range(epochs):
|
||||
iterator = iter(data_generator)
|
||||
|
||||
assert len(data_generator) == len(expected_batch_sizes[_epoch])
|
||||
|
||||
for i in range(len(data_generator)):
|
||||
batch, _ = next(iterator)
|
||||
|
||||
assert len(batch) == 11
|
||||
assert len(batch[0]) == expected_batch_sizes[_epoch][i]
|
||||
|
||||
with pytest.raises(StopIteration):
|
||||
next(iterator)
|
||||
|
||||
data_generator.on_epoch_end()
|
||||
|
||||
|
||||
def test_data_generator_with_fixed_batch_size(model_data: RasaModelData):
|
||||
data_generator = RasaBatchDataGenerator(
|
||||
model_data, batch_size=2, epochs=1, batch_strategy="balanced", shuffle=True
|
||||
)
|
||||
|
||||
expected_batch_sizes = [2, 2, 1]
|
||||
|
||||
iterator = iter(data_generator)
|
||||
|
||||
assert len(data_generator) == len(expected_batch_sizes)
|
||||
|
||||
for i in range(len(data_generator)):
|
||||
batch, _ = next(iterator)
|
||||
assert len(batch) == 11
|
||||
assert len(batch[0]) == expected_batch_sizes[i]
|
||||
|
||||
with pytest.raises(StopIteration):
|
||||
next(iterator)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"incoming_data, expected_shape",
|
||||
[
|
||||
(FeatureArray(np.random.rand(7, 12), number_of_dimensions=2), (7, 12)),
|
||||
(FeatureArray(np.random.rand(7), number_of_dimensions=1), (7,)),
|
||||
(
|
||||
FeatureArray(
|
||||
ragged_array_to_ndarray(
|
||||
[
|
||||
np.random.rand(1, 10),
|
||||
np.random.rand(3, 10),
|
||||
np.random.rand(7, 10),
|
||||
np.random.rand(1, 10),
|
||||
]
|
||||
),
|
||||
number_of_dimensions=3,
|
||||
),
|
||||
(4, 7, 10),
|
||||
),
|
||||
(
|
||||
FeatureArray(
|
||||
ragged_array_to_ndarray(
|
||||
[
|
||||
ragged_array_to_ndarray(
|
||||
[
|
||||
np.random.rand(1, 10),
|
||||
np.random.rand(5, 10),
|
||||
np.random.rand(7, 10),
|
||||
]
|
||||
),
|
||||
ragged_array_to_ndarray(
|
||||
[
|
||||
np.random.rand(1, 10),
|
||||
np.random.rand(3, 10),
|
||||
np.random.rand(3, 10),
|
||||
np.random.rand(7, 10),
|
||||
]
|
||||
),
|
||||
np.array([np.random.rand(2, 10)]),
|
||||
]
|
||||
),
|
||||
number_of_dimensions=4,
|
||||
),
|
||||
(8, 7, 10),
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_pad_dense_data(incoming_data: FeatureArray, expected_shape: np.ndarray):
|
||||
padded_data = RasaDataGenerator._pad_dense_data(incoming_data)
|
||||
|
||||
assert padded_data.shape == expected_shape
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"incoming_data, expected_shape",
|
||||
[
|
||||
(
|
||||
FeatureArray(
|
||||
np.array([scipy.sparse.csr_matrix(np.random.randint(5, size=(7, 12)))]),
|
||||
number_of_dimensions=3,
|
||||
),
|
||||
[1, 7, 12],
|
||||
),
|
||||
(
|
||||
FeatureArray(
|
||||
np.array([scipy.sparse.csr_matrix(np.random.randint(5, size=(7,)))]),
|
||||
number_of_dimensions=2,
|
||||
),
|
||||
[1, 1, 7],
|
||||
),
|
||||
(
|
||||
FeatureArray(
|
||||
ragged_array_to_ndarray(
|
||||
[
|
||||
scipy.sparse.csr_matrix(np.random.randint(10, size=(1, 10))),
|
||||
scipy.sparse.csr_matrix(np.random.randint(10, size=(3, 10))),
|
||||
scipy.sparse.csr_matrix(np.random.randint(10, size=(7, 10))),
|
||||
scipy.sparse.csr_matrix(np.random.randint(10, size=(1, 10))),
|
||||
]
|
||||
),
|
||||
number_of_dimensions=3,
|
||||
),
|
||||
(4, 7, 10),
|
||||
),
|
||||
(
|
||||
FeatureArray(
|
||||
ragged_array_to_ndarray(
|
||||
[
|
||||
ragged_array_to_ndarray(
|
||||
[
|
||||
scipy.sparse.csr_matrix(
|
||||
np.random.randint(10, size=(1, 10))
|
||||
),
|
||||
scipy.sparse.csr_matrix(
|
||||
np.random.randint(10, size=(5, 10))
|
||||
),
|
||||
scipy.sparse.csr_matrix(
|
||||
np.random.randint(10, size=(7, 10))
|
||||
),
|
||||
]
|
||||
),
|
||||
ragged_array_to_ndarray(
|
||||
[
|
||||
scipy.sparse.csr_matrix(
|
||||
np.random.randint(10, size=(1, 10))
|
||||
),
|
||||
scipy.sparse.csr_matrix(
|
||||
np.random.randint(10, size=(3, 10))
|
||||
),
|
||||
scipy.sparse.csr_matrix(
|
||||
np.random.randint(10, size=(1, 10))
|
||||
),
|
||||
scipy.sparse.csr_matrix(
|
||||
np.random.randint(10, size=(7, 10))
|
||||
),
|
||||
]
|
||||
),
|
||||
ragged_array_to_ndarray(
|
||||
[
|
||||
scipy.sparse.csr_matrix(
|
||||
np.random.randint(10, size=(2, 10))
|
||||
)
|
||||
]
|
||||
),
|
||||
]
|
||||
),
|
||||
number_of_dimensions=4,
|
||||
),
|
||||
(8, 7, 10),
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_scipy_matrix_to_values(
|
||||
incoming_data: FeatureArray, expected_shape: np.ndarray
|
||||
):
|
||||
indices, data, shape = RasaDataGenerator._scipy_matrix_to_values(incoming_data)
|
||||
|
||||
assert np.all(shape == expected_shape)
|
||||
Reference in New Issue
Block a user