Downloads · 30 days
10
7% of all-time downloads
Wojtekb30/plt5-paraphraser-pl
plt5-paraphraser-pl is a text generation model from Wojtekb30. Use it when you need the model to write or continue text. The card lists the license as cc-by-nc-sa-4.0.
https://huggingface.co/allegro/plt5-base
Downloads · 30 days
10
7% of all-time downloads
All-time downloads
136
Public
Parameters
352M
1.4 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors1.4 GB · 100%
From the Hugging Face model README
https://huggingface.co/allegro/plt5-base
https://huggingface.co/datasets/allegro/klej-cdsc-e
https://huggingface.co/datasets/sdadas/ppc
https://huggingface.co/datasets/Wojtekb30/Polish-paraphrases-12K-synthetic
The first 2 were created by Allegro and Sławomir Dadas (sdadas) respectively and have Creative Commons Attribution Non Commercial Share Alike 4.0 licence. The last one was created by me (Wojtekb30) using ChatGPT and Gemini and has Creative Commons Attribution 4.0 licence.
Important note: inputs must start with "Parafrazuj: ", for example "Parafrazuj: Dzisiaj jest ładna pogoda.".
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
MODEL_NAME = "Wojtekb30/plt5-paraphraser-pl"
#MODEL_NAME = "plt5-paraphraser-pl"
print("Loading model...")
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
# Use GPU if available
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
model.eval()
def paraphrase(text, num_return_sequences=3):
"""
Generate paraphrases for a given Polish input sentence.
"""
# The model requires this prefix
input_text = f"Parafrazuj: {text}"
inputs = tokenizer(
input_text,
return_tensors="pt",
max_length=256,
truncation=True
).to(device)
outputs = model.generate(
**inputs,
max_length=256,
num_return_sequences=num_return_sequences,
num_beams=5,
do_sample=True,
temperature=1.0,
top_k=50,
top_p=0.95,
)
paraphrases = [
tokenizer.decode(output, skip_special_tokens=True)
for output in outputs
]
return paraphrases
if __name__ == "__main__":
test_sentences = [
"W nocy zapowiadane są bardzo silne opady deszczu, dlatego lepiej nie wychodzić z domu.",
"Pomimo zmęczenia po ciężkim dniu pracy, Janek zdecydował się pójść na długi spacer z psem do lasu."
]
for sentence in test_sentences:
print("\nOriginal:", sentence)
print("Paraphrases:")
for i, p in enumerate(paraphrase(sentence), 1):
print(f"{i}. {p}")
https://huggingface.co/allegro/plt5-base
https://huggingface.co/datasets/allegro/klej-cdsc-e
https://huggingface.co/datasets/sdadas/ppc
https://huggingface.co/datasets/Wojtekb30/Polish-paraphrases-12K-synthetic
Pierwsze dwa zostały stworzone kolejno przez Allegro i Sławomira Dadasa (sdadas) i są objęte licencją Creative Commons Attribution Non Commercial Share Alike 4.0. Ostatni został stworzony przeze mnie (Wojtekb30) przy użyciu ChatGPT i Gemini i jest objęty licencją Creative Commons Attribution 4.0.
Ważna uwaga: wejście musi się zaczynać od "Parafrazuj: ", np. "Parafrazuj: Dzisiaj jest ładna pogoda.".
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
MODEL_NAME = "Wojtekb30/plt5-paraphraser-pl"
#MODEL_NAME = "plt5-paraphraser-pl"
print("Loading model...")
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
# Use GPU if available
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
model.eval()
def paraphrase(text, num_return_sequences=3):
"""
Generate paraphrases for a given Polish input sentence.
"""
# The model requires this prefix
input_text = f"Parafrazuj: {text}"
inputs = tokenizer(
input_text,
return_tensors="pt",
max_length=256,
truncation=True
).to(device)
outputs = model.generate(
**inputs,
max_length=256,
num_return_sequences=num_return_sequences,
num_beams=5,
do_sample=True,
temperature=1.0,
top_k=50,
top_p=0.95,
)
paraphrases = [
tokenizer.decode(output, skip_special_tokens=True)
for output in outputs
]
return paraphrases
if __name__ == "__main__":
test_sentences = [
"W nocy zapowiadane są bardzo silne opady deszczu, dlatego lepiej nie wychodzić z domu.",
"Pomimo zmęczenia po ciężkim dniu pracy, Janek zdecydował się pójść na długi spacer z psem do lasu."
]
for sentence in test_sentences:
print("\nOriginal:", sentence)
print("Paraphrases:")
for i, p in enumerate(paraphrase(sentence), 1):
print(f"{i}. {p}")