Corpusit
corpusit provides easy-to-use dataset iterators for natural language modeling
tasks, such as SkipGram.
It is written in rust to enable fast multi-threading random sampling with deterministic results. So you dont have to worry about the speed / reproducibility.
Corpusit does not provide tokenization functionalities. So please use corpusit
on tokenized corpus files (plain texts).
Environment
Python >= 3.6
Installation
$ pip install corpusit
On Windows and MacOS
Please install rust compiler before
executing pip install corpusit.
Usage
SkipGram with Positive Sampling
Process tokenized sequences to generate positive SkipGram pairs:
import corpusit
import numpy as np
# Create word counts mapping (word_id -> count)
word_counts = {0: 100, 1: 50, 2: 200, 3: 75, 4: 150}
# Create SkipGram configuration
config = corpusit.SkipGramConfig(
word_counts=word_counts,
win_size=5,
subsample=1e-3,
power=0.75,
n_neg=1
)
# Create positive sampler
sampler = config.positive_sampler(seed=0)
# Process a sequence of word IDs
sequence = [0, 1, 2, 3, 4, 1, 2, 0]
pairs = sampler.process_sequence(sequence)
print(f'Generated {len(pairs)} positive pairs')
print(f'Shape: {pairs.shape}')
print(f'First few pairs: {pairs[:3]}')
SkipGram with Negative Sampling
Generate both positive and negative samples with labels:
# Create sampler with negative sampling
sampler = config.sampler(seed=0, num_threads=4)
# Process sequences
sequences = [[0, 1, 2, 3], [1, 2, 3, 4], [2, 3, 4, 0]]
pairs, labels = sampler.process_sequences(sequences)
print(f'Generated {len(pairs)} samples')
print(f'Pairs shape: {pairs.shape}')
print(f'Labels shape: {labels.shape}')
print(f'Positive samples: {np.sum(labels)}')
print(f'Negative samples: {np.sum(~labels)}')
SkipGram with Tokenization
Process raw text sequences with automatic tokenization:
# Create configuration with tokenization support
word_counts = {0: 100, 1: 50, 2: 200, 3: 75, 4: 150}
word_to_id = {"hello": 0, "world": 1, "python": 2, "rust": 3, "fast": 4}
config = corpusit.SkipGramConfigWithTokenization(
word_counts=word_counts,
word_to_id=word_to_id,
separator=" ",
win_size=5,
subsample=1e-3,
power=0.75,
n_neg=1
)
# Create sampler
sampler = config.sampler(seed=0, num_threads=4)
# Process raw text
text_sequences = ["hello world python", "world python rust", "python rust fast"]
pairs, labels = sampler.process_string_sequences(text_sequences)
print(f'Generated {len(pairs)} samples from text')
print(f'First few pairs: {pairs[:3]}')
print(f'Labels: {labels[:3]}')
Roadmap
- GloVe
License
MIT
Metadata
Release files for corpusit 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| corpusit-0.2.1.tar.gz | 30.4 kB | Details |
Built distributions (wheels)
Total release size: 2.3 MB
Release files / corpusit-0.2.1.tar.gz
| Download URL | corpusit-0.2.1.tar.gz |
|---|---|
| Size | 30.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7506925ef920913e91334ea916f7c713dce365044d23536132ec0d6ed4ec15ea
|
|
BLAKE2b-256 checksum How to use checksums |
2d43e2fbb85257bb7041ce0f43c8c8a1adff2ff6d31047a6e284eeab690b8161
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|
Release files / corpusit-0.2.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | corpusit-0.2.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 288.3 kB |
| Tags | Linux glibc 2.17+ x86-64 PyPy 3.9 PyPy 3.9 7.3 |
|
SHA-256 checksum How to use checksums |
e7eb98b446b5d18d0e377c35548ba62c279f8afd7874ca98172649fa67de10f1
|
|
BLAKE2b-256 checksum How to use checksums |
5a4358934f10cbbbca4f76d17abb71b7c47ea49b8291ecedce90b3c6e1829946
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|
Release files / corpusit-0.2.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | corpusit-0.2.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 288.3 kB |
| Tags | Linux glibc 2.17+ x86-64 PyPy 3.8 PyPy 3.8 7.3 |
|
SHA-256 checksum How to use checksums |
9390f6cd08893081e97f30111c2d3c667fd66d71e5a4cda7e77fcf28144d7bb9
|
|
BLAKE2b-256 checksum How to use checksums |
de2aa2429cdea29f185d255703b88907f8ece0f1aa939a72e146f9d5c2a15193
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|
Release files / corpusit-0.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | corpusit-0.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 287.8 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
f3ca006dabba10a5703587420150cf9df2bcf4aea83b2ded21d8c0002811c0f8
|
|
BLAKE2b-256 checksum How to use checksums |
4f94515acf99fa8be5e8989764117c0d2cb35c2e356af9eef59636d67e9adf5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|
Release files / corpusit-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | corpusit-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 287.9 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e2e29e02cd653c9d4df906d0403ce190f48abe9e1151030c883985cc03e38ada
|
|
BLAKE2b-256 checksum How to use checksums |
755bacc4783f213c0c35aa4a556532cd49410e9d0ec282ce842e2908b4871c84
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|
Release files / corpusit-0.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | corpusit-0.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 287.9 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
337353a08dd1afb476a42c83d482d0f44fbb2b66040afc9e438dd4308c64bd29
|
|
BLAKE2b-256 checksum How to use checksums |
20c736e8242b8d036f1b5207915c74fe969a4b82e2f87a174355b1b2a072c26e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|
Release files / corpusit-0.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | corpusit-0.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 288.2 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
376d89eb4702b948f1038f62a5fa8a2b69388cc25d19148f3d5725af48f7b643
|
|
BLAKE2b-256 checksum How to use checksums |
249343a3226290f9d16b68b85c0fba4fe2d4eca1795d6bd80c302ef49f370151
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|
Release files / corpusit-0.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | corpusit-0.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 288.6 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
5ded27a69b97a117445ad0201cad40d7380daabd8cc81795ae793d0499da2f45
|
|
BLAKE2b-256 checksum How to use checksums |
6208522ad24e28259ea42e78e0dd97269fb121e0e504949ba72ddbba847d4d1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|
Release files / corpusit-0.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | corpusit-0.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 288.8 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
509b914330c2477538ce373eb61b5adb00e14bba8279658af3471f43e2b058a2
|
|
BLAKE2b-256 checksum How to use checksums |
54dcbc3da1f5e742c8ce686ae24449450de15b512840b3db522af560e6ff2272
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|