{"id":444,"date":"2017-02-16T21:25:26","date_gmt":"2017-02-16T21:25:26","guid":{"rendered":"http:\/\/sag.art.uniroma2.it\/kelp_wordpress\/?page_id=444"},"modified":"2018-08-10T22:42:27","modified_gmt":"2018-08-10T22:42:27","slug":"using-the-runnable-jars","status":"publish","type":"page","link":"http:\/\/www.kelp-ml.org\/?page_id=444","title":{"rendered":"Using the runnable jars"},"content":{"rendered":"<p>KeLP adopts a simple and intuitive serialization\/deserialization formalism for objects, such as kernels and algorithms, that is based on JSON (more details in\u00a0this <a href=\"http:\/\/www.kelp-ml.org\/?page_id=186\">page<\/a>).<br \/>\nJSON is the\u00a0JavaScript Object Notation, a standard de facto when exchanging data in WEB, and its main characteristic is that it is easily readable by humans, and that it can be efficiently composed to represent object hierarchies.<\/p>\n<p>This allows to compile stand-alone JAR files (runnable from command line) that read the description of a\u00a0learning algorithm and\/or kernel function and operate over a dataset <strong><em>without<\/em><\/strong>\u00a0the need of new\u00a0Java code.\u00a0In such a way you are free to specify and parameterize your\u00a0learning method via an expressive <em>JSON parameter file<\/em>.<\/p>\n<p>KeLP runnable\u00a0jars\u00a0are meant to provide an easy-to-use way to train, for example, a <strong>classifier<\/strong>, and use it to make predictions. Two java jars are released: the <em>kelp-learn-x.x.x.jar<\/em> can be used to train a classifier and to save a KeLP model (more details about models are available <a href=\"http:\/\/www.kelp-ml.org\/?page_id=186\">here<\/a>); the <em>kelp-classify-x.x.x.jar<\/em> instead can be used to make predictions given an already trained classifier (i.e., a model):<\/p>\n<ul>\n<li>kelp-learn.x.x.x.jar takes in input a training dataset in KeLP format, a learning algorithm specification in JSON language and the path where to save the model;<\/li>\n<li>kelp-classify.x.x.x.jar takes as\u00a0input a dataset, the model path and the path where to save the predictions.<\/li>\n<\/ul>\n<p>The two jars kelp-learn.x.x.x.jar and\u00a0kelp-classify.x.x.x.jar include all the functionalities of <a href=\"http:\/\/disi.unitn.it\/moschitti\/Tree-Kernel.htm\" target=\"_blank\" rel=\"noopener\">svm-light-tk<\/a>\u00a0and provide many more kernels functions and learning algorithms.<\/p>\n<p><strong>Click to the following links\u00a0to download the latest version<\/strong> of <a href=\"http:\/\/www.kelp-ml.org\/kelp-executables\/kelp-learn-2.2.3.jar\" target=\"_blank\" rel=\"noopener\">kelp-learn<\/a> and <a href=\"http:\/\/www.kelp-ml.org\/kelp-executables\/kelp-classify-2.2.3.jar\" target=\"_blank\" rel=\"noopener\">kelp-classify<\/a>.<\/p>\n<p>In order to show how to use the kelp runnable jars, download the <a href=\"http:\/\/www.kelp-ml.org\/kelp-executables\/iris_train.txt\" target=\"_blank\" rel=\"noopener\">training dataset<\/a>, the <a href=\"http:\/\/www.kelp-ml.org\/kelp-executables\/iris_test.txt\" target=\"_blank\" rel=\"noopener\">testing dataset<\/a> and the <a href=\"http:\/\/www.kelp-ml.org\/kelp-executables\/learning_algorithm_specification.json\" target=\"_blank\" rel=\"noopener\">algorithm specification<\/a>.<\/p>\n<p>You can inspect the learning algorithm specification by using a common text editor. It should look like:<\/p>\n<pre>{\r\n  \"algorithm\" : \"oneVsAll\",\r\n  \"baseAlgorithm\" : {\r\n    \"algorithm\" : \"binaryCSvmClassification\",\r\n    \"cp\" : 1.0,\r\n    \"cn\" : 1.0,\r\n    \"kernel\" : {\r\n      \"kernelType\" : \"linear\",\r\n      \"representation\" : \"0\",\r\n      \"kernelID\" : \"1\",\r\n      \"kernelCache\" : {\r\n        \"cacheType\" : \"fixIndex\",\r\n        \"examplesToStore\" : 300\r\n      }\r\n    },\r\n    \"fairness\" : false\r\n  }\r\n}\r\n<\/pre>\n<p>In the JSON specification, it is possible to see that the adopted algorithm is a <a href=\"http:\/\/www.kelp-ml.org\/kelp-javadoc\/current-version\/it\/uniroma2\/sag\/kelp\/learningalgorithm\/classification\/libsvm\/BinaryCSvmClassification.html\" target=\"_blank\" rel=\"noopener\">BinaryCSVM<\/a> with a <a href=\"http:\/\/www.kelp-ml.org\/kelp-javadoc\/current-version\/it\/uniroma2\/sag\/kelp\/kernel\/vector\/LinearKernel.html\" target=\"_blank\" rel=\"noopener\">linear kernel<\/a> that operates on the first (0) representation. <em>C<\/em> parameter is set to <em>1.0<\/em>\u00a0(<em>cp<\/em> and <em>cn<\/em>) and a One-Vs-All approach is adopted to manage multiple classes.<\/p>\n<p><em>Training<\/em> phase: <em>java -jar kelp-learn-2.2.3.jar iris_train.txt learning_algorithm_specification.json model<\/em><\/p>\n<p>After the training stage, you can inspect the model simply by opening it with a text editor. The model is written by KeLP, again, \u00a0in JSON format; in this way, it is easily readable. In this case, a list of support vectors can be recognized in the <em>model.txt<\/em> file.<\/p>\n<p><em>Testing<\/em> phase: <em>java -jar kelp-classify-2.2.3.jar iris_test.txt model predictions.txt<\/em><\/p>\n<p>The output of kelp-classify should be <em>Accuracy on test set: 0.9375.<\/em><\/p>\n<p><em>predictions.txt<\/em> file contains the predictions made by kelp. In this example, a multiclass problem with three classes has been proposed. Each row of <em>predictions.txt<\/em> refer to an example (in the same order) of the iris_test.txt file, and the sore for each label is reported: for example, the first row should be similar to:<\/p>\n<p>iris-setosa:1.5446491 iris-versicolor:-1.8121223 iris-virginica:-9.402145<\/p>\n","protected":false},"excerpt":{"rendered":"<p>KeLP adopts a simple and intuitive serialization\/deserialization formalism for objects, such as kernels and algorithms, that is based on JSON (more details in\u00a0this page). JSON is the\u00a0JavaScript Object Notation, a standard de facto when exchanging data in WEB, and its main characteristic is that it is easily readable by humans, and that it can be <a href=\"http:\/\/www.kelp-ml.org\/?page_id=444\" rel=\"nofollow\"><span class=\"sr-only\">Read more about Using the runnable jars<\/span>[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":37,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages\/444"}],"collection":[{"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=444"}],"version-history":[{"count":20,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages\/444\/revisions"}],"predecessor-version":[{"id":1083,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages\/444\/revisions\/1083"}],"up":[{"embeddable":true,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages\/37"}],"wp:attachment":[{"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}