Vamsi995/Paraphrase-Generator
소개
T5 모델을 기반으로 영어 문장을 바꿔 쓰는 패러프레이즈 생성기입니다.
AI 및 머신러닝측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalParaphrase Generator with T5
A Paraphrase-Generator built using transformers which takes an English sentence as an input and produces a set of paraphrased sentences. This is an NLP task of conditional text-generation. The model used here is the T5ForConditionalGeneration from the huggingface transformers library. This model is trained on the Google's PAWS Dataset and the model is saved in the transformer model hub of hugging face library under the name Vamsi/T5_Paraphrase_Paws.
List of publications using Paraphrase-Generator (please open a pull request to add missing entries):
Sports Narrative Enhancement with Natural Language Generation
EHRSQL: A Practical Text-to-SQL Benchmark for Electronic Health Records
Wissensgenerierung für deutschprachige Chatbots
Causal Document-Grounded Dialogue Pre-training
Creativity Evaluation Method for Procedural Content Generated Game Items via Machine Learning
Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Prerequisites
- Streamlit library
- Huggingface transformers library
- Pytorch
- Tensorflow
Installing
- Streamlit
$ pip install streamlit
- Huggingface transformers library
$ pip install transformers
- Tensorflow
$ pip install --upgrade tensorflow
- Pytorch
Head to the docs and install a compatible version
https://pytorch.org/
Running the web app
- Clone the repository
$ git clone [repolink]
- Running streamlit app
$ cd Streamlit
$ streamlit run paraphrase.py
- Running the flask app
$ cd Server
$ python server.py
The initial server call will take some time as it downloads the model parameters. The later calls will be relatively faster as it will store the model params in the cache.


General Usage
PyTorch and TF models are available
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("Vamsi/T5_Paraphrase_Paws")
model = AutoModelForSeq2SeqLM.from_pretrained("Vamsi/T5_Paraphrase_Paws")
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
sentence = "This is something which i cannot understand at all"
text = "paraphrase: " + sentence + " </s>"
encoding = tokenizer.encode_plus(text,pad_to_max_length=True, return_tensors="pt")
input_ids, attention_masks = encoding["input_ids"].to(device), encoding["attention_mask"].to(device)
outputs = model.generate(
input_ids=input_ids, attention_mask=attention_masks,
max_length=256,
do_sample=True,
top_k=200,
top_p=0.95,
early_stopping=True,
num_return_sequences=5
)
for output in outputs:
line = tokenizer.decode(output, skip_special_tokens=True,clean_up_tokenization_spaces=True)
print(line)
Dockerfile
The repository also contains a minimal reproducible Dockerfile that can be used to spin up a server with the API endpoints to perform text paraphrasing.
Note: The Dockerfile uses the built-in Flask development server, hence it's not recommended for production usage. It should be replaced with a production-ready WSGI server.
After cloning the repository, starting the local server it's a two lines script:
docker build -t paraphrase .
docker run -p 5000:5000 paraphrase
and then the API is available on localhost:5000
curl -XPOST localhost:5000/run_forward \
-H 'content-type: application/json' \
-d '{"sentence": "What is the best paraphrase of a long sentence that does not say much?", "decoding_params": {"tokenizer": "", "max_len": 512, "strategy": "", "top_k": 168, "top_p": 0.95, "return_sen_num": 3}}'
Built With
- Streamlit - Fastest way for building data apps
- Flask - Backend framework
- Transformers-Huggingface - On a mission to solve NLP, one commit at a time. Transformers Library.
Authors
Citing
@misc{alisetti2021paraphrase,
title={Paraphrase generator with t5},
author={Alisetti, Sai Vamsi},
year={2021}
}
관련 프로젝트 살펴보기
불러오는 중…