repo_id stringclasses 409
values | prefix large_stringlengths 34 36.3k | target large_stringlengths 1 498 | assertion_type stringclasses 31
values | difficulty stringclasses 8
values | test_file stringlengths 10 121 | test_function stringlengths 1 104 | test_class stringlengths 0 51 | lineno int32 2 11.3k | commit_idx int32 |
|---|---|---|---|---|---|---|---|---|---|
explosion/thinc | from functools import partial
import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import Linear, NumpyOps, Relu, chain
def nB(request):
return request.param
def nI(request):
return request.param
def nH(request):
return request.param
def nO(request):
return request.p... | (nO,) | assert | collection | thinc/tests/layers/test_feed_forward.py | test_models_have_shape | 78 | null | |
explosion/thinc | import timeit
import numpy
import pytest
from thinc.api import LSTM, NumpyOps, Ops, PyTorchLSTM, fix_random_seed, with_padded
from thinc.compat import has_torch
def nI(request):
return request.param
def nO(request):
return request.param
@pytest.mark.parametrize("ops", [Ops(), NumpyOps()])
@pytest.mark.para... | (2, 1, 1, nO) | assert | collection | thinc/tests/layers/test_lstm.py | test_LSTM_init_with_sizes | 59 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import (
PyTorchWrapper_v2,
TorchScriptWrapper_v1,
pytorch_to_torchscript_wrapper,
)
from thinc.compat import has_torch, torch
@pytest.mark.skipif(not has_torch, reason="needs PyTorch")
@pytest.mark.parametrize("nN,nI,nO", [(2, 3, 4)])
def test_pytorch_script(nN, ... | Y_script) | assert_* | variable | thinc/tests/layers/test_torchscriptwrapper.py | test_pytorch_script | 22 | null | |
explosion/thinc | import numpy
import pytest
from hypothesis import given, settings
from hypothesis.strategies import composite, integers, lists
from numpy.testing import assert_allclose
from thinc.layers import Embed
from thinc.layers.uniqued import uniqued
ROWS = 10
def lists_of_integers(draw, columns=2, lo=0, hi=ROWS - 1):
# W... | [True, True] | assert | collection | thinc/tests/layers/test_uniqued.py | test_uniqued_calls_init | 46 | null | |
explosion/thinc | from thinc.api import (
compounding,
constant,
constant_then,
cyclic_triangular,
decaying,
slanted_triangular,
warmup_linear,
)
def test_slanted_triangular_rate():
rates = slanted_triangular(1.0, 20.0, ratio=10)
rate0 = next(rates)
assert rate0 < 1.0
rate1 = next(rates)
... | rate3 | assert | variable | thinc/tests/test_schedules.py | test_slanted_triangular_rate | 42 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import (
Adam,
ArgsKwargs,
Linear,
Model,
TensorFlowWrapper,
get_current_ops,
keras_subclass,
tensorflow2xp,
xp2tensorflow,
)
from thinc.compat import has_cupy_gpu, has_tensorflow
from thinc.util import to_categorical
from ..util import che... | summary | assert | variable | thinc/tests/layers/test_tensorflow_wrapper.py | test_tensorflow_wrapper_print_summary | 313 | null | |
explosion/thinc | import numpy
import numpy.testing
import pytest
from thinc.api import (
Linear,
Model,
NumpyOps,
noop,
with_array,
with_array2d,
with_getitem,
with_list,
with_padded,
with_ragged,
)
from thinc.types import Padded, Ragged
from ..util import get_data_checker
def shapes(request):... | outputs[i]) | assert_* | complex_expr | thinc/tests/layers/test_with_transforms.py | check_transform_doesnt_change_noop_values | 175 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import (
SGD,
ArgsKwargs,
CupyOps,
Linear,
MPSOps,
NumpyOps,
PyTorchWrapper,
PyTorchWrapper_v2,
PyTorchWrapper_v3,
Relu,
chain,
get_current_ops,
torch2xp,
use_ops,
xp2torch,
)
from thinc.backends import context_pools
... | (nN, nO) | assert | collection | thinc/tests/layers/test_pytorch_wrapper.py | test_pytorch_wrapper | 91 | null | |
explosion/thinc | import contextlib
import shutil
import tempfile
from pathlib import Path
import numpy
import pytest
from thinc.api import ArgsKwargs, Linear, Padded, Ragged
from thinc.util import has_cupy, is_cupy_array, is_numpy_array
def make_tempdir():
d = Path(tempfile.mkdtemp())
yield d
shutil.rmtree(str(d))
def g... | Ragged(*Y)) | assert_* | func_call | thinc/tests/util.py | assert_ragged_data_match | 91 | null | |
explosion/thinc | from unittest.mock import MagicMock
import numpy
import pytest
from hypothesis import given, settings
from numpy.testing import assert_allclose
from thinc.api import SGD, Dropout, Linear, chain
from ..strategies import arrays_OI_O_BI
from ..util import get_model, get_shape
def model():
model = Linear()
retu... | 0.0 | assert | numeric_literal | thinc/tests/layers/test_linear.py | test_update | 222 | null | |
explosion/thinc | import timeit
import numpy
import pytest
from thinc.api import LSTM, NumpyOps, Ops, PyTorchLSTM, fix_random_seed, with_padded
from thinc.compat import has_torch
def nI(request):
return request.param
def nO(request):
return request.param
@pytest.mark.parametrize("ops", [Ops(), NumpyOps()])
@pytest.mark.para... | None | assert | none_literal | thinc/tests/layers/test_lstm.py | test_LSTM_init_with_sizes | 48 | null | |
explosion/thinc | import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import (
Dropout,
Linear,
Model,
NumpyOps,
add,
clone,
concatenate,
map_list,
noop,
)
from thinc.layers import chain, tuplify
def nB(request):
return request.param
def nI(request):
return r... | 5 | assert | numeric_literal | thinc/tests/layers/test_combinators.py | test_clone_gives_distinct_ids | 211 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import reduce_first, reduce_last, reduce_max, reduce_mean, reduce_sum
from thinc.types import Ragged
def Xs():
seqs = [numpy.zeros((10, 8), dtype="f"), numpy.zeros((4, 8), dtype="f")]
for x in seqs:
x[0] = 1
x[1] = 2 # so max != first
x[-1] = ... | Xs[1].mean() | assert | func_call | thinc/tests/layers/test_reduce.py | test_reduce_mean | 92 | null | |
explosion/thinc | import inspect
import platform
from typing import Tuple, cast
import numpy
import pytest
from hypothesis import given, settings
from hypothesis.strategies import composite, integers
from numpy.testing import assert_allclose
from packaging.version import Version
from thinc.api import (
LSTM,
CupyOps,
Numpy... | None | assert | none_literal | thinc/tests/backends/test_ops.py | test_custom_kernel_compilation | 1,603 | null | |
explosion/thinc | from thinc.api import (
compounding,
constant,
constant_then,
cyclic_triangular,
decaying,
slanted_triangular,
warmup_linear,
)
def test_decaying_rate():
rates = decaying(0.001, 1e-4)
rate = next(rates)
assert rate == 0.001
next_rate = next(rates)
assert next_rate < rate... | 0 | assert | numeric_literal | thinc/tests/test_schedules.py | test_decaying_rate | 18 | null | |
explosion/thinc | import numpy
from thinc.api import HashEmbed
def test_init():
model = HashEmbed(64, 1000).initialize()
assert model.get_dim("nV") == 1000
assert model.get_dim("nO") == | 64 | assert | numeric_literal | thinc/tests/layers/test_hash_embed.py | test_init | 9 | null | |
explosion/thinc | import timeit
import numpy
import pytest
from thinc.api import LSTM, NumpyOps, Ops, PyTorchLSTM, fix_random_seed, with_padded
from thinc.compat import has_torch
def nI(request):
return request.param
def nO(request):
return request.param
def test_list2padded():
ops = NumpyOps()
seqs = [numpy.zeros((... | 3 | assert | numeric_literal | thinc/tests/layers/test_lstm.py | test_list2padded | 27 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import reduce_first, reduce_last, reduce_max, reduce_mean, reduce_sum
from thinc.types import Ragged
def Xs():
seqs = [numpy.zeros((10, 8), dtype="f"), numpy.zeros((4, 8), dtype="f")]
for x in seqs:
x[0] = 1
x[1] = 2 # so max != first
x[-1] = ... | Xs[0].mean() | assert | func_call | thinc/tests/layers/test_reduce.py | test_reduce_mean | 90 | null | |
explosion/thinc | import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import (
Dropout,
Linear,
Model,
NumpyOps,
add,
clone,
concatenate,
map_list,
noop,
)
from thinc.layers import chain, tuplify
def nB(request):
return request.param
def nI(request):
return r... | 6 | assert | numeric_literal | thinc/tests/layers/test_combinators.py | test_clone_gives_distinct_ids | 216 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import Optimizer, registry
def _test_schedule_valid():
while True:
yield 0.456
def _test_schedule_invalid():
yield from []
def schedule_valid(request):
# Use lambda to prevent iterator from being consumed by first test
r_func, r1, r2, r3 = request.pa... | lr_next2 | assert | variable | thinc/tests/test_optimizers.py | test_optimizer_schedules_from_config | 62 | null | |
explosion/thinc | import numpy
import numpy.testing
import pytest
from thinc.api import (
Linear,
Model,
NumpyOps,
noop,
with_array,
with_array2d,
with_getitem,
with_list,
with_padded,
with_ragged,
)
from thinc.types import Padded, Ragged
from ..util import get_data_checker
def shapes(request):... | outputs) | assert_* | variable | thinc/tests/layers/test_with_transforms.py | check_transform_doesnt_change_noop_values | 178 | null | |
explosion/thinc | import numpy
import pytest
from hypothesis import given
from thinc.api import Padded, Ragged, get_width
from thinc.types import ArgsKwargs
from thinc.util import (
convert_recursive,
get_array_module,
is_cupy_array,
is_numpy_array,
to_categorical,
)
from . import strategies
ALL_XP = [numpy]
@pyt... | ValueError) | pytest.raises | variable | thinc/tests/test_util.py | test_get_width_fail | 52 | null | |
explosion/thinc | import numpy
import pytest
from hypothesis import given
from thinc.api import Padded, Ragged, get_width
from thinc.types import ArgsKwargs
from thinc.util import (
convert_recursive,
get_array_module,
is_cupy_array,
is_numpy_array,
to_categorical,
)
from . import strategies
ALL_XP = [numpy]
@giv... | expected_shape | assert | variable | thinc/tests/test_util.py | test_to_categorical | 106 | null | |
explosion/thinc | from unittest.mock import MagicMock
import numpy
import pytest
from hypothesis import given, settings
from numpy.testing import assert_allclose
from thinc.api import SGD, Dropout, Linear, chain
from ..strategies import arrays_OI_O_BI
from ..util import get_model, get_shape
def model():
model = Linear()
retu... | 2 | assert | numeric_literal | thinc/tests/layers/test_linear.py | test_init | 149 | null | |
explosion/thinc | import pytest
import srsly
from thinc.api import (
Linear,
Maxout,
Model,
Shim,
chain,
deserialize_attr,
serialize_attr,
with_array,
)
def linear():
return Linear(5, 3)
def test_simple_model_roundtrip_bytes_length():
"""Ensure that serialization of non-initialized weight matri... | len(data2) | assert | func_call | thinc/tests/test_serialize.py | test_simple_model_roundtrip_bytes_length | 76 | null | |
explosion/thinc | import numpy
import pytest
from hypothesis import given
from thinc.api import Padded, Ragged, get_width
from thinc.types import ArgsKwargs
from thinc.util import (
convert_recursive,
get_array_module,
is_cupy_array,
is_numpy_array,
to_categorical,
)
from . import strategies
ALL_XP = [numpy]
@giv... | (2, 3) | assert | collection | thinc/tests/test_util.py | test_to_categorical | 83 | null | |
explosion/thinc | from typing import List, Optional
import numpy
import pytest
import srsly
from numpy.testing import assert_almost_equal
from thinc.api import Dropout, Model, NumpyOps, registry, with_padded
from thinc.backends import NumpyOps
from thinc.compat import has_torch
from thinc.types import Array2d, Floats2d, FloatsXd, Padd... | data) | assert_* | variable | thinc/tests/layers/test_layers_api.py | test_dropout | 183 | null | |
explosion/thinc | from typing import List, Optional
import numpy
import pytest
import srsly
from numpy.testing import assert_almost_equal
from thinc.api import Dropout, Model, NumpyOps, registry, with_padded
from thinc.backends import NumpyOps
from thinc.compat import has_torch
from thinc.types import Array2d, Floats2d, FloatsXd, Padd... | Y.ndim | assert | complex_expr | thinc/tests/layers/test_layers_api.py | assert_data_match | 42 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import reduce_first, reduce_last, reduce_max, reduce_mean, reduce_sum
from thinc.types import Ragged
def Xs():
seqs = [numpy.zeros((10, 8), dtype="f"), numpy.zeros((4, 8), dtype="f")]
for x in seqs:
x[0] = 1
x[1] = 2 # so max != first
x[-1] = ... | list(Xs[1][-1]) | assert | func_call | thinc/tests/layers/test_reduce.py | test_reduce_last | 61 | null | |
explosion/thinc | import pytest
import srsly
from thinc.api import (
Linear,
Maxout,
Model,
Shim,
chain,
deserialize_attr,
serialize_attr,
with_array,
)
def linear():
return Linear(5, 3)
def test_serialize_model_shims_roundtrip_bytes():
fwd = lambda model, X, is_train: (X, lambda dY: dY)
te... | "shimdata" | assert | string_literal | thinc/tests/test_serialize.py | test_serialize_model_shims_roundtrip_bytes | 137 | null | |
explosion/thinc | import numpy
from thinc.backends._param_server import ParamServer
def test_param_server_init():
array = numpy.zeros((5,), dtype="f")
params = {("a", 1): array, ("b", 2): array}
grads = {("a", 1): array, ("c", 3): array}
ps = ParamServer(params, grads)
assert ps.param_keys == (("a", 1), ("b", 2))
... | (("a", 1),) | assert | collection | thinc/tests/backends/test_mem.py | test_param_server_init | 12 | null | |
explosion/thinc | import contextlib
import shutil
import tempfile
from pathlib import Path
import numpy
import pytest
from thinc.api import ArgsKwargs, Linear, Padded, Ragged
from thinc.util import has_cupy, is_cupy_array, is_numpy_array
def make_tempdir():
d = Path(tempfile.mkdtemp())
yield d
shutil.rmtree(str(d))
def g... | Y.shape[0] | assert | complex_expr | thinc/tests/util.py | assert_arrays_match | 53 | null | |
explosion/thinc | from unittest.mock import MagicMock
import numpy
import pytest
from hypothesis import given, settings
from numpy.testing import assert_allclose
from thinc.api import SGD, Dropout, Linear, chain
from ..strategies import arrays_OI_O_BI
from ..util import get_model, get_shape
def model():
model = Linear()
retu... | gradient.shape | assert | complex_expr | thinc/tests/layers/test_linear.py | sgd | 61 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import reduce_first, reduce_last, reduce_max, reduce_mean, reduce_sum
from thinc.types import Ragged
def Xs():
seqs = [numpy.zeros((10, 8), dtype="f"), numpy.zeros((4, 8), dtype="f")]
for x in seqs:
x[0] = 1
x[1] = 2 # so max != first
x[-1] = ... | list(Xs[1][1]) | assert | func_call | thinc/tests/layers/test_reduce.py | test_reduce_max | 75 | null | |
explosion/thinc | import numpy
import pytest
from hypothesis import given
from thinc.api import Padded, Ragged, get_width
from thinc.types import ArgsKwargs
from thinc.util import (
convert_recursive,
get_array_module,
is_cupy_array,
is_numpy_array,
to_categorical,
)
from . import strategies
ALL_XP = [numpy]
def ... | "FOO" | assert | string_literal | thinc/tests/test_util.py | test_convert_recursive | 160 | null | |
explosion/thinc | import inspect
import platform
from typing import Tuple, cast
import numpy
import pytest
from hypothesis import given, settings
from hypothesis.strategies import composite, integers
from numpy.testing import assert_allclose
from packaging.version import Version
from thinc.api import (
LSTM,
CupyOps,
Numpy... | 1 | assert | numeric_literal | thinc/tests/backends/test_ops.py | test_alloc | 199 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import Optimizer, registry
def _test_schedule_valid():
while True:
yield 0.456
def _test_schedule_invalid():
yield from []
def schedule_valid(request):
# Use lambda to prevent iterator from being consumed by first test
r_func, r1, r2, r3 = request.pa... | learn_rate | assert | variable | thinc/tests/test_optimizers.py | test_optimizers_from_config | 53 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import (
SGD,
ArgsKwargs,
CupyOps,
Linear,
MPSOps,
NumpyOps,
PyTorchWrapper,
PyTorchWrapper_v2,
PyTorchWrapper_v3,
Relu,
chain,
get_current_ops,
torch2xp,
use_ops,
xp2torch,
)
from thinc.backends import context_pools
... | prev | assert | variable | thinc/tests/layers/test_pytorch_wrapper.py | check_learns_zero_output | 65 | null | |
explosion/thinc | from thinc.api import (
compounding,
constant,
constant_then,
cyclic_triangular,
decaying,
slanted_triangular,
warmup_linear,
)
def test_constant_then_schedule():
rates = constant_then(1.0, 2, [100, 200])
assert next(rates) == 1.0
assert next(rates) == 1.0
assert next(rates)... | 200 | assert | numeric_literal | thinc/tests/test_schedules.py | test_constant_then_schedule | 50 | null | |
explosion/thinc | import platform
import threading
import time
from collections import Counter
import numpy
import pytest
from thinc.api import (
Adam,
CupyOps,
Dropout,
Linear,
Model,
Relu,
Shim,
Softmax,
chain,
change_attr_values,
concatenate,
set_dropout_rate,
use_ops,
with_de... | 0.0 | assert | numeric_literal | thinc/tests/model/test_model.py | test_set_dropout | 229 | null | |
explosion/thinc | from typing import List, Optional
import numpy
import pytest
import srsly
from numpy.testing import assert_almost_equal
from thinc.api import Dropout, Model, NumpyOps, registry, with_padded
from thinc.backends import NumpyOps
from thinc.compat import has_torch
from thinc.types import Array2d, Floats2d, FloatsXd, Padd... | model.get_dim("nO") | assert | func_call | thinc/tests/layers/test_layers_api.py | test_layers_from_config | 156 | null | |
explosion/thinc | from typing import cast
import numpy
import pytest
from thinc.api import (
Adam,
ArgsKwargs,
Model,
MXNetWrapper,
Ops,
get_current_ops,
mxnet2xp,
xp2mxnet,
)
from thinc.compat import has_cupy_gpu, has_mxnet
from thinc.types import Array1d, Array2d, IntsXd
from thinc.util import to_cate... | None | assert | none_literal | thinc/tests/layers/test_mxnet_wrapper.py | test_mxnet_wrapper_built_model | 105 | null | |
explosion/thinc | from typing import List
from thinc.api import Model, with_flatten_v2
INPUT = [[1, 2, 3], [4, 5], [], [6, 7, 8]]
INPUT_FLAT = [1, 2, 3, 4, 5, 6, 7, 8]
OUTPUT = [[2, 3, 4], [5, 6], [], [7, 8, 9]]
BACKPROP_OUTPUT = [[3, 4, 5], [6, 7], [], [8, 9, 10]]
def _memoize_input() -> Model[List[int], List[int]]:
return Model... | INPUT_FLAT | assert | variable | thinc/tests/layers/test_with_flatten.py | test_with_flatten | 30 | null | |
explosion/thinc | import inspect
import pickle
from types import GeneratorType
from typing import Any, Callable, Dict, Iterable, List, Optional, Union
import catalogue
import numpy
import pytest
import thinc.config
from thinc.api import Config, Model, NumpyOps, RAdam
from thinc.config import ConfigValidationError
from thinc.types impo... | optimizer.schedules | assert | complex_expr | thinc/tests/test_config.py | test_objects_from_config | 187 | null | |
explosion/thinc | import contextlib
import shutil
import tempfile
from pathlib import Path
import numpy
import pytest
from thinc.api import ArgsKwargs, Linear, Padded, Ragged
from thinc.util import has_cupy, is_cupy_array, is_numpy_array
def make_tempdir():
d = Path(tempfile.mkdtemp())
yield d
shutil.rmtree(str(d))
def g... | Padded(*Y)) | assert_* | func_call | thinc/tests/util.py | assert_padded_data_match | 87 | null | |
explosion/thinc | import numpy
import pytest
from thinc import registry
from thinc.api import (
CategoricalCrossentropy,
CosineDistance,
L2Distance,
SequenceCategoricalCrossentropy,
)
scores0 = numpy.zeros((3, 3), dtype="f")
labels0 = numpy.asarray([0, 1, 1], dtype="i")
guesses1 = numpy.asarray([[0.1, 0.5, 0.6], [0.4,... | [] | assert | collection | thinc/tests/test_loss.py | test_loss | 36 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import reduce_first, reduce_last, reduce_max, reduce_mean, reduce_sum
from thinc.types import Ragged
def Xs():
seqs = [numpy.zeros((10, 8), dtype="f"), numpy.zeros((4, 8), dtype="f")]
for x in seqs:
x[0] = 1
x[1] = 2 # so max != first
x[-1] = ... | ValueError) | pytest.raises | variable | thinc/tests/layers/test_reduce.py | test_size_mismatch | 121 | null | |
explosion/thinc | from typing import List, Optional
import numpy
import pytest
import srsly
from numpy.testing import assert_almost_equal
from thinc.api import Dropout, Model, NumpyOps, registry, with_padded
from thinc.backends import NumpyOps
from thinc.compat import has_torch
from thinc.types import Array2d, Floats2d, FloatsXd, Padd... | Y.data.ndim | assert | complex_expr | thinc/tests/layers/test_layers_api.py | assert_data_match | 45 | null | |
explosion/thinc | import os
import re
import shutil
import sys
from pathlib import Path
import pytest
mypy = pytest.importorskip("mypy")
GENERATE = False
cases = [
("mypy-plugin.ini", "success_plugin.py", "success-plugin.txt"),
("mypy-plugin.ini", "fail_plugin.py", "fail-plugin.txt"),
("mypy-default.ini", "success_no_plu... | expected_out.strip() | assert | func_call | thinc/tests/mypy/test_mypy.py | test_mypy_results | 78 | null | |
explosion/thinc | from functools import partial
import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import Linear, NumpyOps, Relu, chain
def nB(request):
return request.param
def nI(request):
return request.param
def nH(request):
return request.param
def nO(request):
return request.p... | None | assert | none_literal | thinc/tests/layers/test_feed_forward.py | test_infer_output_shape | 90 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import reduce_first, reduce_last, reduce_max, reduce_mean, reduce_sum
from thinc.types import Ragged
def Xs():
seqs = [numpy.zeros((10, 8), dtype="f"), numpy.zeros((4, 8), dtype="f")]
for x in seqs:
x[0] = 1
x[1] = 2 # so max != first
x[-1] = ... | list(Xs[1][0]) | assert | func_call | thinc/tests/layers/test_reduce.py | test_reduce_first | 47 | null | |
explosion/thinc | import inspect
import platform
from typing import Tuple, cast
import numpy
import pytest
from hypothesis import given, settings
from hypothesis.strategies import composite, integers
from numpy.testing import assert_allclose
from packaging.version import Version
from thinc.api import (
LSTM,
CupyOps,
Numpy... | shape | assert | variable | thinc/tests/backends/test_ops.py | test_get_dropout_not_empty | 231 | null | |
explosion/thinc | import pytest
import srsly
from thinc.api import (
Linear,
Maxout,
Model,
Shim,
chain,
deserialize_attr,
serialize_attr,
with_array,
)
def linear():
return Linear(5, 3)
def test_simple_model_roundtrip_bytes():
model = Maxout(5, 10, nP=2).initialize()
b = model.get_param("b... | 1 | assert | numeric_literal | thinc/tests/test_serialize.py | test_simple_model_roundtrip_bytes | 63 | null | |
explosion/thinc | import pytest
import srsly
from thinc.api import (
Linear,
Maxout,
Model,
Shim,
chain,
deserialize_attr,
serialize_attr,
with_array,
)
def linear():
return Linear(5, 3)
def test_simple_model_roundtrip_bytes_serializable_attrs():
fwd = lambda model, X, is_train: (X, lambda dY: ... | b"foo" | assert | string_literal | thinc/tests/test_serialize.py | test_simple_model_roundtrip_bytes_serializable_attrs | 83 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import reduce_first, reduce_last, reduce_max, reduce_mean, reduce_sum
from thinc.types import Ragged
def Xs():
seqs = [numpy.zeros((10, 8), dtype="f"), numpy.zeros((4, 8), dtype="f")]
for x in seqs:
x[0] = 1
x[1] = 2 # so max != first
x[-1] = ... | Xs[0][:, 0].sum() | assert | func_call | thinc/tests/layers/test_reduce.py | test_reduce_sum | 105 | null | |
explosion/thinc | import contextlib
import shutil
import tempfile
from pathlib import Path
import numpy
import pytest
from thinc.api import ArgsKwargs, Linear, Padded, Ragged
from thinc.util import has_cupy, is_cupy_array, is_numpy_array
def make_tempdir():
d = Path(tempfile.mkdtemp())
yield d
shutil.rmtree(str(d))
def g... | n_args | assert | variable | thinc/tests/util.py | check_input_converters | 96 | null | |
explosion/thinc | import inspect
import platform
from typing import Tuple, cast
import numpy
import pytest
from hypothesis import given, settings
from hypothesis.strategies import composite, integers
from numpy.testing import assert_allclose
from packaging.version import Version
from thinc.api import (
LSTM,
CupyOps,
Numpy... | dtype | assert | variable | thinc/tests/backends/test_ops.py | test_maxout | 286 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import (
Adam,
ArgsKwargs,
Linear,
Model,
TensorFlowWrapper,
get_current_ops,
keras_subclass,
tensorflow2xp,
xp2tensorflow,
)
from thinc.compat import has_cupy_gpu, has_tensorflow
from thinc.util import to_categorical
from ..util import che... | "" | assert | string_literal | thinc/tests/layers/test_tensorflow_wrapper.py | test_tensorflow_wrapper_built_model | 101 | null | |
explosion/thinc | import pytest
import srsly
from thinc.api import (
Linear,
Maxout,
Model,
Shim,
chain,
deserialize_attr,
serialize_attr,
with_array,
)
def linear():
return Linear(5, 3)
def test_simple_model_roundtrip_bytes_length():
"""Ensure that serialization of non-initialized weight matri... | data2 | assert | variable | thinc/tests/test_serialize.py | test_simple_model_roundtrip_bytes_length | 75 | null | |
explosion/thinc | import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.types import Pairs, Ragged
def ragged():
data = numpy.zeros((20, 4), dtype="f")
lengths = numpy.array([4, 2, 8, 1, 4], dtype="i")
data[0] = 0
data[1] = 1
data[2] = 2
data[3] = 3
data[4] = 4
data[5] = 5
... | ragged.data[4:6]) | assert_* | complex_expr | thinc/tests/test_indexing.py | test_ragged_simple_index | 42 | null | |
explosion/thinc | import pytest
import srsly
from thinc.api import (
Linear,
Maxout,
Model,
Shim,
chain,
deserialize_attr,
serialize_attr,
with_array,
)
def linear():
return Linear(5, 3)
def test_serialize_model_shims_roundtrip_bytes():
fwd = lambda model, X, is_train: (X, lambda dY: dY)
te... | ValueError) | pytest.raises | variable | thinc/tests/test_serialize.py | test_serialize_model_shims_roundtrip_bytes | 139 | null | |
explosion/thinc | import inspect
import pickle
from types import GeneratorType
from typing import Any, Callable, Dict, Iterable, List, Optional, Union
import catalogue
import numpy
import pytest
import thinc.config
from thinc.api import Config, Model, NumpyOps, RAdam
from thinc.config import ConfigValidationError
from thinc.types impo... | "transformed_model" | assert | string_literal | thinc/tests/test_config.py | test_handle_generic_model_type | 203 | null | |
explosion/thinc | from thinc.api import (
compounding,
constant,
constant_then,
cyclic_triangular,
decaying,
slanted_triangular,
warmup_linear,
)
def test_compounding_rate():
rates = compounding(1, 16, 1.01)
rate0 = next(rates)
assert rate0 == 1.0
rate1 = next(rates)
rate2 = next(rates)
... | rate2 - rate1 | assert | complex_expr | thinc/tests/test_schedules.py | test_compounding_rate | 30 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import (
Adam,
ArgsKwargs,
Linear,
Model,
TensorFlowWrapper,
get_current_ops,
keras_subclass,
tensorflow2xp,
xp2tensorflow,
)
from thinc.compat import has_cupy_gpu, has_tensorflow
from thinc.util import to_categorical
from ..util import che... | None | assert | none_literal | thinc/tests/layers/test_tensorflow_wrapper.py | test_tensorflow_wrapper_built_model | 99 | null | |
explosion/thinc | from thinc.api import (
compounding,
constant,
constant_then,
cyclic_triangular,
decaying,
slanted_triangular,
warmup_linear,
)
def test_constant_then_schedule():
rates = constant_then(1.0, 2, [100, 200])
assert next(rates) == 1.0
assert next(rates) == 1.0
assert next(rates... | 100 | assert | numeric_literal | thinc/tests/test_schedules.py | test_constant_then_schedule | 49 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import Optimizer, registry
def _test_schedule_valid():
while True:
yield 0.456
def _test_schedule_invalid():
yield from []
def schedule_valid(request):
# Use lambda to prevent iterator from being consumed by first test
r_func, r1, r2, r3 = request.pa... | lr_next1 | assert | variable | thinc/tests/test_optimizers.py | test_optimizer_schedules_from_config | 60 | null | |
explosion/thinc | import contextlib
import shutil
import tempfile
from pathlib import Path
import numpy
import pytest
from thinc.api import ArgsKwargs, Linear, Padded, Ragged
from thinc.util import has_cupy, is_cupy_array, is_numpy_array
def make_tempdir():
d = Path(tempfile.mkdtemp())
yield d
shutil.rmtree(str(d))
def g... | Y.dtype | assert | complex_expr | thinc/tests/util.py | assert_arrays_match | 51 | null | |
explosion/thinc | from typing import List, Optional
import numpy
import pytest
import srsly
from numpy.testing import assert_almost_equal
from thinc.api import Dropout, Model, NumpyOps, registry, with_padded
from thinc.backends import NumpyOps
from thinc.compat import has_torch
from thinc.types import Array2d, Floats2d, FloatsXd, Padd... | in_data) | assert_* | variable | thinc/tests/layers/test_layers_api.py | test_layers_with_residual | 175 | null | |
explosion/thinc | import numpy
import pytest
from hypothesis import given, settings
from hypothesis.strategies import composite, integers, lists
from numpy.testing import assert_allclose
from thinc.layers import Embed
from thinc.layers.uniqued import uniqued
ROWS = 10
def lists_of_integers(draw, columns=2, lo=0, hi=ROWS - 1):
# W... | dXu) | assert_* | variable | thinc/tests/layers/test_uniqued.py | test_uniqued_doesnt_change_result | 58 | null | |
explosion/thinc | import numpy
import pytest
from thinc.layers import premap_ids, remap_ids, remap_ids_v2
def keys():
return numpy.array([4, 2, 6, 1, 8, 7, 9, 3, 30])
def mapper(keys):
return {int(k): int(v) for v, k in enumerate(keys)}
def test_remap_premap_eq(keys, mapper):
remap = remap_ids(mapper, default=99)
rem... | values2) | assert_* | variable | thinc/tests/layers/test_mappers.py | test_remap_premap_eq | 42 | null | |
explosion/thinc | import numpy
import numpy.testing
import pytest
from thinc.api import (
Linear,
Model,
NumpyOps,
noop,
with_array,
with_array2d,
with_getitem,
with_list,
with_padded,
with_ragged,
)
from thinc.types import Padded, Ragged
from ..util import get_data_checker
def shapes(request):... | d_inputs) | assert_* | variable | thinc/tests/layers/test_with_transforms.py | check_transform_doesnt_change_noop_values | 179 | null | |
explosion/thinc | import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.types import Pairs, Ragged
def ragged():
data = numpy.zeros((20, 4), dtype="f")
lengths = numpy.array([4, 2, 8, 1, 4], dtype="i")
data[0] = 0
data[1] = 1
data[2] = 2
data[3] = 3
data[4] = 4
data[5] = 5
... | ragged.lengths) | assert_* | complex_expr | thinc/tests/test_indexing.py | test_ragged_empty | 26 | null | |
explosion/thinc | import numpy
import numpy.testing
import pytest
from thinc.api import (
Linear,
Model,
NumpyOps,
noop,
with_array,
with_array2d,
with_getitem,
with_list,
with_padded,
with_ragged,
)
from thinc.types import Padded, Ragged
from ..util import get_data_checker
def shapes(request):... | len(data) | assert | func_call | thinc/tests/layers/test_with_transforms.py | test_with_getitem | 294 | null | |
explosion/thinc | import timeit
import numpy
import pytest
from thinc.api import LSTM, NumpyOps, Ops, PyTorchLSTM, fix_random_seed, with_padded
from thinc.compat import has_torch
def nI(request):
return request.param
def nO(request):
return request.param
@pytest.mark.parametrize("ops", [Ops(), NumpyOps()])
@pytest.mark.para... | numpy.vstack(Xs).shape | assert | func_call | thinc/tests/layers/test_lstm.py | test_BiLSTM_fwd_bwd_shapes | 96 | null | |
explosion/thinc | import numpy
import pytest
from thinc import registry
from thinc.api import (
CategoricalCrossentropy,
CosineDistance,
L2Distance,
SequenceCategoricalCrossentropy,
)
scores0 = numpy.zeros((3, 3), dtype="f")
labels0 = numpy.asarray([0, 1, 1], dtype="i")
guesses1 = numpy.asarray([[0.1, 0.5, 0.6], [0.4,... | 5) | pytest.approx | numeric_literal | thinc/tests/test_loss.py | test_L2 | 252 | null | |
explosion/thinc | import random
import pytest
from thinc.api import (
Adam,
HashEmbed,
Model,
Relu,
Softmax,
chain,
expand_window,
strings2arrays,
with_array,
)
def ancora():
pytest.importorskip("ml_datasets")
import ml_datasets
return ml_datasets.ud_ancora_pos_tags()
def create_embed... | losses[0] | assert | complex_expr | thinc/tests/layers/test_basic_tagger.py | test_small_end_to_end | 85 | null | |
explosion/thinc | import numpy
from thinc.api import HashEmbed
def test_init():
model = HashEmbed(64, 1000).initialize()
assert model.get_dim("nV") == 1000
assert model.get_dim("nO") == 64
assert model.get_param("E").shape == | (1000, 64) | assert | collection | thinc/tests/layers/test_hash_embed.py | test_init | 10 | null | |
explosion/thinc | import contextlib
import shutil
import tempfile
from pathlib import Path
import numpy
import pytest
from thinc.api import ArgsKwargs, Linear, Padded, Ragged
from thinc.util import has_cupy, is_cupy_array, is_numpy_array
def make_tempdir():
d = Path(tempfile.mkdtemp())
yield d
shutil.rmtree(str(d))
def g... | Y.lengths) | assert_* | complex_expr | thinc/tests/util.py | assert_paddeds_match | 78 | null | |
explosion/thinc | import numpy
import pytest
from hypothesis import given
from thinc.api import Padded, Ragged, get_width
from thinc.types import ArgsKwargs
from thinc.util import (
convert_recursive,
get_array_module,
is_cupy_array,
is_numpy_array,
to_categorical,
)
from . import strategies
ALL_XP = [numpy]
@pyt... | width | assert | variable | thinc/tests/test_util.py | test_get_width | 47 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import Optimizer, registry
def _test_schedule_valid():
while True:
yield 0.456
def _test_schedule_invalid():
yield from []
def schedule_valid(request):
# Use lambda to prevent iterator from being consumed by first test
r_func, r1, r2, r3 = request.pa... | ValueError) | pytest.raises | variable | thinc/tests/test_optimizers.py | test_optimizer_schedules_invalid | 82 | null | |
explosion/thinc | from functools import partial
import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import Linear, NumpyOps, Relu, chain
def nB(request):
return request.param
def nI(request):
return request.param
def nH(request):
return request.param
def nO(request):
return request.p... | model1.get_dim("nI") | assert | func_call | thinc/tests/layers/test_feed_forward.py | test_model_shape | 82 | null | |
explosion/thinc | import numpy
import pytest
from thinc import registry
from thinc.api import (
CategoricalCrossentropy,
CosineDistance,
L2Distance,
SequenceCategoricalCrossentropy,
)
scores0 = numpy.zeros((3, 3), dtype="f")
labels0 = numpy.asarray([0, 1, 1], dtype="i")
guesses1 = numpy.asarray([[0.1, 0.5, 0.6], [0.4,... | 0) | pytest.approx | numeric_literal | thinc/tests/test_loss.py | test_equality | 44 | null | |
explosion/thinc | import numpy
import pytest
from hypothesis import given
from thinc.api import Padded, Ragged, get_width
from thinc.types import ArgsKwargs
from thinc.util import (
convert_recursive,
get_array_module,
is_cupy_array,
is_numpy_array,
to_categorical,
)
from . import strategies
ALL_XP = [numpy]
def ... | ("FOO", [{"b": "FOO"}]) | assert | collection | thinc/tests/test_util.py | test_convert_recursive | 164 | null | |
explosion/thinc | from thinc.api import (
compounding,
constant,
constant_then,
cyclic_triangular,
decaying,
slanted_triangular,
warmup_linear,
)
def test_decaying_rate():
rates = decaying(0.001, 1e-4)
rate = next(rates)
assert rate == 0.001
next_rate = next(rates)
assert next_rate < rate... | next(rates) | assert | func_call | thinc/tests/test_schedules.py | test_decaying_rate | 19 | null | |
explosion/thinc | import numpy
import pytest
from hypothesis import given, settings
from hypothesis.strategies import composite, integers, lists
from numpy.testing import assert_allclose
from thinc.layers import Embed
from thinc.layers.uniqued import uniqued
ROWS = 10
def lists_of_integers(draw, columns=2, lo=0, hi=ROWS - 1):
# W... | [True] | assert | collection | thinc/tests/layers/test_uniqued.py | test_uniqued_calls_init | 43 | null | |
explosion/thinc | import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.types import Pairs, Ragged
def ragged():
data = numpy.zeros((20, 4), dtype="f")
lengths = numpy.array([4, 2, 8, 1, 4], dtype="i")
data[0] = 0
data[1] = 1
data[2] = 2
data[3] = 3
data[4] = 4
data[5] = 5
... | ragged.lengths[arr].sum() | assert | func_call | thinc/tests/test_indexing.py | test_ragged_array_index | 56 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import Optimizer, registry
def _test_schedule_valid():
while True:
yield 0.456
def _test_schedule_invalid():
yield from []
def schedule_valid(request):
# Use lambda to prevent iterator from being consumed by first test
r_func, r1, r2, r3 = request.pa... | 1.0 | assert | numeric_literal | thinc/tests/test_optimizers.py | test_optimizer_schedules_from_config | 66 | null | |
explosion/thinc | import contextlib
import shutil
import tempfile
from pathlib import Path
import numpy
import pytest
from thinc.api import ArgsKwargs, Linear, Padded, Ragged
from thinc.util import has_cupy, is_cupy_array, is_numpy_array
def make_tempdir():
d = Path(tempfile.mkdtemp())
yield d
shutil.rmtree(str(d))
def g... | Y.indices) | assert_* | complex_expr | thinc/tests/util.py | assert_paddeds_match | 79 | null | |
explosion/thinc | import numpy
import numpy.testing
import pytest
from thinc.api import (
Linear,
Model,
NumpyOps,
noop,
with_array,
with_array2d,
with_getitem,
with_list,
with_padded,
with_ragged,
)
from thinc.types import Padded, Ragged
from ..util import get_data_checker
def shapes(request):... | outputs.data) | assert_* | complex_expr | thinc/tests/layers/test_with_transforms.py | check_transform_doesnt_change_noop_values | 181 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import NumpyOps, Ragged, registry, strings2arrays
from ..util import get_data_checker
def shapes(request):
return request.param
def ops():
return NumpyOps()
def list_data(shapes):
return [numpy.zeros(shape, dtype="f") for shape in shapes]
def ragged_data(ops, ... | [] | assert | collection | thinc/tests/layers/test_transforms.py | test_strings2arrays | 79 | null | |
explosion/thinc | from functools import partial
import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import Linear, NumpyOps, Relu, chain
def nB(request):
return request.param
def nI(request):
return request.param
def nH(request):
return request.param
def nO(request):
return request.p... | (nH, nI) | assert | collection | thinc/tests/layers/test_feed_forward.py | test_models_have_shape | 75 | null | |
explosion/thinc | from unittest.mock import MagicMock
import numpy
import pytest
from hypothesis import given, settings
from numpy.testing import assert_allclose
from thinc.api import SGD, Dropout, Linear, chain
from ..strategies import arrays_OI_O_BI
from ..util import get_model, get_shape
def model():
model = Linear()
retu... | expected) | assert_* | variable | thinc/tests/layers/test_linear.py | test_predict_weights | 190 | null | |
explosion/thinc | import inspect
import platform
from typing import Tuple, cast
import numpy
import pytest
from hypothesis import given, settings
from hypothesis.strategies import composite, integers
from numpy.testing import assert_allclose
from packaging.version import Version
from thinc.api import (
LSTM,
CupyOps,
Numpy... | Yt) | assert_* | variable | thinc/tests/backends/test_ops.py | test_softmax_temperature | 776 | null | |
explosion/thinc | import platform
import threading
import time
from collections import Counter
import numpy
import pytest
from thinc.api import (
Adam,
CupyOps,
Dropout,
Linear,
Model,
Relu,
Shim,
Softmax,
chain,
change_attr_values,
concatenate,
set_dropout_rate,
use_ops,
with_de... | 0.2 | assert | numeric_literal | thinc/tests/model/test_model.py | test_set_dropout | 231 | null | |
explosion/thinc | import numpy
import pytest
from hypothesis import given
from thinc.api import Padded, Ragged, get_width
from thinc.types import ArgsKwargs
from thinc.util import (
convert_recursive,
get_array_module,
is_cupy_array,
is_numpy_array,
to_categorical,
)
from . import strategies
ALL_XP = [numpy]
def ... | {"a": ["x", "FOO"]} | assert | collection | thinc/tests/test_util.py | test_convert_recursive | 165 | null | |
explosion/thinc | import numpy
import pytest
from thinc.api import Optimizer, registry
def _test_schedule_valid():
while True:
yield 0.456
def _test_schedule_invalid():
yield from []
def schedule_valid(request):
# Use lambda to prevent iterator from being consumed by first test
r_func, r1, r2, r3 = request.pa... | lr_next3 | assert | variable | thinc/tests/test_optimizers.py | test_optimizer_schedules_from_config | 64 | null | |
explosion/thinc | import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.types import Pairs, Ragged
def ragged():
data = numpy.zeros((20, 4), dtype="f")
lengths = numpy.array([4, 2, 8, 1, 4], dtype="i")
data[0] = 0
data[1] = 1
data[2] = 2
data[3] = 3
data[4] = 4
data[5] = 5
... | (size, r.data.shape[1]) | assert | collection | thinc/tests/test_indexing.py | test_ragged_slice_index | 49 | null | |
explosion/thinc | import contextlib
import shutil
import tempfile
from pathlib import Path
import numpy
import pytest
from thinc.api import ArgsKwargs, Linear, Padded, Ragged
from thinc.util import has_cupy, is_cupy_array, is_numpy_array
def make_tempdir():
d = Path(tempfile.mkdtemp())
yield d
shutil.rmtree(str(d))
def g... | len(Y) | assert | func_call | thinc/tests/util.py | assert_lists_match | 60 | null | |
explosion/thinc | import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import (
Dropout,
Linear,
Model,
NumpyOps,
add,
clone,
concatenate,
map_list,
noop,
)
from thinc.layers import chain, tuplify
def nB(request):
return request.param
def nI(request):
return r... | 0 | assert | numeric_literal | thinc/tests/layers/test_combinators.py | test_clone_noop | 221 | null | |
explosion/thinc | from functools import partial
import numpy
import pytest
from numpy.testing import assert_allclose
from thinc.api import Linear, NumpyOps, Relu, chain
def nB(request):
return request.param
def nI(request):
return request.param
def nH(request):
return request.param
def nO(request):
return request.p... | model2.get_dim("nO") | assert | func_call | thinc/tests/layers/test_feed_forward.py | test_model_shape | 83 | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.