Views
No views yet
topic || texttopic||text1from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
2
3model_name = "agentlans/flan-t5-small-title"
4model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6
7# Prepare the input text
8topic = "The Serenity of Nature" # a cue to establish context (not necessary but recommended)
9text = "As dawn breaks, the world awakens to a symphony of colors and sounds. The golden rays of sunlight filter through the leaves, casting playful shadows on the forest floor. Birds chirp melodiously, their songs weaving through the crisp morning air, while a gentle breeze rustles the branches overhead. Dew-kissed flowers bloom in vibrant hues, their fragrant scents mingling with the earthy aroma of damp soil. In this tranquil setting, one can’t help but feel a profound sense of peace and connection to the natural world, reminding us of the simple joys that life has to offer."
10
11input_text = f"{topic}||{text}"
12
13# Tokenize the input
14inputs = tokenizer(input_text, return_tensors="pt", max_length=512, truncation=True)
15
16# Generate the title
17outputs = model.generate(**inputs, max_length=30, num_return_sequences=1)
18
19# Decode and print the generated title
20generated_title = tokenizer.decode(outputs[0], skip_special_tokens=True)
21print(generated_title) # The Serenity of Nature: A Symbol of Peace and Harmony