Models that generate SQL queries from user input and a specified database source.
data_blob
, which should contains:
./experiments
directory to store the outputs.
train
or test
. Based on that it will create an
experiment folder. So suppose your name is experiment is: βtest_generatorsβ then it will create a folder
./experiments/test_generators_test
or ./experiments/test_generators_train
based on the type.
./experiments
directory.
Text2SQLGeneratorHF
utilizes Hugging Face Transformers. You can use any model from the
Hugging Face model hub. Now letβs generate answer for a single data point.
Output
dict
The data blob containing the prompt and other required information.Optional[float]
, default=0.0
The temperature value for sampling. Higher values increase diversity.Optional[int]
, default=256
The maximum number of tokens to generate.Optional[bool]
, default=True
Whether to postprocess the generated SQL query.dict
Additional arguments passed to the model or any other configurations.generate
method runs a single inference without saving results.
To generate and save multiple responses inside the experiment_path
, use the generate_and_save
method.
experiment_path
as predict.json
.
On subsequent runs, the cached results are reused unless force=True
is specified.
predict.json
file.
SQLiteExecutor
. You can use any other executors as well.
Hereβs how to use it with generate_and_save
method:
mlx
is installed. If not you can install it by:
Text2SQLGenerator
class. This will
allow you to define your own generation strategies, models, and other configurations but
still use the same API as the built-in generators. Here is an example on how you can do that.
To define custom generator, you need to define four methods (mandatory):
load_client
: Load the model and other configurations. This method acts like property
and should return the model object.
load_tokenizer
: Load the tokenizer for the model. This method acts like property
and should return the tokenizer object. In case your generator is not using any tokenizer, just return None.
generate
: Generate the SQL query from the prompt. This method should return the SQL query. So what ever
logic is needed to run the model should be dumped here, such that the output is a single SQL query.
model_name_or_path
: Here you need to return a string which will tell either the name of the model used or
the path to load the model.