Vietnamese tokenization, preprocess and models NLP
Project description
Genz Tokenize
Installation:
pip install genz-tokenize
Using for tokenize basic
>>> from genz_tokenize import Tokenize
# using vocab from lib
>>> tokenize = Tokenize()
>>> print(tokenize('sinh_viên công_nghệ', 'hello', max_len = 10, padding = True, truncation = True))
# {'input_ids': [1, 770, 1444, 2, 2, 30469, 2, 0, 0, 0], 'attention_mask': [1, 1, 1, 1, 1, 1, 1, 0, 0, 0], 'sequence_id': [None, 0, 0, None, None, 1, None]}
>>> print(tokenize.decode([1, 770, 2]))
# <s> sinh_viên </s>
# from your vocab
>>> tokenize = Tokenize.fromFile('vocab.txt','bpe.codes')
Using bert tokenize inheritance from PreTrainedTokenizer transformers
>>> from genz_tokenize import TokenizeForBert
# Using vocab from lib
>>> tokenize = TokenizeForBert()
>>> print(tokenize(['sinh_viên công_nghệ', 'hello'], max_length=5, padding='max_length',truncation=True))
# {'input_ids': [[1, 770, 1444, 2, 0], [1, 30469, 2, 0, 0]], 'token_type_ids': [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], 'attention_mask': [[1, 1, 1, 1, 0], [1, 1, 1, 0, 0]]}
# Using your vocab
>>> tokenize = TokenizeForBert.fromFile('vocab.txt','bpe.codes')
Embedding matrix from fasttext
>>> from genz_tokenize import get_embedding_matrix
>>> embedding_matrix = get_embedding_matrix()
Model
1. Seq2Seq with Bahdanau Attention
2. Transformer classification
3. Transformer
Trainer
>>> from genz_tokenize.models.utils import Config
>>> from genz_tokenize.models import Seq2Seq, Transformer, TransformerClassification
>>> from genz_tokenize.models.training import TrainArgument, Trainer
# create config hyper parameter
>>> config = Config()
>>> config.vocab_size = 100
>>> config.target_vocab_size = 120
>>> config.units = 16
>>> config.maxlen = 20
# initial model
>>> model = Seq2Seq(config)
>>> x = tf.zeros(shape=(10, config.maxlen))
>>> y = tf.zeros(shape=(10, config.maxlen))
# create dataset
>>> BUFFER_SIZE = len(x)
>>> dataset_train = tf.data.Dataset.from_tensor_slices((x, y))
>>> dataset_train = dataset_train.shuffle(BUFFER_SIZE)
>>> dataset_train = dataset_train.batch(2)
>>> dataset_train = dataset_train.prefetch(tf.data.experimental.AUTOTUNE)
>>> args = TrainArgument(batch_size=2, epochs=2)
>>> trainer = Trainer(model=model, args=args, data_train=dataset_train)
>>> trainer.train()
Create your vocab
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
genz-tokenize-1.1.8.tar.gz
(62.5 MB
view details)
Built Distribution
File details
Details for the file genz-tokenize-1.1.8.tar.gz
.
File metadata
- Download URL: genz-tokenize-1.1.8.tar.gz
- Upload date:
- Size: 62.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9029aa88d882a22d64a3ead50b80e4b2aa7a55da10b5abc7a1e996aa04339000 |
|
MD5 | 44c0d0fb5c0dec87454a6d8a75cd5389 |
|
BLAKE2b-256 | 142bc13d1d3330bb9643c4feedd0b500836dd3204215af9f10929db2c872bf2e |
File details
Details for the file genz_tokenize-1.1.8-py3-none-any.whl
.
File metadata
- Download URL: genz_tokenize-1.1.8-py3-none-any.whl
- Upload date:
- Size: 63.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b188454ac2c217a58423570b18269d687ade0cfe00567677544b86de97e1c98 |
|
MD5 | 15d290ad7d7118c0f9a324e3b7fd0f82 |
|
BLAKE2b-256 | 3611272a12bbac49bff0712f556e2cb0eefae92a38f695752a167ae39b4bdfa6 |