skorch

A scikit-learn compatible neural network library that wraps PyTorch

https://github.com/skorch-dev/skorch

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    2 of 67 committers (3.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.0%) to scientific vocabulary

Keywords

hacktoberfest huggingface machine-learning pytorch scikit-learn

Keywords from Contributors

cryptocurrency cryptography jax transformer closember qt neuroimaging
Last synced: 6 months ago · JSON representation ·

Repository

A scikit-learn compatible neural network library that wraps PyTorch

Basic Info
  • Host: GitHub
  • Owner: skorch-dev
  • License: bsd-3-clause
  • Language: Jupyter Notebook
  • Default Branch: master
  • Homepage:
  • Size: 11.9 MB
Statistics
  • Stars: 6,109
  • Watchers: 81
  • Forks: 403
  • Open Issues: 66
  • Releases: 18
Topics
hacktoberfest huggingface machine-learning pytorch scikit-learn
Created over 8 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License Citation

README.rst

.. image:: https://github.com/skorch-dev/skorch/blob/master/assets/skorch_bordered.svg
   :width: 30%

------------

|build| |coverage| |docs| |huggingface| |powered|

A scikit-learn compatible neural network library that wraps PyTorch.

.. |build| image:: https://github.com/skorch-dev/skorch/workflows/tests/badge.svg
    :alt: Test Status

.. |coverage| image:: https://github.com/skorch-dev/skorch/blob/master/assets/coverage.svg
    :alt: Test Coverage

.. |docs| image:: https://readthedocs.org/projects/skorch/badge/?version=latest
    :alt: Documentation Status
    :target: https://skorch.readthedocs.io/en/latest/?badge=latest

.. |huggingface| image:: https://github.com/skorch-dev/skorch/actions/workflows/test-hf-integration.yml/badge.svg
    :alt: Hugging Face Integration
    :target: https://github.com/skorch-dev/skorch/actions/workflows/test-hf-integration.yml

.. |powered| image:: https://github.com/skorch-dev/skorch/blob/master/assets/powered.svg
    :alt: Powered by
    :target: https://github.com/ottogroup/

=========
Resources
=========

- `Documentation `_
- `Source Code `_
- `Installation `_

========
Examples
========

To see more elaborate examples, look `here
`__.

.. code:: python

    import numpy as np
    from sklearn.datasets import make_classification
    from torch import nn
    from skorch import NeuralNetClassifier

    X, y = make_classification(1000, 20, n_informative=10, random_state=0)
    X = X.astype(np.float32)
    y = y.astype(np.int64)

    class MyModule(nn.Module):
        def __init__(self, num_units=10, nonlin=nn.ReLU()):
            super().__init__()

            self.dense0 = nn.Linear(20, num_units)
            self.nonlin = nonlin
            self.dropout = nn.Dropout(0.5)
            self.dense1 = nn.Linear(num_units, num_units)
            self.output = nn.Linear(num_units, 2)
            self.softmax = nn.Softmax(dim=-1)

        def forward(self, X, **kwargs):
            X = self.nonlin(self.dense0(X))
            X = self.dropout(X)
            X = self.nonlin(self.dense1(X))
            X = self.softmax(self.output(X))
            return X

    net = NeuralNetClassifier(
        MyModule,
        max_epochs=10,
        lr=0.1,
        # Shuffle training data on each epoch
        iterator_train__shuffle=True,
    )

    net.fit(X, y)
    y_proba = net.predict_proba(X)

In an `sklearn Pipeline `_:

.. code:: python

    from sklearn.pipeline import Pipeline
    from sklearn.preprocessing import StandardScaler

    pipe = Pipeline([
        ('scale', StandardScaler()),
        ('net', net),
    ])

    pipe.fit(X, y)
    y_proba = pipe.predict_proba(X)

With `grid search `_:

.. code:: python

    from sklearn.model_selection import GridSearchCV

    # deactivate skorch-internal train-valid split and verbose logging
    net.set_params(train_split=False, verbose=0)
    params = {
        'lr': [0.01, 0.02],
        'max_epochs': [10, 20],
        'module__num_units': [10, 20],
    }
    gs = GridSearchCV(net, params, refit=False, cv=3, scoring='accuracy', verbose=2)

    gs.fit(X, y)
    print("best score: {:.3f}, best params: {}".format(gs.best_score_, gs.best_params_))


skorch also provides many convenient features, among others:

- `Learning rate schedulers `_ (Warm restarts, cyclic LR and many more)
- `Scoring using sklearn (and custom) scoring functions `_
- `Early stopping `_
- `Checkpointing `_
- `Parameter freezing/unfreezing `_
- `Progress bar `_ (for CLI as well as jupyter)
- `Automatic inference of CLI parameters `_
- `Integration with GPyTorch for Gaussian Processes `_
- `Integration with Hugging Face 🤗 `_

============
Installation
============

skorch requires Python 3.9 or higher.

conda installation
==================

You need a working conda installation. Get the correct miniconda for
your system from `here `__.

To install skorch, you need to use the conda-forge channel:

.. code:: bash

    conda install -c conda-forge skorch

We recommend to use a `conda virtual environment `_.

**Note**: The conda channel is *not* managed by the skorch
maintainers. More information is available `here
`__.

pip installation
================

To install with pip, run:

.. code:: bash

    python -m pip install -U skorch

Again, we recommend to use a `virtual environment
`_ for this.

From source
===========

If you would like to use the most recent additions to skorch or
help development, you should install skorch from source.

Using conda
-----------

To install skorch from source using conda, proceed as follows:

.. code:: bash

    git clone https://github.com/skorch-dev/skorch.git
    cd skorch
    conda create -n skorch-env python=3.12
    conda activate skorch-env
    python -m pip install torch
    python -m pip install .

If you want to help developing, run:

.. code:: bash

    git clone https://github.com/skorch-dev/skorch.git
    cd skorch
    conda create -n skorch-env python=3.12
    conda activate skorch-env
    python -m pip install torch
    python -m pip install '.[test,docs,dev,extended]'

    py.test  # unit tests
    pylint skorch  # static code checks

You may adjust the Python version to any of the supported Python versions.

Using pip
---------

For pip, follow these instructions instead:

.. code:: bash

    git clone https://github.com/skorch-dev/skorch.git
    cd skorch
    # create and activate a virtual environment
    # install pytorch version for your system (see below)
    python -m pip install .

If you want to help developing, run:

.. code:: bash

    git clone https://github.com/skorch-dev/skorch.git
    cd skorch
    # create and activate a virtual environment
    # install pytorch version for your system (see below)
    python -m pip install -e '.[test,docs,dev,extended]'

    py.test  # unit tests
    pylint skorch  # static code checks

PyTorch
=======

PyTorch is not covered by the dependencies, since the PyTorch version
you need is dependent on your OS and device. For installation
instructions for PyTorch, visit the `PyTorch website
`__. skorch officially supports the last four
minor PyTorch versions, which currently are:

- 2.5.1
- 2.6.0
- 2.7.1
- 2.8.0

However, that doesn't mean that older versions don't work, just that
they aren't tested. Since skorch mostly relies on the stable part of
the PyTorch API, older PyTorch versions should work fine.

In general, running this to install PyTorch should work:

.. code:: bash

    python -m pip install torch

==================
External resources
==================

- @jakubczakon: `blog post
  `_
  "8 Creators and Core Contributors Talk About Their Model Training
  Libraries From PyTorch Ecosystem" 2020
- @BenjaminBossan: `talk 1
  `_ "skorch: A
  scikit-learn compatible neural network library" at PyCon/PyData 2019
- @githubnemo: `poster `_
  for the PyTorch developer conference 2019
- @thomasjpfan: `talk 2 `_
  "Skorch: A Union of Scikit learn and PyTorch" at SciPy 2019
- @thomasjpfan: `talk 3 `_
  "Skorch - A Union of Scikit-learn and PyTorch" at PyData 2018
- @BenjaminBossan: `talk 4 `_ "Extend your
  scikit-learn workflow with Hugging Face and skorch" at PyData Amsterdam 2023
  (`slides 4 `_)

=============
Communication
=============

- `GitHub discussions `_: 
  user questions, thoughts, install issues, general discussions.

- `GitHub issues `_: bug
  reports, feature requests, RFCs, etc.

- Slack: We run the #skorch channel on the `PyTorch Slack server
  `_, for which you can `request access
  here `_.

Owner

  • Name: skorch-dev
  • Login: skorch-dev
  • Kind: organization

Organization for maintaining skorch, a sklearn wrapper for PyTorch

Citation (CITATION)

@manual{skorch,
  author       = {Marian Tietz and Thomas J. Fan and Daniel Nouri and Benjamin Bossan and {skorch Developers}},
  title        = {skorch: A scikit-learn compatible neural network library that wraps PyTorch},
  month        = jul,
  year         = 2017,
  url          = {https://skorch.readthedocs.io/en/stable/}
}

GitHub Events

Total
  • Create event: 14
  • Release event: 2
  • Issues event: 25
  • Watch event: 234
  • Delete event: 8
  • Member event: 1
  • Issue comment event: 116
  • Push event: 34
  • Pull request review event: 121
  • Pull request review comment event: 116
  • Pull request event: 47
  • Fork event: 17
Last Year
  • Create event: 14
  • Release event: 2
  • Issues event: 25
  • Watch event: 234
  • Delete event: 8
  • Member event: 1
  • Issue comment event: 116
  • Push event: 34
  • Pull request review event: 121
  • Pull request review comment event: 116
  • Pull request event: 47
  • Fork event: 17

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 949
  • Total Committers: 67
  • Avg Commits per committer: 14.164
  • Development Distribution Score (DDS): 0.728
Past Year
  • Commits: 26
  • Committers: 7
  • Avg Commits per committer: 3.714
  • Development Distribution Score (DDS): 0.5
Top Committers
Name Email Commits
Marian Tietz m****z@o****m 258
Benjamin Bossan b****n@o****m 255
Benjamin Bossan B****n 181
Thomas Fan t****n@g****m 91
BenjaminBossan b****n@g****m 43
Sergey Alexandrov a****8@g****m 18
Daniel Nouri d****i@g****m 11
nemo g****t@n****e 6
Timo Kaufmann t****u@z****m 6
Scott Sievert s****t 5
Parag Ekbote t****9@g****m 4
nemo g****t@n****t 3
Tomasz Pietruszka t****a@p****m 3
githubnemo g****o 3
zhao meng 1****8@q****m 2
guyuz b****y@g****m 2
Yann Dubois y****6@g****m 2
Juri Paern j****n@o****e 2
Jakub c****b@g****m 2
Francesco Mistri f****i@b****e 2
Andrew Spott a****t@g****m 2
Alan deLevie a****e@g****m 2
Aaron Berk a****k 2
Alexander Kolb a****b@o****m 1
Bram Vanroy B****y@U****e 1
Soumith Chintala s****h@g****m 1
Sawradip Saha 6****p 1
Royi R****l@o****m 1
Roman 5****t 1
Riccardo Di Maio 3****o 1
and 37 more...

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 109
  • Total pull requests: 151
  • Average time to close issues: 5 months
  • Average time to close pull requests: about 1 month
  • Total issue authors: 84
  • Total pull request authors: 29
  • Average comments per issue: 3.97
  • Average comments per pull request: 1.65
  • Merged pull requests: 122
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 17
  • Pull requests: 44
  • Average time to close issues: 10 days
  • Average time to close pull requests: 10 days
  • Issue authors: 16
  • Pull request authors: 8
  • Average comments per issue: 2.06
  • Average comments per pull request: 1.3
  • Merged pull requests: 31
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • BenjaminBossan (14)
  • githubnemo (3)
  • benjamin-work (3)
  • ParagEkbote (2)
  • asmyoo (2)
  • timokau (2)
  • jamesee (2)
  • adrinjalali (2)
  • RoyiAvital (2)
  • DCoupry (2)
  • Raphaaal (2)
  • mingYi-ch (1)
  • mbignotti (1)
  • edoumazane (1)
  • AIIAAI (1)
Pull Request Authors
  • BenjaminBossan (105)
  • ParagEkbote (12)
  • ottonemo (9)
  • githubnemo (8)
  • mylapallilavanyaa (2)
  • Ball-Man (2)
  • omahs (2)
  • devyanic11 (2)
  • MaxBalmus (2)
  • RomanBredehoft (2)
  • raphaelrubrice (2)
  • adelevie (2)
  • merveenoyan (1)
  • josarago (1)
  • TrellixVulnTeam (1)
Top Labels
Issue Labels
question (17) enhancement (7) good first issue (7) bug (5) help wanted (4) documentation (3)
Pull Request Labels
bug (9) enhancement (6) documentation (3) maintenance (2)

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 100,387 last-month
  • Total docker downloads: 513
  • Total dependent packages: 29
    (may contain duplicates)
  • Total dependent repositories: 196
    (may contain duplicates)
  • Total versions: 40
  • Total maintainers: 2
pypi.org: skorch

scikit-learn compatible neural network library for pytorch

  • Versions: 21
  • Dependent Packages: 29
  • Dependent Repositories: 196
  • Downloads: 100,387 Last month
  • Docker Downloads: 513
Rankings
Stargazers count: 0.4%
Dependent packages count: 0.6%
Dependent repos count: 1.1%
Downloads: 1.2%
Average: 1.3%
Docker downloads count: 1.9%
Forks count: 2.8%
Maintainers (2)
Last synced: 6 months ago
proxy.golang.org: github.com/skorch-dev/skorch
  • Versions: 19
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 9.0%
Average: 9.6%
Dependent repos count: 10.2%
Last synced: 6 months ago

Dependencies

.github/workflows/test-hf-integration.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
.github/workflows/testing.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
Dockerfile docker
  • nvidia/cuda 9.0-cudnn7-runtime build
examples/translation/Dockerfile docker
  • skorch latest build
docs/requirements.txt pypi
  • docutils <0.18
  • gpytorch >=1.5
  • numpy >=1.13.3
  • numpydoc ==0.8.0
  • scikit-learn >=0.19.1
  • sphinx-rtd-theme ==0.4.0
  • torch >=1.11.0
  • transformers *
examples/nuclei_image_segmentation/requirements.txt pypi
  • kaggle >=1.4.2
  • matplotlib >=2.2.2
  • notebook >=5.7.8
  • torchvision >=0.2.1
requirements-dev.txt pypi
  • accelerate >=0.11.0 development
  • fire * development
  • flaky * development
  • future >=0.17.1 development
  • gpytorch >=1.5 development
  • jupyter * development
  • matplotlib >=2.0.2 development
  • neptune-client >=0.14.3 development
  • numpydoc * development
  • openpyxl * development
  • pandas * development
  • pillow * development
  • protobuf >=3.12.0,<4.0dev development
  • pylint * development
  • pytest >=3.4 development
  • pytest-cov * development
  • sacred * development
  • sphinx * development
  • sphinx_rtd_theme * development
  • tensorboard >=1.14.0 development
  • tokenizers * development
  • transformers * development
  • wandb >=0.12.17 development
requirements.txt pypi
  • numpy >=1.13.3
  • scikit-learn >=0.22.0
  • scipy >=1.1.0
  • tabulate >=0.7.7
  • tqdm >=4.14.0
setup.py pypi
  • l.strip *
examples/translation/docker-compose.yml docker