Chirayu commited on
Commit
ae55cc8
·
1 Parent(s): f03c55e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +59 -0
README.md CHANGED
@@ -1,3 +1,62 @@
1
  ---
2
  license: mit
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ tags:
4
+ - code
5
  ---
6
+
7
+ # What does this model do?
8
+ This model generates a pandas query given the input text. It is a fine-tuned CodeT5+ 220M. This model is a part of nl2query repository which is present at https://github.com/Chirayu-Tripathi/nl2query
9
+
10
+ You can use this model via the github repository or via following code.
11
+
12
+ ```python
13
+
14
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
15
+ import torch
16
+
17
+ model = AutoModelForSeq2SeqLM.from_pretrained("Chirayu/nl2pandas")
18
+ tokenizer = AutoTokenizer.from_pretrained("Chirayu/nl2pandas")
19
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
20
+ model = model.to(device)
21
+
22
+ def generate_query(
23
+ textual_query: str,
24
+ num_beams: int = 10,
25
+ max_length: int = 128,
26
+ repetition_penalty: int = 2.5,
27
+ length_penalty: int = 1,
28
+ early_stopping: bool = True,
29
+ top_p: int = 0.95,
30
+ top_k: int = 50,
31
+ num_return_sequences: int = 1,
32
+ ) -> str:
33
+
34
+ input_ids = tokenizer.encode(
35
+ textual_query, return_tensors="pt", add_special_tokens=True
36
+ )
37
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
38
+ input_ids = input_ids.to(device)
39
+
40
+ generated_ids = model.generate(
41
+ input_ids=input_ids,
42
+ num_beams=num_beams,
43
+ max_length=max_length,
44
+ repetition_penalty=repetition_penalty,
45
+ length_penalty=length_penalty,
46
+ early_stopping=early_stopping,
47
+ top_p=top_p,
48
+ top_k=top_k,
49
+ num_return_sequences=num_return_sequences,
50
+ )
51
+ query = [
52
+ tokenizer.decode(
53
+ generated_id,
54
+ skip_special_tokens=True,
55
+ clean_up_tokenization_spaces=True,
56
+ )
57
+ for generated_id in generated_ids
58
+ ][0]
59
+
60
+ return query
61
+ ```
62
+