17.4.4 Unsupervised GraphWiseモデルのサポート対象のプロパティ・タイプ
モデルは、頂点とエッジの両方に2つのタイプのプロパティをサポートします。
continuous properties
(boolean、double、float、integer、long)categorical properties
(string)
カテゴリ・プロパティの場合、次の2つのカテゴリ構成が可能です。
- One-hotエンコーディング: 各カテゴリはベクトルにマップされ、他の機能に連結されます(デフォルト)
- 埋込み表: 各カテゴリは他の機能に連結される埋込みにマップされ、モデルとともにトレーニングされます
One-hotエンコーディングは、各カテゴリを独立したベクトルに変換します。これは、各カテゴリを等しく独立したグループとして解釈する場合に便利です。たとえば、AからEまでの範囲のカテゴリがあり、各アルファベットに固有の意味がない場合、one-hotエンコーディングが適しています。
埋込み表は、プロパティのセマンティクスが重要で、特定のカテゴリが他のカテゴリよりも近い場合に推奨されます。たとえば、月曜日から日曜日までの範囲の値を持つday
プロパティがあるとします。火曜日が土曜日より水曜日に近いという考えを保持する場合は、埋込み表構成を選択すると、トレーニング中にカテゴリを表すベクトルを学習できるようになるため、火曜日にマップされるベクトルが水曜日のベクトルに近い状態になります。
埋込み表アプローチがone-hotエンコーディングよりも優れている利点の1つは、各カテゴリを表すためにより適切なベクトルを学習できることです。ただし、これは、埋込み表を適切にトレーニングするために十分な量のデータが必要であることを意味します。トレーニング・データが限られているユースケースでは、one-hotエンコーディング・アプローチの方が適している場合があります。
埋込み表を使用する場合、ユーザーはボキャブラリ外の確率を設定できます。指定された確率で、推論中に表示されないカテゴリに対してモデルがより堅牢になるように、埋込みがトレーニング中にランダムに埋め込まれるボキャブラリ外に設定されます。
opg4j> import oracle.pgx.config.mllib.inputconfig.CategoricalPropertyConfig;
opg4j> var prop1config = analyst.categoricalPropertyConfigBuilder("vertex_str_feature_1").
oneHotEncoding().
setMaxVocabularySize(100).
build()
opg4j> var prop2config = analyst.categoricalPropertyConfigBuilder("vertex_str_feature_2").
embeddingTable().
setShared(false). // set whether to share the vocabulary or not when several vertex types have a property with the same name
setEmbeddingDimension(32).
setOutOfVocabularyProbability(0.001). // probability to set the word embedding to the out-of-vocabulary embedding
build()
opg4j> var model = analyst.unsupervisedGraphWiseModelBuilder().
setVertexInputPropertyNames(
"vertex_int_feature_1", // continuous feature
"vertex_str_feature_1", // string feature using one-hot-encoding
"vertex_str_feature_2", // string feature using embedding table
"vertex_str_feature_3" // string feature using one-hot-encoding (default)
).
setVertexInputPropertyConfigs(prop1config, prop2config).
build()
import oracle.pgx.config.mllib.inputconfig.CategoricalPropertyConfig;
import oracle.pgx.config.mllib.inputconfig.InputPropertyConfig;
InputPropertyConfig prop1config = analyst.categoricalPropertyConfigBuilder("vertex_str_feature_1")
.oneHotEncoding()
.setMaxVocabularySize(100)
.build();
InputPropertyConfig prop2config = analyst.categoricalPropertyConfigBuilder("vertex_str_feature_2")
.embeddingTable()
.setShared(false) // set whether to share the vocabulary or not when several vertex types have a property with the same name
.setEmbeddingDimension(32)
.setOutOfVocabularyProbability(0.001) // probability to set the word embedding to the out-of-vocabulary embedding
.build();
SupervisedGraphWiseModelBuilder model = analyst.unsupervisedGraphWiseModelBuilder()
.setVertexInputPropertyNames(
"vertex_int_feature_1", // continuous feature
"vertex_str_feature_1", // string feature using one-hot-encoding
"vertex_str_feature_2", // string feature using embedding table
"vertex_str_feature_3" // string feature using one-hot-encoding (default)
)
.setVertexInputPropertyConfigs(prop1config, prop2config)
.build();
vertex_input_property_configs = [
analyst.one_hot_encoding_categorical_property_config(
property_name="vertex_str_feature_1",
max_vocabulary_size=100,
),
analyst.learned_embedding_categorical_property_config(
property_name="vertex_str_feature_2",
embedding_dim=4,
shared=False, // set whether to share the vocabulary or not when several types have a property with the same name
oov_probability=0.001 // probability to set the word embedding to the out-of-vocabulary embedding
)
]
model_params = dict(
vertex_input_property_names=[
"vertex_int_feature_1", // continuous feature
"vertex_str_feature_1", // string feature using one-hot-encoding
"vertex_str_feature_2", // string feature using embedding table
"vertex_str_feature_3", // string feature using one-hot-encoding (default)
],
vertex_input_property_configs=vertex_input_property_configs
)
model = analyst.supervised_graphwise_builder(**model_params)