Update README.md
Browse files
README.md
CHANGED
@@ -1,202 +1,198 @@
|
|
1 |
---
|
2 |
base_model: Qwen/Qwen2.5-7B
|
3 |
library_name: peft
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
|
|
|
10 |
|
|
|
11 |
|
12 |
## Model Details
|
13 |
|
14 |
### Model Description
|
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 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
## Training Details
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
-
|
173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
-
|
175 |
-
**BibTeX:**
|
176 |
-
|
177 |
-
[More Information Needed]
|
178 |
-
|
179 |
-
**APA:**
|
180 |
-
|
181 |
-
[More Information Needed]
|
182 |
-
|
183 |
-
## Glossary [optional]
|
184 |
-
|
185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
-
|
187 |
-
[More Information Needed]
|
188 |
-
|
189 |
-
## More Information [optional]
|
190 |
-
|
191 |
-
[More Information Needed]
|
192 |
-
|
193 |
-
## Model Card Authors [optional]
|
194 |
-
|
195 |
-
[More Information Needed]
|
196 |
-
|
197 |
-
## Model Card Contact
|
198 |
-
|
199 |
-
[More Information Needed]
|
200 |
-
### Framework versions
|
201 |
-
|
202 |
-
- PEFT 0.14.0
|
|
|
1 |
---
|
2 |
base_model: Qwen/Qwen2.5-7B
|
3 |
library_name: peft
|
4 |
+
language:
|
5 |
+
- en
|
6 |
+
license: agpl-3.0
|
7 |
+
datasets:
|
8 |
+
- OramaSearch/nlp-to-query-small
|
9 |
---
|
10 |
|
11 |
+
# Query Translator Mini
|
|
|
|
|
12 |
|
13 |
+
This repository contains a fine-tuned version of Qwen 2.5 7B model specialized in translating natural language queries into structured Orama search queries.
|
14 |
|
15 |
+
The model uses PEFT with LoRA to maintain efficiency while achieving high performance.
|
16 |
|
17 |
## Model Details
|
18 |
|
19 |
### Model Description
|
20 |
|
21 |
+
The Query Translator Mini model is designed to convert natural language queries into structured JSON queries compatible with the Orama search engine.
|
22 |
+
|
23 |
+
It understands various data types and query operators, making it versatile for different search scenarios.
|
24 |
+
|
25 |
+
### Key Features
|
26 |
+
|
27 |
+
- Translates natural language to structured Orama queries
|
28 |
+
- Supports multiple field types: string, number, boolean, enum, and arrays
|
29 |
+
- Handles complex query operators: `gt`, `gte`, `lt`, `lte`, `eq`, `between`, `containsAll`
|
30 |
+
- Supports nested properties with dot notation
|
31 |
+
- Works with both full-text search and filtered queries
|
32 |
+
|
33 |
+
## Usage
|
34 |
+
|
35 |
+
```python
|
36 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
37 |
+
from peft import PeftModel
|
38 |
+
|
39 |
+
# Load the model and tokenizer
|
40 |
+
model_name = "your-username/query-translator-mini"
|
41 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
42 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
43 |
+
|
44 |
+
# System Prompt used during training
|
45 |
+
SYSTEM_PROMPT = """
|
46 |
+
You are a tool used to generate synthetic data of Orama queries. Orama is a full-text, vector, and hybrid search engine.
|
47 |
+
|
48 |
+
Let me show you what you need to do with some examples.
|
49 |
+
|
50 |
+
Example:
|
51 |
+
- Query: `"What are the red wines that cost less than 20 dollars?"`
|
52 |
+
- Schema: `{ "name": "string", "content": "string", "price": "number", "tags": "enum[]" }`
|
53 |
+
- Generated query: `{ "term": "", "where": { "tags": { "containsAll": ["red", "wine"] }, "price": { "lt": 20 } } }`
|
54 |
+
|
55 |
+
Another example:
|
56 |
+
- Query: `"Show me 5 prosecco wines good for aperitif"`
|
57 |
+
- Schema: `{ "name": "string", "content": "string", "price": "number", "tags": "enum[]" }`
|
58 |
+
- Generated query: `{ "term": "prosecco aperitif", "limit": 5 }`
|
59 |
+
|
60 |
+
One last example:
|
61 |
+
- Query: `"Show me some wine reviews with a score greater than 4.5 and less than 5.0."`
|
62 |
+
- Schema: `{ "title": "string", "content": "string", "reviews": { "score": "number", "text": "string" } }]`
|
63 |
+
- Generated query: `{ "term": "", "where": { "reviews.score": { "between": [4.5, 5.0] } } }`
|
64 |
+
|
65 |
+
The rules to generate the query are:
|
66 |
+
|
67 |
+
- Never use an "embedding" field in the schema.
|
68 |
+
- Every query has a "term" field that is a string. It represents the full-text search terms. Can be empty (will match all documents).
|
69 |
+
- You can use a "where" field that is an object. It represents the filters to apply to the documents. Its keys and values depend on the schema of the database:
|
70 |
+
- If the field is a "string", you should not use operators. Example: `{ "where": { "title": "champagne" } }`.
|
71 |
+
- If the field is a "number", you can use the following operators: "gt", "gte", "lt", "lte", "eq", "between". Example: `{ "where": { "price": { "between": [20, 100] } } }`. Another example: `{ "where": { "price": { "lt": 20 } } }`.
|
72 |
+
- If the field is an "enum", you can use the following operators: "eq", "in", "nin". Example: `{ "where": { "tags": { "containsAll": ["red", "wine"] } } }`.
|
73 |
+
- If the field is an "string[]", it's gonna be just like the "string" field, but you can use an array of values. Example: `{ "where": { "title": ["champagne", "montagne"] } }`.
|
74 |
+
- If the field is a "boolean", you can use the following operators: "eq". Example: `{ "where": { "isAvailable": true } }`. Another example: `{ "where": { "isAvailable": false } }`.
|
75 |
+
- If the field is a "enum[]", you can use the following operators: "containsAll". Example: `{ "where": { "tags": { "containsAll": ["red", "wine"] } } }`.
|
76 |
+
- Nested properties are supported. Just translate them into dot notation. Example: `{ "where": { "author.name": "John" } }`.
|
77 |
+
- Array of numbers are not supported.
|
78 |
+
- Array of booleans are not supported.
|
79 |
+
"""
|
80 |
+
|
81 |
+
# Example query
|
82 |
+
query = "What are the red wines that cost less than 20 dollars?"
|
83 |
+
|
84 |
+
# Orama schema
|
85 |
+
schema = {
|
86 |
+
"name": "string",
|
87 |
+
"content": "string",
|
88 |
+
"price": "number",
|
89 |
+
"tags": "enum[]"
|
90 |
+
}
|
91 |
+
|
92 |
+
# Generate structured query
|
93 |
+
messages = [
|
94 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
95 |
+
{"role": "user", "content": f"Query: {query}\nSchema: {json.dumps(schema)}"},
|
96 |
+
]
|
97 |
+
|
98 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
99 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
100 |
+
outputs = model.generate(
|
101 |
+
**inputs,
|
102 |
+
max_length=512,
|
103 |
+
temperature=0.1,
|
104 |
+
top_p=0.9,
|
105 |
+
num_return_sequences=1,
|
106 |
+
)
|
107 |
+
|
108 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
109 |
+
```
|
110 |
|
111 |
## Training Details
|
112 |
|
113 |
+
The model was trained on a NVIDIA H100 SXM using the following configuration:
|
114 |
+
|
115 |
+
- Base Model: Qwen 2.5 7B
|
116 |
+
- Training Method: LoRA
|
117 |
+
- Quantization: 4-bit quantization using bitsandbytes
|
118 |
+
- LoRA Configuration:
|
119 |
+
- Rank: 16
|
120 |
+
- Alpha: 32
|
121 |
+
- Dropout: 0.1
|
122 |
+
- Target Modules: Attention layers and MLP
|
123 |
+
|
124 |
+
- Training Arguments:
|
125 |
+
- Epochs: 3
|
126 |
+
- Batch Size: 2
|
127 |
+
- Learning Rate: 5e-5
|
128 |
+
- Gradient Accumulation Steps: 8
|
129 |
+
- FP16 Training: Enabled
|
130 |
+
- Gradient Checkpointing: Enabled
|
131 |
+
|
132 |
+
## Supported Query Types
|
133 |
+
|
134 |
+
The model can handle various types of queries including:
|
135 |
+
|
136 |
+
1. Simple text search:
|
137 |
+
|
138 |
+
```json
|
139 |
+
{
|
140 |
+
"term": "prosecco aperitif",
|
141 |
+
"limit": 5
|
142 |
+
}
|
143 |
+
```
|
144 |
+
|
145 |
+
2. Numeric range queries:
|
146 |
+
|
147 |
+
```json
|
148 |
+
{
|
149 |
+
"term": "",
|
150 |
+
"where": {
|
151 |
+
"price": {
|
152 |
+
"between": [20, 100]
|
153 |
+
}
|
154 |
+
}
|
155 |
+
}
|
156 |
+
```
|
157 |
+
|
158 |
+
3. Tag-based filtering:
|
159 |
+
|
160 |
+
```json
|
161 |
+
{
|
162 |
+
"term": "",
|
163 |
+
"where": {
|
164 |
+
"tags": {
|
165 |
+
"containsAll": ["red", "wine"]
|
166 |
+
}
|
167 |
+
}
|
168 |
+
}
|
169 |
+
```
|
170 |
+
|
171 |
+
## Limitations
|
172 |
+
|
173 |
+
- Does not support array of numbers or booleans
|
174 |
+
- Maximum input length is 1024 tokens
|
175 |
+
- Embedding fields are not supported in the schema
|
176 |
+
|
177 |
+
## Citation
|
178 |
+
|
179 |
+
If you use this model in your research, please cite:
|
180 |
+
|
181 |
+
```
|
182 |
+
@misc{query-translator-mini,
|
183 |
+
author = {OramaSearch Inc.},
|
184 |
+
title = {Query Translator Mini: Natural Language to Orama Query Translation},
|
185 |
+
year = {2024},
|
186 |
+
publisher = {HuggingFace},
|
187 |
+
journal = {HuggingFace Repository},
|
188 |
+
howpublished = {\url{https://huggingface.co/OramaSearch/query-translator-mini}}
|
189 |
+
}
|
190 |
+
```
|
191 |
+
|
192 |
+
## License
|
193 |
+
|
194 |
+
AGPLv3
|
195 |
+
|
196 |
+
## Acknowledgments
|
197 |
+
|
198 |
+
This model builds upon the Qwen 2.5 7B model and uses techniques from the PEFT library. Special thanks to the teams behind these projects.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|