Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
3tokenizer = AutoTokenizer.from_pretrained("Ateeqq/news-title-generator")
4model = AutoModelForSeq2SeqLM.from_pretrained("Ateeqq/news-title-generator")1def generate_title(input_text):
2
3 input_ids = tokenizer.encode(input_text, return_tensors="pt")
4 output = model.generate(input_ids)
5 decoded_text = tokenizer.decode(output[0], skip_special_tokens=True)
6 return decoded_text
7
8input_text = """Microsoft is opening a new office in London dedicated to artificial
9 intelligence (AI) research and development. The tech firm's AI boss Mustafa
10 Suleyman said it will advertise roles for exceptional individuals in the
11 coming weeks and months. But he has not said how many jobs will be created.
12 Microsoft is a major investor in ChatGPT-creator OpenAI, which itself opened
13 an office in London in 2023."""
14generated_title = generate_title(input_text)
15
16print(generated_title)Microsoft to open new London office dedicated to AI research