Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
library_name: transformers
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
|
| 7 |
+
base_model: meta-llama/Meta-Llama-3-8B
|
| 8 |
+
base_model_relation: finetune
|
| 9 |
+
---
|
| 10 |
+
# Model Information
|
| 11 |
+
The Llama-3-8B_SFT_Finetune_Pandas_Code is a quantized, fine-tuned version of the Meta-Llama-3 model designed specifically for analyzing tabular data.
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# How to use
|
| 15 |
+
Starting with transformers version 4.34.0 and later, you can run conversational inference using the Transformers pipeline.
|
| 16 |
+
|
| 17 |
+
Make sure to update your transformers installation via pip install --upgrade transformers.
|
| 18 |
+
|
| 19 |
+
```python
|
| 20 |
+
import transformers
|
| 21 |
+
import torch
|
| 22 |
+
from peft import PeftModel, PeftConfig, get_peft_model
|
| 23 |
+
from transformers import pipeline
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
```python
|
| 27 |
+
def get_pipline():
|
| 28 |
+
model_name = "nirusanan/Llama-3-8B_SFT_Finetune_Pandas_Code"
|
| 29 |
+
|
| 30 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 31 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 32 |
+
|
| 33 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 34 |
+
model_name,
|
| 35 |
+
torch_dtype=torch.float16,
|
| 36 |
+
device_map="cuda:0",
|
| 37 |
+
trust_remote_code=True
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=850)
|
| 41 |
+
|
| 42 |
+
return pipe
|
| 43 |
+
|
| 44 |
+
pipe = get_pipline()
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
def generate_prompt(task, header_columns):
|
| 49 |
+
prompt = f"""Below is an instruction that describes a task. Write a Python function using Pandas to accomplish the task described below.
|
| 50 |
+
|
| 51 |
+
### Instruction:
|
| 52 |
+
{task}
|
| 53 |
+
|
| 54 |
+
header columns with sample data:
|
| 55 |
+
{header_columns}
|
| 56 |
+
|
| 57 |
+
### Response:
|
| 58 |
+
"""
|
| 59 |
+
return prompt
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
prompt = generate_prompt("Your question based on tabular data", "Necessary columns names")
|
| 64 |
+
result = pipe(prompt)
|
| 65 |
+
generated_text = result[0]['generated_text']
|
| 66 |
+
print(generated_text.split("### End")[0])
|
| 67 |
+
```
|