A refreshing functional take on deep learning, compatible with your favorite libraries
Project description
Thinc: A refreshing functional take on deep learning, compatible with your favorite libraries
From the makers of spaCy, Prodigy and FastAPI
Thinc is a lightweight deep learning library that offers an elegant, type-checked, functional-programming API for composing models, with support for layers defined in other frameworks such as PyTorch, TensorFlow and MXNet. You can use Thinc as an interface layer, a standalone toolkit or a flexible way to develop new models. Previous versions of Thinc have been running quietly in production in thousands of companies, via both spaCy and Prodigy. We wrote the new version to let users compose, configure and deploy custom models built with their favorite framework.
🔥 Features
- Type-check your model definitions with custom types and
mypy
plugin. - Wrap PyTorch, TensorFlow and MXNet models for use in your network.
- Concise functional-programming approach to model definition, using composition rather than inheritance.
- Optional custom infix notation via operator overloading.
- Integrated config system to describe trees of objects and hyperparameters.
- Choice of extensible backends.
- Read more →
🚀 Quickstart
Thinc is compatible with Python 3.6+ and runs on Linux,
macOS and Windows. The latest releases with binary wheels are available from
pip. Before you install Thinc and its
dependencies, make sure that your pip
, setuptools
and wheel
are up to
date. For the most recent releases, pip 19.3 or newer is recommended.
pip install -U pip setuptools wheel
pip install thinc
See the extended installation docs for details on optional dependencies for different backends and GPU. You might also want to set up static type checking to take advantage of Thinc's type system.
⚠️ If you have installed PyTorch and you are using Python 3.7+, uninstall the package
dataclasses
withpip uninstall dataclasses
, since it may have been installed by PyTorch and is incompatible with Python 3.7+.
📓 Selected examples and notebooks
Also see the /examples
directory and usage documentation for more examples. Most examples are Jupyter notebooks – to launch them on Google Colab (with GPU support!) click on the button next to the notebook name.
Notebook | Description |
---|---|
intro_to_thinc |
Everything you need to know to get started. Composing and training a model on the MNIST data, using config files, registering custom functions and wrapping PyTorch, TensorFlow and MXNet models. |
transformers_tagger_bert |
How to use Thinc, transformers and PyTorch to train a part-of-speech tagger. From model definition and config to the training loop. |
pos_tagger_basic_cnn |
Implementing and training a basic CNN for part-of-speech tagging model without external dependencies and using different levels of Thinc's config system. |
parallel_training_ray |
How to set up synchronous and asynchronous parameter server training with Thinc and Ray. |
📖 Documentation & usage guides
Documentation | Description |
---|---|
Introduction | Everything you need to know. |
Concept & Design | Thinc's conceptual model and how it works. |
Defining and using models | How to compose models and update state. |
Configuration system | Thinc's config system and function registry. |
Integrating PyTorch, TensorFlow & MXNet | Interoperability with machine learning frameworks |
Layers API | Weights layers, transforms, combinators and wrappers. |
Type Checking | Type-check your model definitions and more. |
🗺 What's where
Module | Description |
---|---|
thinc.api |
User-facing API. All classes and functions should be imported from here. |
thinc.types |
Custom types and dataclasses. |
thinc.model |
The Model class. All Thinc models are an instance (not a subclass) of Model . |
thinc.layers |
The layers. Each layer is implemented in its own module. |
thinc.shims |
Interface for external models implemented in PyTorch, TensorFlow etc. |
thinc.loss |
Functions to calculate losses. |
thinc.optimizers |
Functions to create optimizers. Currently supports "vanilla" SGD, Adam and RAdam. |
thinc.schedules |
Generators for different rates, schedules, decays or series. |
thinc.backends |
Backends for numpy and cupy . |
thinc.config |
Config parsing and validation and function registry system. |
thinc.util |
Utilities and helper functions. |
🐍 Development notes
Thinc uses black
for auto-formatting, flake8
for linting and mypy
for type checking. All code is written compatible with Python 3.6+, with type hints wherever possible. See the type reference for more details on Thinc's custom types.
👷♀️ Building Thinc from source
Building Thinc from source requires the full dependencies listed in
requirements.txt
to be installed. You'll also need a
compiler to build the C extensions.
git clone https://github.com/explosion/thinc
cd thinc
python -m venv .env
source .env/bin/activate
pip install -U pip setuptools wheel
pip install -r requirements.txt
pip install --no-build-isolation .
Alternatively, install in editable mode:
pip install -r requirements.txt
pip install --no-build-isolation --editable .
Or by setting PYTHONPATH
:
export PYTHONPATH=`pwd`
pip install -r requirements.txt
python setup.py build_ext --inplace
🚦 Running tests
Thinc comes with an extensive test suite. The following should all pass and not report any warnings or errors:
python -m pytest thinc # test suite
python -m mypy thinc # type checks
python -m flake8 thinc # linting
To view test coverage, you can run python -m pytest thinc --cov=thinc
. We aim for a 100% test coverage. This doesn't mean that we meticulously write tests for every single line – we ignore blocks that are not relevant or difficult to test and make sure that the tests execute all code paths.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for thinc-8.1.0.dev2-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1d14a8537675b84c6755bb43e99aa4c07c25ab5f397399d1c8355ebefdefcf8 |
|
MD5 | 9f63a5e63ca465ca0d9f9a878704c403 |
|
BLAKE2b-256 | 0fb62378c2047cb13861ab6297746f977e606581c478cadf88174a2492a4b9c6 |
Hashes for thinc-8.1.0.dev2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 516c26c110177b64998bc54635e2bb324b4745857ef103b09097c08f7559bc9f |
|
MD5 | 9d4fb26251b422deff61817fcebf7a6a |
|
BLAKE2b-256 | f3e03a3519774f697f1dd78eab8e556609b3a129e26ab335115089adf7e6ea94 |
Hashes for thinc-8.1.0.dev2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ed3640ab0935d920141b003fb914212204e9589916d3ff3aba42c9c4a5418ce |
|
MD5 | e67f9a94bb186e5480bc57f8f42cc739 |
|
BLAKE2b-256 | 1bdf3a1591e19d3f898d88975013993c98d6921dbe52b3f28542094be0923480 |
Hashes for thinc-8.1.0.dev2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca847362c54d9710a145e653a7ad33b9d97cb7cf5e8680734d7c7eb6c7ba9314 |
|
MD5 | 951ed5c9e604049442352cb2ea328bca |
|
BLAKE2b-256 | 5f31e11edd93d0e0647f5092c84ccdbf9abe22378558fc985a0a7b941a377002 |
Hashes for thinc-8.1.0.dev2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b17b33a9e6804e5c06b2659185bf62bb65bd04eb7a9b568d10cec5d8e82dc5d |
|
MD5 | ff5b4e0b2bd3d40b71343b6fda05ef8f |
|
BLAKE2b-256 | 9d67b6b50707cb91765fa4b7fe54b026d5d5aec46ad6722fdf17c1c470c9aeba |
Hashes for thinc-8.1.0.dev2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7608e025ab9147b1d4efed0d0770fc4210e9cc6aeab608ec3e6d649a0dea84b |
|
MD5 | 12fe642e4bcd59463f673f5d955eca71 |
|
BLAKE2b-256 | 866fb5cc4034f6a2948efae0eec94ae74bd82ef537dbf71538baf896b64d9650 |
Hashes for thinc-8.1.0.dev2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6acc542f4e4dfde247ef97228553e83d5041b727c08c204df052f7ce506cae6 |
|
MD5 | e77cefd98a1b8b3bb8ae0a7acfd690d2 |
|
BLAKE2b-256 | f5895efe51a27c744526349b9da9e1ddeb8c212801f0c7989cdf0b8052b106a6 |
Hashes for thinc-8.1.0.dev2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 509b02a10ab2971907a83aecbb1529066fdd69816b27a8996bd688975dfd36e9 |
|
MD5 | ed1deba595f3c7b0bede6b32f67fa8d6 |
|
BLAKE2b-256 | 1c7a2dd3d9ad5d8a0c3d0fd692c1f3af7bdc5f2722881465bbdd92af3f09558c |
Hashes for thinc-8.1.0.dev2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac5eafe21c8f5bca180de1cb1f818f55b5c4c48e539e40e66d112376b1e3f26f |
|
MD5 | 9ca3144cac54f7c85cbc2d569d803e24 |
|
BLAKE2b-256 | 1969b6b640eaa232716e19edd01a23d5af7f03910048fde4cba95bcd056f5f2e |
Hashes for thinc-8.1.0.dev2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcd86130478a8e54daeb1aee31133b2c5d71150535d945adf23821dad06e104b |
|
MD5 | a5298abc4a2588f830b87af63adca29f |
|
BLAKE2b-256 | dcf8f96363534f8f429522d0866c29ea176a602838fcf60a5c58617b3cafde91 |
Hashes for thinc-8.1.0.dev2-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2747e47e18b755eed194283304310b472068fc067050c94b89d22418c091a396 |
|
MD5 | 6525129f63720c31e464fc0e2255df1b |
|
BLAKE2b-256 | 4264f1ea267ecb4774c069586fdcc2f5cde74c6c29b66f12fc11617e8728a83f |
Hashes for thinc-8.1.0.dev2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0e9a5a37d2ec3386c43e928b3cb2dbb1213167631d2bbecd91d8d5031feacd3 |
|
MD5 | c1e4266b370e493935f21f214b4839f6 |
|
BLAKE2b-256 | 0753064bda2d40158cf321b709b8d602e9308ed548acfb3fe442e5a82d8b95a6 |
Hashes for thinc-8.1.0.dev2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eba4accafb8a335587ceb2ab4a4c2bdd52efced7083e9ceab77986f9a7dbce1b |
|
MD5 | 8a538b396110489ce714cb1ee334a84e |
|
BLAKE2b-256 | f8d3724a80dc53c194b0723a18eef2ee2cb37f77fa6092c80947b83c9296e4da |
Hashes for thinc-8.1.0.dev2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d68fe55b40481bb6f907944c4806c5d2320fcd16fe1b32200fe0c6e745d5e53 |
|
MD5 | 8914d76bc900df4aeb898b47cb3264f7 |
|
BLAKE2b-256 | 51f99578fe88e7037998a8e7f546c682395053df07c91fd1c54d3e922dfa9c11 |
Hashes for thinc-8.1.0.dev2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c408fff94e80ff9d0ff100cc5e7b7f76cfac71199e36822763a5d520ebd172f4 |
|
MD5 | b91c459894ac0ea456325548fde7ab8a |
|
BLAKE2b-256 | 4372790550ad2cd7e98add8c546a3f01404909ce5f5d2832e58f70a4cfe1410d |
Hashes for thinc-8.1.0.dev2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 544745bf6071a424e4b67b52e3aa464f81a74f3bed7761a9bc6e7ef397313dac |
|
MD5 | 83e5396fa9db47030407ddbcd29bc560 |
|
BLAKE2b-256 | ff63285d8c0f494ad6a06abca926a37aee3bbe690bdf7c4179351ff58f9874b2 |
Hashes for thinc-8.1.0.dev2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db8cde8e689a775b92a3484620039b400c9a686b5eb63707a569f39a4a47e023 |
|
MD5 | 592e85360ed834f618c84682cf5996b6 |
|
BLAKE2b-256 | 44252f2cd28544b9c741771f13ceb818abfd5d0f1fb527c46a1c4729bb6f2547 |
Hashes for thinc-8.1.0.dev2-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33df58019308ec280d6a364b3afda0a44e97e8aee5792c5eeaecaf410c9e7aff |
|
MD5 | 4b6c8a46950c6dfa5a4b6973aa18a969 |
|
BLAKE2b-256 | 75fb49c773a92ff1ee09d8806c5c1732b99344e91364eb2556d10c2fe09e5ad1 |