Update README.md
Browse files
README.md
CHANGED
@@ -12,16 +12,41 @@ pipeline_tag: text-generation
|
|
12 |
fine-tuned from [sea-lion-7b-instruct](aisingapore/sea-lion-7b-instruct) with question-pandas expression pairs.
|
13 |
|
14 |
## How to use:
|
15 |
-
```python
|
16 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
17 |
-
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
```
|
26 |
|
27 |
# sponser
|
|
|
12 |
fine-tuned from [sea-lion-7b-instruct](aisingapore/sea-lion-7b-instruct) with question-pandas expression pairs.
|
13 |
|
14 |
## How to use:
|
15 |
+
```python
|
16 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
17 |
+
import pandas as pd
|
18 |
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained("aisingapore/sea-lion-7b-instruct", trust_remote_code=True)
|
20 |
+
model = AutoModelForCausalLM.from_pretrained("aisingapore/sea-lion-7b-instruct", trust_remote_code=True)
|
21 |
+
|
22 |
+
df = pd.read_csv("Your csv..")
|
23 |
+
|
24 |
+
prompt_template = "### USER:\n{human_prompt}\n\n### RESPONSE:\n"
|
25 |
+
|
26 |
+
prompt = """\
|
27 |
+
You are working with a pandas dataframe in Python.
|
28 |
+
The name of the dataframe is `df`.
|
29 |
+
This is the result of `print(df.head())`:
|
30 |
+
{df_str}
|
31 |
|
32 |
+
Follow these instructions:
|
33 |
+
1. Convert the query to executable Python code using Pandas.
|
34 |
+
2. The final line of code should be a Python expression that can be called with the `eval()` function.
|
35 |
+
3. The code should represent a solution to the query.
|
36 |
+
4. PRINT ONLY THE EXPRESSION.
|
37 |
+
5. Do not quote the expression.
|
38 |
+
Query: {query_str} """
|
39 |
+
|
40 |
+
def create_prompt(query_str, df):
|
41 |
+
text = prompt.format(df_str=str(df.head()), query_str=query_str)
|
42 |
+
text = prompt_template.format(human_prompt=text)
|
43 |
+
return text
|
44 |
+
|
45 |
+
full_prompt = create_prompt("Find test ?", df)
|
46 |
+
|
47 |
+
tokens = tokenizer(full_prompt, return_tensors="pt")
|
48 |
+
output = model.generate(tokens["input_ids"], max_new_tokens=20, eos_token_id=tokenizer.eos_token_id)
|
49 |
+
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
50 |
```
|
51 |
|
52 |
# sponser
|