Skip to main content

txt2txt - An extremely easy to use seq2seq implementation with Attention for text to text use cases

DOI

Examples

  1. Adding two numbers
  2. More Complex Math and fit_generator

Installation

pip install txt2txt

Training a model

from txt2txt import build_params, build_model, convert_training_data

input_data = ['123', '213', '312', '321', '132', '231']
output_data = ['123', '123', '123', '123', '123', '123']

build_params(input_data = input_data, output_data = output_data, params_path = 'test/params', max_lenghts=(10, 10))

model, params = build_model(params_path='test/params')

input_data, output_data = convert_training_data(input_data, output_data, params)

checkpoint = ModelCheckpoint('test/checkpoint', monitor='val_acc', verbose=1, save_best_only=True, mode='max')
callbacks_list = [checkpoint]

model.fit(input_data, output_data, validation_data=(input_data, output_data), batch_size=2, epochs=20, callbacks=callbacks_list)

Loading a trained model and running inference

from txt2txt import build_model, infer
model, params = build_model(params_path='test/params')
model.load_weights('path_to_checkpoint_file')
infer(input_text, model, params)

Note: Checkout https://github.com/bedapudi6788/deepcorrect for pre-trained models for english punctuation correction and grammar correction.

Requirements

This module needs Keras and Tensorflow. (tested with tf>=1.8.0, keras>=2.2.0).

Tensorflow is not included in setup.py and needs to be installed seperately.

What's the use of this module

Working with seq2seq tasks in NLP, I realised there aren't any easy to use, simple to understand and good performing libraries available for this. Though libraries like FairSeq or transformer are available they are in general either too complex for a newbie to understand or most probably overkill (and are very tough to train) for simple projects.

This module provides pre-built seq2seq model with Attention that performs excellently on most of the "simple" NLP taks. (Tested with Punctuation correction, transliteration and spell correction)

To Do

Make number of encoder and decoder layers configurable

Give option to add language model probability in beam search

License

Although txt2txt is licensed under GPL, if you want to use it commercially without open sourcing your code please email me or raise a issue in this repo so that I can provide you explicit written permission to use as you wish. The only reason for doing this is, it would be nice to know if some company is using my work.

Metadata

Release files for txt2txt 1.1.2

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

Source distribution (sdist)

Source distribution for txt2txt 1.1.2
File Size Uploaded
txt2txt-1.1.2.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for txt2txt 1.1.2
File Interpreter ABI Platform
txt2txt-1.1.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 25.1 kB

Release files / txt2txt-1.1.2.tar.gz

Download URL txt2txt-1.1.2.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6fedd15baf0aa37a00bb63084d0e6453cf4efa035dd3babe086da44d191685d0
BLAKE2b-256 checksum
How to use checksums
3b3f2e85bd56cf59e881a7796a2a537f29c3af6e9dc343047b3868a8a493132e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.0

Release files / txt2txt-1.1.2-py2.py3-none-any.whl

Download URL txt2txt-1.1.2-py2.py3-none-any.whl
Size 18.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ea33275fb30f4efe9257e4fdfb21f73ff3d16e1acfa0bc00559f9629cceb101d
BLAKE2b-256 checksum
How to use checksums
ae9a16a6f30dc4bcd18bed48dbfb75cac27fe0e61f37e9b67e12e87b3c17ff7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.0

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.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