ToS-Summarization / abstractive_model.py
EE21's picture
Update abstractive_model.py
72c8f79
raw
history blame
611 Bytes
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# Load the BART tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("EE21/BART-ToSSimplify")
model = AutoModelForSeq2SeqLM.from_pretrained("EE21/BART-ToSSimplify")
# Define the abstractive summarization function
def summarize_with_bart(input_text):
inputs = tokenizer.encode("summarize: " + input_text, return_tensors="pt", max_length=1024, truncation=True)
summary_ids = model.generate(inputs, max_length=50, min_length=10, num_beams=8)
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
return summary