Chirayu commited on
Commit
f6f27da
1 Parent(s): 6e34e0d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +51 -0
README.md CHANGED
@@ -1,3 +1,54 @@
1
  ---
2
  license: mit
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ tags:
4
+ - code
5
  ---
6
+ # What does this model do?
7
+ This model converts the natural language input to Kusto (KQL) query. 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
8
+
9
+ You can use this model via the github repository or via following code.
10
+
11
+ ```python
12
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
13
+ import torch
14
+ model = AutoModelForSeq2SeqLM.from_pretrained("Chirayu/nl2kql")
15
+ tokenizer = AutoTokenizer.from_pretrained("Chirayu/nl2kql")
16
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
17
+ model = model.to(device)
18
+ def generate_query(
19
+ textual_query: str,
20
+ num_beams: int = 10,
21
+ max_length: int = 128,
22
+ repetition_penalty: int = 2.5,
23
+ length_penalty: int = 1,
24
+ early_stopping: bool = True,
25
+ top_p: int = 0.95,
26
+ top_k: int = 50,
27
+ num_return_sequences: int = 1,
28
+ ) -> str:
29
+ input_ids = tokenizer.encode(
30
+ textual_query, return_tensors="pt", add_special_tokens=True
31
+ )
32
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
33
+ input_ids = input_ids.to(device)
34
+ generated_ids = model.generate(
35
+ input_ids=input_ids,
36
+ num_beams=num_beams,
37
+ max_length=max_length,
38
+ repetition_penalty=repetition_penalty,
39
+ length_penalty=length_penalty,
40
+ early_stopping=early_stopping,
41
+ top_p=top_p,
42
+ top_k=top_k,
43
+ num_return_sequences=num_return_sequences,
44
+ )
45
+ query = [
46
+ tokenizer.decode(
47
+ generated_id,
48
+ skip_special_tokens=True,
49
+ clean_up_tokenization_spaces=True,
50
+ )
51
+ for generated_id in generated_ids
52
+ ][0]
53
+ return query
54
+ ```