Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def my_train_split(ds, y):
# Return (corpus.train, corpus.valid) in case the network
# is fitted using net.fit(corpus.train).
return ds, skorch.dataset.Dataset(corpus.valid[:200], y=None)
def my_train_split(ds, y):
return ds, skorch.dataset.Dataset(corpus.valid[:200], y=None)
def uses_placeholder_y(ds):
"""If ``ds`` is a ``skorch.dataset.Dataset`` or a
``skorch.dataset.Dataset`` nested inside a
``torch.utils.data.Subset`` and uses
y as a placeholder, return ``True``."""
if isinstance(ds, torch.utils.data.Subset):
return uses_placeholder_y(ds.dataset)
return isinstance(ds, Dataset) and hasattr(ds, "y") and ds.y is None
def is_skorch_dataset(ds):
"""Checks if the supplied dataset is an instance of
``skorch.dataset.Dataset`` even when it is nested inside
``torch.util.data.Subset``."""
from skorch.dataset import Dataset
if isinstance(ds, Subset):
return is_skorch_dataset(ds.dataset)
return isinstance(ds, Dataset)