Downloads Ā· 30 days
34
5% of all-time downloads
philipp-zettl/t5-small-paraphraser
t5-small-paraphraser is a text generation model from philipp-zettl. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as mit.
This is the model card of a š¤ transformers model that has been pushed on the Hub. This model card has been automatically generated.
Downloads Ā· 30 days
34
5% of all-time downloads
All-time downloads
633
Public
Parameters
77M
309 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors308 MB Ā· 99%
From the Hugging Face model README
This is the model card of a š¤ transformers model that has been pushed on the Hub. This model card has been automatically generated.
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
Use the code below to get started with the model.
model_name = 'philipp-zettl/t5-small-long-qa'
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained('google/flan-t5-small')
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = model.to(device)
def eval(inputs, tokenizer, model):
model_inputs = tokenizer(inputs, max_length=512, padding=True, truncation=True)
input_ids = torch.tensor(model_inputs['input_ids']).to(device)
attention_mask = torch.tensor(model_inputs['attention_mask']).to(device)
with torch.no_grad():
sample_output = model.generate(
input_ids[:1],
max_length=85,
temperature=0.5,
do_sample=True
)
sample_output_text = tokenizer.decode(sample_output[0], skip_special_tokens=True)
input_text = tokenizer.decode(input_ids[0], skip_special_tokens=True)
print(f"Sample Input:\n \"{input_text}\"\n\n")
print(f"Model Output: \"{sample_output_text}\"")
statement = "The model should change the words but not the meaning of this sentence."
eval([f"paraphrase: {statement} . output: "], tokenizer, model)
For training we used the grammarly/medit dataset, filtered by german/english paraphrasing samples.
def preprocess_batch(batch, tokenizer, max_input_length=512, max_output_length=128):
questions = batch['src']
answers = batch['tgt']
inputs = [f"paraphrase: {q} output: " for q in questions]
model_inputs = tokenizer(inputs, max_length=max_input_length, padding=True, truncation=True)
labels = tokenizer(answers, max_length=max_output_length, padding=True, truncation=True)
model_inputs['labels'] = labels['input_ids']
return model_inputs
# Tokenize the dataset
train_dataset = train_dataset.filter(lambda x: x['task'] == 'paraphrasing' and x['lang'] in ['de', 'en']).map(lambda batch: preprocess_batch(batch, tokenizer), batched=True)
validation_dataset = validation_dataset.filter(lambda x: x['task'] == 'paraphrasing' and x['lang'] in ['de', 'en']).map(lambda batch: preprocess_batch(batch, tokenizer), batched=True)
# Set format for PyTorch
train_dataset.set_format(type='torch', columns=['input_ids', 'attention_mask', 'labels'])
validation_dataset.set_format(type='torch', columns=['input_ids', 'attention_mask', 'labels'])
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
BibTeX:
[More Information Needed]
APA:
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]
[More Information Needed]