Update README.md
Browse files
README.md
CHANGED
@@ -65,15 +65,17 @@ See the [author's demo](https://huggingface.co/spaces/tonic/gaiaminimed)
|
|
65 |
Use the code below to get started with the model.
|
66 |
|
67 |
```python
|
68 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
69 |
import torch
|
70 |
import gradio as gr
|
71 |
|
72 |
# Define the device
|
73 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
74 |
|
|
|
75 |
# Use model IDs as variables
|
76 |
-
base_model_id = "
|
77 |
model_directory = "Tonic/GaiaMiniMed"
|
78 |
|
79 |
# Instantiate the Tokenizer
|
@@ -82,13 +84,16 @@ tokenizer.pad_token = tokenizer.eos_token
|
|
82 |
tokenizer.padding_side = 'left'
|
83 |
|
84 |
|
|
|
85 |
# Load the GaiaMiniMed model with the specified configuration
|
86 |
-
#
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
89 |
|
90 |
-
# Now you can use peft_model without any NameError
|
91 |
-
peft_model = peft_model.to_bettertransformer("tiiuae/falcon-7b-instruct")
|
92 |
|
93 |
# Class to encapsulate the Falcon chatbot
|
94 |
class FalconChatBot:
|
@@ -125,7 +130,7 @@ class FalconChatBot:
|
|
125 |
input_ids = tokenizer.encode(conversation, return_tensors="pt", add_special_tokens=False)
|
126 |
|
127 |
# Generate a response using the Falcon model
|
128 |
-
response = falcon_model.generate(input_ids, max_length=max_length, use_cache=True, early_stopping=True, bos_token_id=falcon_model.config.bos_token_id, eos_token_id=falcon_model.config.eos_token_id, pad_token_id=falcon_model.config.eos_token_id, temperature=0.
|
129 |
|
130 |
# Decode the generated response to text
|
131 |
response_text = tokenizer.decode(response[0], skip_special_tokens=True)
|
|
|
65 |
Use the code below to get started with the model.
|
66 |
|
67 |
```python
|
68 |
+
from transformers import AutoConfig, AutoTokenizer, AutoModelForCausalLM
|
69 |
+
from peft import PeftModel, PeftConfig
|
70 |
import torch
|
71 |
import gradio as gr
|
72 |
|
73 |
# Define the device
|
74 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
75 |
|
76 |
+
|
77 |
# Use model IDs as variables
|
78 |
+
base_model_id = "tiiuae/falcon-7b-instruct"
|
79 |
model_directory = "Tonic/GaiaMiniMed"
|
80 |
|
81 |
# Instantiate the Tokenizer
|
|
|
84 |
tokenizer.padding_side = 'left'
|
85 |
|
86 |
|
87 |
+
|
88 |
# Load the GaiaMiniMed model with the specified configuration
|
89 |
+
# Specify the configuration class for the model
|
90 |
+
model_config = AutoConfig.from_pretrained(base_model_id)
|
91 |
+
# Load the PEFT model with the specified configuration
|
92 |
+
peft_model = AutoModelForCausalLM.from_pretrained(base_model_id, config=model_config)
|
93 |
+
peft_model = PeftModel.from_pretrained("Tonic/GaiaMiniMed")
|
94 |
+
peft_model = PeftModel.from_pretrained(peft_model, "Tonic/GaiaMiniMed")
|
95 |
+
|
96 |
|
|
|
|
|
97 |
|
98 |
# Class to encapsulate the Falcon chatbot
|
99 |
class FalconChatBot:
|
|
|
130 |
input_ids = tokenizer.encode(conversation, return_tensors="pt", add_special_tokens=False)
|
131 |
|
132 |
# Generate a response using the Falcon model
|
133 |
+
response = falcon_model.generate(input_ids, max_length=max_length, use_cache=True, early_stopping=True, bos_token_id=falcon_model.config.bos_token_id, eos_token_id=falcon_model.config.eos_token_id, pad_token_id=falcon_model.config.eos_token_id, temperature=0.4, do_sample=True)
|
134 |
|
135 |
# Decode the generated response to text
|
136 |
response_text = tokenizer.decode(response[0], skip_special_tokens=True)
|