6 #ifndef TURI_RECSYS_MODEL_ITEMCF_H_ 7 #define TURI_RECSYS_MODEL_ITEMCF_H_ 11 #include <model_server/lib/extensions/option_manager.hpp> 12 #include <toolkits/coreml_export/mlmodel_wrapper.hpp> 13 #include <toolkits/recsys/recsys_model_base.hpp> 14 #include <core/generics/symmetric_2d_array.hpp> 28 class sparse_similarity_lookup;
98 bool use_target_column(
bool target_is_present)
const override {
99 return target_is_present;
102 static constexpr
size_t ITEMCF_VERSION = 2;
104 void init_options(
const std::map<std::string, flexible_type>& options)
override;
110 void set_extra_data(
const std::map<std::string, variant_type>& extra_data)
override;
111 void load_user_provided_data();
113 struct user_provided_data_struct {
117 std::shared_ptr<user_provided_data_struct> user_provided_data;
124 std::map<std::string, flexible_type> train(
const v2::ml_data& data)
override;
135 sframe predict(
const v2::ml_data& test_data)
const override;
137 std::vector<double> predict_all_items(
138 const std::vector<flexible_type>& base_observation)
const;
141 mutable atomic<int> user_item_buffers_setup;
142 mutable std::vector<std::vector<std::pair<size_t, double> > > user_item_buffers_by_thread;
143 mutable mutex init_user_item_buffers_lock;
146 void _score_items(std::vector<std::pair<size_t, double> >& item_scores,
147 const std::vector<std::pair<size_t, double> >& user_scores)
const;
159 void score_all_items(
160 std::vector<std::pair<size_t, double> >& scores,
161 const std::vector<v2::ml_data_entry>& query_row,
163 const std::vector<std::pair<size_t, double> >& user_item_list,
164 const std::vector<std::pair<size_t, double> >& new_user_item_data,
165 const std::vector<v2::ml_data_row_reference>& new_observation_data,
166 const std::shared_ptr<v2::ml_data_side_features>& known_side_features)
const override;
171 std::string response_column_name()
const;
173 inline size_t internal_get_version()
const override {
174 return ITEMCF_VERSION;
178 void internal_load(
turi::iarchive& iarc,
size_t version)
override;
184 std::shared_ptr<sparse_similarity_lookup>
item_sim;
189 std::vector<std::pair<size_t, double> > new_user_seed_items;
190 std::vector<double> item_mean_score;
191 double item_mean_min=0, item_mean_max=0;
214 log_and_throw(
"get_similar_users currently not supported for item similarity models. " 215 "To get the neighborhood of users, train a model with the items and users reversed, " 216 "then call get_similar_items.");
221 virtual std::shared_ptr<coreml::MLModelWrapper> export_to_coreml(
222 const std::string& filename,
223 const std::map<std::string, flexible_type>& additional_user_defined)
228 void make_user_item_graph(
const v2::ml_data& data,
232 std::shared_ptr<sparse_similarity_lookup> create_similarity_lookup()
const;
#define BEGIN_CLASS_MEMBER_REGISTRATION(python_facing_classname)
The serialization input archive object which, provided with a reference to an istream, will read from the istream, providing deserialization capabilities.
std::shared_ptr< sparse_similarity_lookup > item_sim
#define IMPORT_BASE_CLASS_REGISTRATION(base_class)
sframe get_similar_users(std::shared_ptr< sarray< flexible_type > > items, size_t topk=0) const override
#define END_CLASS_MEMBER_REGISTRATION
The serialization output archive object which, provided with a reference to an ostream, will write to the ostream, providing serialization capabilities.