Views
No views yet
1from transformers import GPTNeoXForCausalLM, AutoTokenizer
2
3
4model_name_or_path = 'Mxode/Pythia-70m-C-Language-KnowledgeExtract'
5device = 'cuda'
6
7model = GPTNeoXForCausalLM.from_pretrained(model_name_or_path).to(device)
8tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
9
10# prompt template
11prompt = '<|prompt|>Convert the following passage into synonymous sentences.<|prompt|>\n'
12# any text you wish to convert, preferably in complete single sentences.
13content = 'The theories and methods of systems science are extensively employed in various domains, including biology, economics, and sociology.'
14
15text = prompt + content1inputs = tokenizer(text, return_tensors="pt").to(device)
2input_ids = inputs.input_ids
3
4tokens = model.generate(
5 **inputs,
6 pad_token_id=tokenizer.eos_token_id,
7 max_new_tokens=100,
8 do_sample=True,
9)
10# strip the input
11response = tokenizer.decode(tokens[0]).replace(text, "").strip('<|endoftext|>')
12
13# I call it 'Synonymizer' :)
14print(f'Synonymizer: {response}')
15### output:
16### The disciplines of systems science are extensively employed in various domains, including biology, economics, and sociology.1### ...
2content = 'As both teams exited the court for halftime, Baynes and Mayen were shoulder to shoulder.'
3
4### ...
5print(f'Synonymizer: {response}')
6### output:
7### As the team neets around the court to ease their shifts, Baynes and Middets were partnerly paryyneen.
8
9### sometimes:
10### Begantly mastitatively, Baynes and Mayen staged their team rested the Tywindes rested the Tywindes rested the Tywindes laid the Tywindes laid the Tywindes laid the Tywindes laid the Tywindes laid the Tywindes laid the Tywindes laid the Tywindes laid the Tywindes laid the Tywindes laid the Tywindes laid the Tywindes laid the Tywindes laid the Tywindes laid the Tywindes laid