lgfunderburk
commited on
Commit
•
8b9bde0
1
Parent(s):
0ec019c
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# How to use this
|
2 |
+
|
3 |
+
```
|
4 |
+
import torch
|
5 |
+
from peft import PeftModel, PeftConfig
|
6 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
7 |
+
from IPython.display import display, Markdown
|
8 |
+
|
9 |
+
def make_inference(topic):
|
10 |
+
batch = tokenizer(f"### INSTRUCTION\nBelow summary for a blog post, please write a social media post\
|
11 |
+
\n\n### Topic:\n{topic}\n### Social media post:\n", return_tensors='pt')
|
12 |
+
|
13 |
+
with torch.cuda.amp.autocast():
|
14 |
+
output_tokens = model.generate(**batch, max_new_tokens=200)
|
15 |
+
|
16 |
+
display(Markdown((tokenizer.decode(output_tokens[0], skip_special_tokens=True))))
|
17 |
+
|
18 |
+
if __name__=="__main__":
|
19 |
+
|
20 |
+
# Set up user name and model name
|
21 |
+
hf_username = "lgfunderburk"
|
22 |
+
model_name = 'tech-social-media-posts'
|
23 |
+
peft_model_id = f"{hf_username}/{model_name}"
|
24 |
+
|
25 |
+
# Apply PETF configuration, setup model and autotokenizer
|
26 |
+
config = PeftConfig.from_pretrained(peft_model_id)
|
27 |
+
model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path, return_dict=True, load_in_8bit=False, device_map='auto')
|
28 |
+
tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
|
29 |
+
|
30 |
+
# Load the Lora model
|
31 |
+
model = PeftModel.from_pretrained(model, peft_model_id)
|
32 |
+
|
33 |
+
# Summary to generate a social media post about
|
34 |
+
topic = "The blog post demonstrates how to use JupySQL and DuckDB to query CSV files with SQL in a Jupyter notebook. \
|
35 |
+
It covers installation, setup, querying, and converting queries to DataFrame. \
|
36 |
+
Additionally, the post shows how to register SQLite user-defined functions (UDF), \
|
37 |
+
connect to a SQLite database with spaces, switch connections between databases, and connect to existing engines. \
|
38 |
+
It also provides tips for using JupySQL in Databricks, ignoring deprecation warnings, and hiding connection strings."
|
39 |
+
|
40 |
+
|
41 |
+
# Generate social media post
|
42 |
+
make_inference(topic)
|
43 |
+
|
44 |
+
|
45 |
+
```
|