File size: 1,951 Bytes
1ec4534
 
 
 
2bb1c6e
2aac15e
ce093c5
 
2f85623
a88a0ac
3d0a338
 
e829b11
c3f5f91
c80ce94
c3f5f91
c80ce94
c3f5f91
01beac2
 
c80ce94
 
 
 
 
 
 
 
 
 
c3f5f91
c80ce94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3f5f91
 
a88a0ac
208309c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
language:
- th
- en
license: mit
base_model: aisingapore/sea-lion-7b-instruct
datasets:
- AIAT/Optimizer-datasetfinal
pipeline_tag: text-generation
---
## Sea-lion2pandas
 fine-tuned from [sea-lion-7b-instruct](aisingapore/sea-lion-7b-instruct) with question-pandas expression pairs.

## How to use:
  ```python  
  from transformers import AutoModelForCausalLM, AutoTokenizer
  import pandas as pd
  
  tokenizer = AutoTokenizer.from_pretrained("AIAT/Optimizer-sealion2pandas", trust_remote_code=True)
  model = AutoModelForCausalLM.from_pretrained("AIAT/Optimizer-sealion2pandas", trust_remote_code=True)

  df = pd.read_csv("Your csv..")
  
  prompt_template = "### USER:\n{human_prompt}\n\n### RESPONSE:\n"
  
  prompt = """\
  You are working with a pandas dataframe in Python. 
  The name of the dataframe is `df`.
  This is the result of `print(df.head())`:
  {df_str}
  
  Follow these instructions: 
  1. Convert the query to executable Python code using Pandas. 
  2. The final line of code should be a Python expression that can be called with the `eval()` function.
  3. The code should represent a solution to the query.
  4. PRINT ONLY THE EXPRESSION.
  5. Do not quote the expression.
  Query: {query_str} """
  
  def create_prompt(query_str, df):
      text = prompt.format(df_str=str(df.head()), query_str=query_str)
      text = prompt_template.format(human_prompt=text)
      return text
  
  full_prompt = create_prompt("Find test ?", df)

  tokens = tokenizer(full_prompt, return_tensors="pt")
  output = model.generate(tokens["input_ids"], max_new_tokens=20, eos_token_id=tokenizer.eos_token_id)
  print(tokenizer.decode(output[0], skip_special_tokens=True))
  ```

# sponser
![image/png](https://media.discordapp.net/attachments/1226897965927497818/1235842881520930857/image.png?ex=6635d7df&is=6634865f&hm=be4eb57b51de9f52f0817a88fdd2461b5312d0a013bd022630b2a8dde717976f&=&format=webp&quality=lossless&width=687&height=402)