Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,57 @@
|
|
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 Neo4j (Cypher) 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. More information can be found on the repository.
|
10 |
+
|
11 |
+
```python
|
12 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
13 |
+
import torch
|
14 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("Chirayu/nl2cql")
|
15 |
+
tokenizer = AutoTokenizer.from_pretrained("Chirayu/nl2cql")
|
16 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
17 |
+
model = model.to(device)
|
18 |
+
|
19 |
+
textual_query = '''cypher: find the outcomes of people who are female and below the age of 32 | case : gender, reportdate, ageunit, reporteroccupation, primaryid, age, eventDate | outcome : code, outcome | relationships : resulted_in'''
|
20 |
+
|
21 |
+
def generate_query(
|
22 |
+
textual_query: str,
|
23 |
+
num_beams: int = 10,
|
24 |
+
max_length: int = 128,
|
25 |
+
repetition_penalty: int = 2.5,
|
26 |
+
length_penalty: int = 1,
|
27 |
+
early_stopping: bool = True,
|
28 |
+
top_p: int = 0.95,
|
29 |
+
top_k: int = 50,
|
30 |
+
num_return_sequences: int = 1,
|
31 |
+
) -> str:
|
32 |
+
input_ids = tokenizer.encode(
|
33 |
+
textual_query, return_tensors="pt", add_special_tokens=True
|
34 |
+
)
|
35 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
36 |
+
input_ids = input_ids.to(device)
|
37 |
+
generated_ids = model.generate(
|
38 |
+
input_ids=input_ids,
|
39 |
+
num_beams=num_beams,
|
40 |
+
max_length=max_length,
|
41 |
+
repetition_penalty=repetition_penalty,
|
42 |
+
length_penalty=length_penalty,
|
43 |
+
early_stopping=early_stopping,
|
44 |
+
top_p=top_p,
|
45 |
+
top_k=top_k,
|
46 |
+
num_return_sequences=num_return_sequences,
|
47 |
+
)
|
48 |
+
query = [
|
49 |
+
tokenizer.decode(
|
50 |
+
generated_id,
|
51 |
+
skip_special_tokens=True,
|
52 |
+
clean_up_tokenization_spaces=True,
|
53 |
+
)
|
54 |
+
for generated_id in generated_ids
|
55 |
+
][0]
|
56 |
+
return query
|
57 |
+
```
|