Turi Create
4.0
|
#include <model_server/lib/extensions/ml_model.hpp>
Public Member Functions | |
virtual void | init_options (const std::map< std::string, flexible_type > &_options) |
std::vector< std::string > | list_fields () |
const variant_type & | get_value_from_state (std::string key) |
const std::map< std::string, flexible_type > & | get_current_options () const |
std::map< std::string, flexible_type > | get_default_options () const |
const flexible_type & | get_option_value (const std::string &name) const |
const std::map< std::string, variant_type > & | get_state () const |
bool | is_trained () const |
void | set_options (const std::map< std::string, flexible_type > &_options) |
void | add_or_update_state (const std::map< std::string, variant_type > &dict) |
const std::vector< option_handling::option_info > & | get_option_info () const |
virtual const char * | name ()=0 |
virtual const std::string & | uid ()=0 |
virtual void | save_impl (oarchive &oarc) const |
virtual void | load_version (iarchive &iarc, size_t version) |
void | save_to_url (const std::string &url, const variant_map_type &side_data={}) |
void | save_model_to_data (std::ostream &out) |
virtual size_t | get_version () const |
const std::map< std::string, std::vector< std::string > > & | list_functions () |
const std::vector< std::string > & | list_get_properties () |
const std::vector< std::string > & | list_set_properties () |
variant_type | call_function (const std::string &function, variant_map_type argument) |
variant_type | get_property (const std::string &property) |
variant_type | set_property (const std::string &property, variant_map_type argument) |
const std::string & | get_docstring (const std::string &symbol) |
virtual void | perform_registration () |
Protected Member Functions | |
void | register_function (std::string fnname, const std::vector< std::string > &arguments, impl_fn fn) |
void | register_defaults (const std::string &fnname, const variant_map_type &arguments) |
void | register_setter (const std::string &propname, impl_fn setfn) |
void | register_getter (const std::string &propname, impl_fn getfn) |
void | register_docstring (const std::pair< std::string, std::string > &fnname_docstring) |
Protected Attributes | |
std::map< std::string, variant_type > | state |
Base class for handling machine learning models. This class is meant to be a guide to aid model writing and not a hard and fast rule of how the code must be structured.
Each machine learning C++ toolkit contains the following:
*) state: This is the key-value map that stores the "model" attributes. The value is of type "variant_type" which is fully interfaced with python. You can add basic types, vectors, SFrames etc.
*) options: Option manager which keeps track of default options, current options, option ranges, type etc. This must be initialized only once in the set_options() function.
Functions that should always be implemented. Here are some notes about each of these functions that may help guide you in writing your model.
*) name: Get the name of this model. You might thinks that this is silly but the name holds the key to everything. The unity_server can construct model_base objects and they can be cast to a model of this type. The name determine how the casting happens. The init_models() function in unity_server.cpp will give you an idea of how this interface happens.
*) save: Save the model with the turicreate iarc. Turi is a server-client module. DO NOT SAVE ANYTHING in the client side. Make sure that everything is in the server side. For example: You might be tempted do keep options that the user provides into the server side but DO NOT do that because save and load will break things for you!
*) load: Load the model with the turicreate oarc.
*) version: A get version for this model
Definition at line 64 of file ml_model.hpp.
void turi::ml_model_base::add_or_update_state | ( | const std::map< std::string, variant_type > & | dict | ) |
Append the key value store of the model.
[in] | dict | Options (Key-Value pairs) to set |
|
inherited |
Calls a user defined function.
const std::map<std::string, flexible_type>& turi::ml_model_base::get_current_options | ( | ) | const |
Get current options.
Interfaces with the get_current_options function in the Python side.
std::map<std::string, flexible_type> turi::ml_model_base::get_default_options | ( | ) | const |
Get default options.
Interfaces with the get_default_options function in the Python side.
|
inherited |
Returns the toolkit documentation for a function or property.
const std::vector<option_handling::option_info>& turi::ml_model_base::get_option_info | ( | ) | const |
Returns the option information struct for each of the set parameters.
const flexible_type& turi::ml_model_base::get_option_value | ( | const std::string & | name | ) | const |
Returns the value of an option. Throws an error if the option does not exist.
[in] | name | Name of the option to get. |
|
inherited |
Reads a property.
const std::map<std::string, variant_type>& turi::ml_model_base::get_state | ( | ) | const |
Get model.
const variant_type& turi::ml_model_base::get_value_from_state | ( | std::string | key | ) |
Returns the value of a particular key from the state.
From the python side, this is interfaced with the get() function or the [] operator in python.
|
inlinevirtualinherited |
Returns the current version of the toolkit class for this instance, for serialization purposes.
Reimplemented in turi::kmeans::kmeans_model, turi::recsys::recsys_model_base, turi::model_proxy, turi::supervised::xgboost::xgboost_model, turi::text::topic_model, turi::pattern_mining::fp_growth, turi::supervised::logistic_regression, turi::supervised::linear_svm, turi::sdk_model::feature_engineering::random_projection, turi::text::alias_topic_model, turi::sdk_model::feature_engineering::feature_binner, turi::sdk_model::feature_engineering::sample_transformer, turi::supervised::linear_regression, turi::sdk_model::feature_engineering::transformer_base, turi::sdk_model::feature_engineering::count_featurizer, and turi::simple_model.
Definition at line 130 of file model_base.hpp.
|
inlinevirtual |
Set one of the options in the algorithm. Use the option manager to set these options. If the option does not satisfy the conditions that the option manager has imposed on it. Errors will be thrown.
[in] | options | Options to set |
Reimplemented in turi::kmeans::kmeans_model, turi::pattern_mining::fp_growth, turi::text::topic_model, turi::recsys::recsys_itemcf, turi::supervised::logistic_regression, turi::supervised::linear_svm, turi::sdk_model::feature_engineering::transformer_base, turi::text::alias_topic_model, turi::sdk_model::feature_engineering::random_projection, turi::supervised::xgboost::xgboost_model, turi::sdk_model::feature_engineering::feature_binner, turi::supervised::xgboost::boosted_trees_classifier, turi::supervised::xgboost::random_forest_classifier, turi::sdk_model::feature_engineering::count_featurizer, turi::sdk_model::feature_engineering::sample_transformer, turi::supervised::linear_regression, turi::supervised::xgboost::boosted_trees_regression, turi::supervised::xgboost::random_forest_regression, and turi::recsys::recsys_factorization_model_base.
Definition at line 80 of file ml_model.hpp.
bool turi::ml_model_base::is_trained | ( | ) | const |
Is this model trained.
std::vector<std::string> turi::ml_model_base::list_fields | ( | ) |
Lists all the keys accessible in the "model" map.
This is the function that the list_fields should call in python.
|
inherited |
Lists all the registered functions. Returns a map of function name to array of argument names for the function.
|
inherited |
Lists all the get-table properties of the class.
|
inherited |
Lists all the set-table properties of the class.
|
inlinevirtualinherited |
Loads a toolkit class previously saved at a particular version number. Should raise an exception on failure.
Reimplemented in turi::kmeans::kmeans_model, turi::recsys::recsys_model_base, turi::model_proxy, turi::supervised::xgboost::xgboost_model, turi::pattern_mining::fp_growth, turi::text::topic_model, turi::supervised::logistic_regression, turi::supervised::linear_svm, turi::sdk_model::feature_engineering::random_projection, turi::text::alias_topic_model, turi::supervised::linear_regression, turi::sdk_model::feature_engineering::feature_binner, turi::sdk_model::feature_engineering::sample_transformer, turi::sdk_model::feature_engineering::transformer_base, turi::sdk_model::feature_engineering::count_featurizer, and turi::simple_model.
Definition at line 96 of file model_base.hpp.
|
pure virtualinherited |
Returns the name of the toolkit class, as exposed to client code. For example, the Python proxy for this instance will have a type with this name.
Note: this function is typically overridden using the BEGIN_CLASS_MEMBER_REGISTRATION macro.
|
virtualinherited |
Declare the base registration function. This class has to be handled specially; the macros don't work here due to the override declarations.
Reimplemented in turi::model_proxy.
|
protectedinherited |
Registers default argument values
|
protectedinherited |
Adds a docstring for the specified function or property name.
|
protectedinherited |
Adds a function with the specified name, and argument list.
|
protectedinherited |
Adds a property getter with the specified name.
|
protectedinherited |
Adds a property setter with the specified name.
|
inlinevirtualinherited |
Serializes the toolkit class. Must save the class to the file format version matching that of get_version().
Reimplemented in turi::kmeans::kmeans_model, turi::recsys::recsys_model_base, turi::model_proxy, turi::supervised::xgboost::xgboost_model, turi::pattern_mining::fp_growth, turi::text::topic_model, turi::supervised::logistic_regression, turi::supervised::linear_svm, turi::sdk_model::feature_engineering::random_projection, turi::text::alias_topic_model, turi::supervised::linear_regression, turi::sdk_model::feature_engineering::feature_binner, turi::sdk_model::feature_engineering::sample_transformer, turi::sdk_model::feature_engineering::transformer_base, turi::sdk_model::feature_engineering::count_featurizer, and turi::simple_model.
Definition at line 87 of file model_base.hpp.
|
inherited |
Save a toolkit class to a data stream.
|
inherited |
Save a toolkit class to disk.
url | The destination url to store the class. |
sidedata | Any additional side information |
void turi::ml_model_base::set_options | ( | const std::map< std::string, flexible_type > & | _options | ) |
Set one of the options in the algorithm.
The value are checked with the requirements given by the option instance.
[in] | name | Name of the option. |
[in] | value | Value for the option. |
|
inherited |
Sets a property. The new value of the property should appear in the argument map under the key "value".
|
pure virtualinherited |
Returns a unique identifier for the toolkit class. It can be any unique ID. The UID is only used at runtime (to determine the concrete type of an arbitrary model_base instance) and is never stored.
Note: this function is typically overridden using the BEGIN_CLASS_MEMBER_REGISTRATION macro.
Implemented in turi::model_proxy.
|
protected |
All things python
Definition at line 206 of file ml_model.hpp.