Skip to content

Commit

Permalink
Auto generate a config from a dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
qchiujunhao committed Apr 2, 2024
1 parent 8cc5c50 commit 905a2e2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tools/ludwig_autogencofig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import argparse

import logging

from ludwig import automl
from ludwig.utils import defaults

logging.basicConfig(level=logging.DEBUG)
LOG = logging.getLogger(__name__)

def main():
parser = argparse.ArgumentParser(description='Render a Ludwig config')
parser.add_argument('--dataset', type=str, help='Path to the dataset file', required=True)
parser.add_argument('--output_feature', type=str, help='Name for the output feature', required=True)
parser.add_argument('--output', type=str, help='Path for the output file', required=True)
args = parser.parse_args()


args_init = ["--dataset", args.dataset, "--target", args.output_feature, "--output", args.output]
automl.cli_init_config(args_init)
args_render = ["--config", args.output, "--output", args.output]
defaults.cli_render_config(args_render)

if __name__ == "__main__":
main()
41 changes: 41 additions & 0 deletions tools/ludwig_autogencofig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<tool id="ludwig_config_generator" name="Ludwig Config Generator" version="@VERSION@" profile="@PROFILE@">
<description>Auto-generate a config file from a dataset for Ludwig training.</description>
<macros>
<import>ludwig_macros.xml</import>
</macros>
<expand macro="python_requirements" />
<expand macro="macro_stdio" />
<version_command>echo "@VERSION@"</version_command>
<command>
<![CDATA[
#if $input_file
ln -sf '$input_file' "`pwd`/${input_file.element_identifier}";
#end if
python '$__tool_directory__/ludwig_autogencofig.py'
#if $input_file
--dataset "`pwd`/${input_file.element_identifier}"
#end if
--output_feature '$output_feature'
--output '$output'
]]>
</command>
<inputs>
<param name="input_file" type="data" label="Select CSV File" format="tabular,csv,h5,json,txt" help="Choose a dataset file for processing">

</param>

<!-- <param name="output_feature" type="" data_ref="input_file" multiple="True" numerical="False" label="Output Feature"> -->
<param argument="output_feature" type="text" value="" label="Output Feature" />
<param name="config" type="text" area="true" />
</inputs>

<outputs>
<data name="output" format="yaml" label="${tool.name}" />
</outputs>

<tests>
<test>
<!-- TO DO -->
</test>
</tests>
</tool>

0 comments on commit 905a2e2

Please sign in to comment.