Views
No views yet

!pip install accelerate transformers einops datasets peft bitsandbytes1from datasets import load_dataset
2
3test_dataset = load_dataset("zelalt/scientific-papers", split='train')
4test_dataset = test_dataset.rename_column('full_text', 'text')
5
6def formatting(example):
7 text = f"What is the title of this paper? {example['text'][:180]}\n\nAnswer: "
8 return {'text': text}
9
10formatted_dataset = test_dataset.map(formatting)1
2import torch
3from peft import PeftModel, PeftConfig
4from transformers import AutoModelForCausalLM, AutoTokenizer
5
6peft_model_id = "zelalt/titletor-phi_1-5"
7config = PeftConfig.from_pretrained(peft_model_id)
8model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, trust_remote_code=True)
9tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path,trust_remote_code=True)
10model = PeftModel.from_pretrained(model, peft_model_id)
11
12#from dataset
13inputs = tokenizer(f'''{formatted_dataset['text'][120]}''', return_tensors="pt", return_attention_mask=False)
14outputs = model.generate(**inputs,max_new_tokens=50, pad_token_id = tokenizer.eos_token_id, eos_token_id = tokenizer.eos_token_id)
15text = tokenizer.batch_decode(outputs)[0]
16print(text)1#as string
2inputs = tokenizer(f'''What is the title of this paper? ...[your pdf as text]..\n\nAnswer: ''', return_tensors="pt", return_attention_mask=False)
3outputs = model.generate(**inputs,max_new_tokens=50, pad_token_id = tokenizer.eos_token_id, eos_token_id = tokenizer.eos_token_id)
4text = tokenizer.batch_decode(outputs)[0]
5print(text)What is the title of this paper? Bursting Dynamics of the 3D Euler Equations\nin Cylindrical Domains\nFrançois Golse ∗ †\nEcole Polytechnique, CMLS\n91128 Palaiseau Cedex, France\nAlex Mahalov ‡and Basil Nicolaenko §\n\nAnswer:1What is the title of this paper? Bursting Dynamics of the 3D Euler Equations
2in Cylindrical Domains
3François Golse ∗ †
4Ecole Polytechnique, CMLS
591128 Palaiseau Cedex, France
6Alex Mahalov ‡and Basil Nicolaenko §
7
8Answer: Bursting Dynamics of the 3D Euler Equations in Cylindrical Domains<|endoftext|>