Skip to main content

Reorder word in English sentence to follow correct grammar

Project description

Word ordering

Sequence tagging to predict the correct order of input sequence trained on dedicated dataset

How to use

pip install ReWord
from ReWord import ReWordModel
from transformers import RobertaTokenizer
import torch
pretrained_ck = 'transZ/reword'
tokenizer = RobertaTokenizer.from_pretrained(pretrained_ck, add_prefix_space=True)
model = ReWordModel.from_pretrained(pretrained_ck)
model.eval()
sent = "I education company . <ma> <mp> <mv>"
inputs = sent.split(" ")
tokenized_inputs = tokenizer(
    inputs,
    padding="max_length",
    truncation=True,
    max_length=25,
    is_split_into_words=True,
    return_tensors="pt"
)
with torch.no_grad():
    logits = model(**tokenized_inputs)

preds = logits.argmax(dim=-1)
decoded_preds = tokenizer.decode(preds, skip_special_tokens=True)
print(decoded_preds) # "I <mv> <mp> <ma> education company ."

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ReWord-0.1.0.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

ReWord-0.1.0-py3-none-any.whl (6.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page