Downloads · 30 days
9
10% of all-time downloads
Wojtekb30/plt5-paraphraser-pl-synthetic
plt5-paraphraser-pl-synthetic 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-4.0.
This model may have worse quality than Wojtekb30/plt5-paraphraser-pl, but was trained only on my synthetic dataset, so has less licence restrictions regarding allowed usage.
Downloads · 30 days
9
10% of all-time downloads
All-time downloads
88
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
This model may have worse quality than Wojtekb30/plt5-paraphraser-pl, but was trained only on my synthetic dataset, so has less licence restrictions regarding allowed usage.
https://huggingface.co/Wojtekb30/plt5-paraphraser-pl
https://huggingface.co/allegro/plt5-base
https://huggingface.co/datasets/Wojtekb30/Polish-paraphrases-12K-synthetic
Since the dataset was fully synthetic, the model may have worse quality than Wojtekb30/plt5-paraphraser-pl, but has less licence restrictions regarding allowed usage.
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}")
Ten model może mieć gorszą jakość niż Wojtekb30/plt5-paraphraser-pl, ponieważ został fine-tuned na w pełni systentycznym datasecie, ale ma mniej restrykcji licencyjnych.
https://huggingface.co/Wojtekb30/plt5-paraphraser-pl
https://huggingface.co/allegro/plt5-base
https://huggingface.co/datasets/Wojtekb30/Polish-paraphrases-12K-synthetic
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}")