Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
2from peft import PeftModel, PeftConfig
3
4# Load the model
5model_id = "keyegon2024/falcon-lora-imdb"
6peft_config = PeftConfig.from_pretrained(model_id)
7
8# Load base model
9base_model = AutoModelForCausalLM.from_pretrained(
10 peft_config.base_model_name_or_path, # tiiuae/falcon-rw-1b
11 trust_remote_code=True,
12 device_map="auto"
13)
14
15# Load LoRA adapter
16model = PeftModel.from_pretrained(base_model, model_id)
17model.eval()
18
19# Load tokenizer
20tokenizer = AutoTokenizer.from_pretrained(
21 peft_config.base_model_name_or_path,
22 trust_remote_code=True
23)
24tokenizer.pad_token = tokenizer.eos_token
25
26# Create inference pipeline
27pipe = pipeline(
28 "text-generation",
29 model=model,
30 tokenizer=tokenizer,
31 max_new_tokens=100,
32 do_sample=True,
33 temperature=0.8,
34 top_k=50,
35 top_p=0.95
36)
37
38# Example usage
39prompt = "The movie was absolutely wonderful because"
40result = pipe(prompt)
41print(result[0]["generated_text"])load_dataset("imdb"))1@misc{falcon-lora-imdb-2024,
2 author = {keyegon2024},
3 title = {Falcon LoRA IMDB Sentiment Analysis Model},
4 year = {2024},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/keyegon2024/falcon-lora-imdb}
7}