Update README.md
Browse files
README.md
CHANGED
|
@@ -1,11 +1,17 @@
|
|
| 1 |
---
|
| 2 |
base_model: google/gemma-2b
|
| 3 |
library_name: peft
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
# Model Card for Model ID
|
| 7 |
|
| 8 |
-
|
| 9 |
|
| 10 |
|
| 11 |
|
|
@@ -17,13 +23,13 @@ library_name: peft
|
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
-
- **Developed by:**
|
| 21 |
- **Funded by [optional]:** [More Information Needed]
|
| 22 |
- **Shared by [optional]:** [More Information Needed]
|
| 23 |
- **Model type:** [More Information Needed]
|
| 24 |
- **Language(s) (NLP):** [More Information Needed]
|
| 25 |
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:**
|
| 27 |
|
| 28 |
### Model Sources [optional]
|
| 29 |
|
|
@@ -69,8 +75,53 @@ Users (both direct and downstream) should be made aware of the risks, biases and
|
|
| 69 |
|
| 70 |
## How to Get Started with the Model
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
[More Information Needed]
|
| 75 |
|
| 76 |
## Training Details
|
|
|
|
| 1 |
---
|
| 2 |
base_model: google/gemma-2b
|
| 3 |
library_name: peft
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
datasets:
|
| 6 |
+
- AnonySub628/physics-scienceqa
|
| 7 |
+
language:
|
| 8 |
+
- en
|
| 9 |
+
pipeline_tag: question-answering
|
| 10 |
---
|
| 11 |
|
| 12 |
# Model Card for Model ID
|
| 13 |
|
| 14 |
+
A Gemma-2b finetuned LoRA trained on science Q&A
|
| 15 |
|
| 16 |
|
| 17 |
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
+
- **Developed by:** Venkat
|
| 27 |
- **Funded by [optional]:** [More Information Needed]
|
| 28 |
- **Shared by [optional]:** [More Information Needed]
|
| 29 |
- **Model type:** [More Information Needed]
|
| 30 |
- **Language(s) (NLP):** [More Information Needed]
|
| 31 |
- **License:** [More Information Needed]
|
| 32 |
+
- **Finetuned from model [optional]:** Gemma-2b
|
| 33 |
|
| 34 |
### Model Sources [optional]
|
| 35 |
|
|
|
|
| 75 |
|
| 76 |
## How to Get Started with the Model
|
| 77 |
|
| 78 |
+
import torch
|
| 79 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
|
| 80 |
+
from peft import PeftModel
|
| 81 |
+
from typing import Optional
|
| 82 |
+
import time
|
| 83 |
+
import os
|
| 84 |
+
|
| 85 |
+
def generate_prompt(input_text: str, instruction: Optional[str] = None) -> str:
|
| 86 |
+
text = f"### Question: {input_text}\n\n### Answer: "
|
| 87 |
+
if instruction:
|
| 88 |
+
text = f"### Instruction: {instruction}\n\n{text}"
|
| 89 |
+
return text
|
| 90 |
+
|
| 91 |
+
huggingface_token = os.environ.get('HUGGINGFACE_TOKEN')
|
| 92 |
+
|
| 93 |
+
base_model = AutoModelForCausalLM.from_pretrained("google/gemma-2b", token=huggingface_token)
|
| 94 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2b", token=huggingface_token)
|
| 95 |
+
|
| 96 |
+
lora_model = PeftModel.from_pretrained(base_model, "vdpappu/lora_scienceqa")
|
| 97 |
+
merged_model = lora_model.merge_and_unload()
|
| 98 |
+
|
| 99 |
+
eos_token = '<eos>'
|
| 100 |
+
eos_token_id = tokenizer.encode(eos_token, add_special_tokens=False)[-1]
|
| 101 |
+
|
| 102 |
+
generation_config = GenerationConfig(
|
| 103 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 104 |
+
min_length=5,
|
| 105 |
+
max_length=200,
|
| 106 |
+
do_sample=True,
|
| 107 |
+
temperature=0.7,
|
| 108 |
+
top_p=0.9,
|
| 109 |
+
top_k=50,
|
| 110 |
+
repetition_penalty=1.5,
|
| 111 |
+
no_repeat_ngram_size=3,
|
| 112 |
+
early_stopping=True
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
question = "Which is the smoothest? Choose from: concrete sidewalk, sandpaper, paper."
|
| 116 |
+
prompt = generate_prompt(input_text=question)
|
| 117 |
+
|
| 118 |
+
with torch.no_grad():
|
| 119 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 120 |
+
output = merged_model.generate(**inputs, generation_config=generation_config)
|
| 121 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 122 |
+
|
| 123 |
+
print(f"Inference time: {end-start:.2f} seconds")
|
| 124 |
+
print(response)
|
| 125 |
[More Information Needed]
|
| 126 |
|
| 127 |
## Training Details
|