Skip to main content

Python PyPI PyPI Downloads

Ruff Checked with mypy pre-commit

Build Docs Test Codecov

ToyNLP

Implementing classic NLP models from scratch with clean code and easy-to-understand architecture.

This library is for educational purposes only. It is not optimized for production use. And it may contain bugs CURRENTLY, so feel free to contribute and report issues.

Until now, we only do simple tests, which is not enough. But we will do much more rigorous testing in the FUTURE. And we will add more docs for you can RUN it easily, add more playgrounds for you to experiment with the models and look inside the model implementations.

Models

8 important NLP models range from 2003 to 2020:

  • NNLM(2003)
  • Word2Vec(2013)
  • Seq2Seq(2014)
  • Attention(2014)
  • fastText(2016)
  • Transformer(2017)
  • GPT(2018)
  • BERT(2018)

FAQ

I see there are 10 models before, why only 8 now?

Yes, I removed XLNet and T5. The main reason is that I don't have so many GPUs to train these models. Without training them by myself, I can't guarantee the correctness of the implementations. So I just keep the models that I can train and verify myself.

I find there are DIFFERENCES between the implementations in toynlp and original papers.

Yes, there are some differences in the implementations. The goal of toynlp is to provide a simple and educational implementation of these models, which may not include all the optimizations and features in original papers.

The reason is that I want to focus on the core ideas and concepts behind each model, rather than getting bogged down in implementation details. Especially when the original papers may introduce complexities that are not essential for understanding the main contributions of the work.

But, I do need to add docs for each model to clarify these differences and provide guidance on how to use the implementations effectively. I'll do this later. Let's first make it work and then make it better.

Where is GPT-2 and other LLMs?

Well, it's in toyllm! I separated the models into two libraries, toynlp for traditional "small" NLP models and toyllm for LLMs, which are typically larger and more complex.

Like the "toy" style, anything else?

Glad you asked! The "toy" style is all about simplicity and educational value. We have another two toys besides toynlp and toyllm: toyml for traditional machine learning models; toyrl for deep reinforcement learning models.

Metadata

Release files for toynlp 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for toynlp 0.3.0
File Size Uploaded
toynlp-0.3.0.tar.gz 79.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for toynlp 0.3.0
File Interpreter ABI Platform
toynlp-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 189.4 kB

Release files / toynlp-0.3.0.tar.gz

Download URL toynlp-0.3.0.tar.gz
Size 79.4 kB
Tags Source
SHA-256 checksum
How to use checksums
775d61f413fabf7aebc86fdd9a9e99a9e99c8dc3c6dac3d3bdb53a06a3257f13
BLAKE2b-256 checksum
How to use checksums
600319f25e637943758417fdffee4ddbf15a36f390219f6e402568c85abdd59f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / toynlp-0.3.0-py3-none-any.whl

Download URL toynlp-0.3.0-py3-none-any.whl
Size 110.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a7950973e66019319a0318aa3c45d9b4d5e3f0f2ba465eab89ed3cdf90a11a6
BLAKE2b-256 checksum
How to use checksums
563a6c0c8223064079050801e471c2ad308e755275d4829e548be2b0a70df347
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page