Views
No views yet
1>>> from transformers import AutoModel, AutoTokenizer
2>>>
3>>> model_id = "radi-cho/poetry-bg"
4>>> tokenizer = AutoTokenizer.from_pretrained(model_id)
5>>> model = AutoModel.from_pretrained(model_id, trust_remote_code=True)
6>>>
7>>> input_ids = tokenizer.encode(
8>>> "[HED]Суетата на живота[NEL][BDY]",
9>>> add_special_tokens=False,
10>>> return_tensors='pt')
11>>>
12>>> output_ids = model.generate(
13>>> input_ids,
14>>> do_sample=True,
15>>> max_length=250,
16>>> top_p=0.98,
17>>> top_k=0,
18>>> pad_token_id=2,
19>>> eos_token_id=50258)
20>>>
21>>> output = tokenizer.decode(output_ids[0])
22>>>
23>>> output = output.replace('[NEL]', '\n')
24>>> output = output.replace('[BDY]', '\n')
25>>> output = output.replace('[HED]', '')
26>>> output = output.replace('[SEP]', '')
27>>>
28>>> print(output)
29Суетата на живота
30
31Да страдам ли?
32Да страдам ли за това?
33Не, не за това, че умирам...
34Но само за това,
35че миговете ми са рани.
36
37Аз съм сам и търся утеха.[NEL], [BDY], [HED][HED] denotes where the title of the poem begins;[BDY] denotes where the body of the poem begins;[NEL] marks the end of a verse and should be decoded as a new line;[SEP] (with id 50258) is the end of sequence token.