explanation.proto 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.cloud.aiplatform.v1beta1;
  16. import "google/api/field_behavior.proto";
  17. import "google/cloud/aiplatform/v1beta1/explanation_metadata.proto";
  18. import "google/cloud/aiplatform/v1beta1/io.proto";
  19. import "google/protobuf/struct.proto";
  20. import "google/api/annotations.proto";
  21. option csharp_namespace = "Google.Cloud.AIPlatform.V1Beta1";
  22. option go_package = "google.golang.org/genproto/googleapis/cloud/aiplatform/v1beta1;aiplatform";
  23. option java_multiple_files = true;
  24. option java_outer_classname = "ExplanationProto";
  25. option java_package = "com.google.cloud.aiplatform.v1beta1";
  26. option php_namespace = "Google\\Cloud\\AIPlatform\\V1beta1";
  27. option ruby_package = "Google::Cloud::AIPlatform::V1beta1";
  28. // Explanation of a prediction (provided in [PredictResponse.predictions][google.cloud.aiplatform.v1beta1.PredictResponse.predictions])
  29. // produced by the Model on a given [instance][google.cloud.aiplatform.v1beta1.ExplainRequest.instances].
  30. message Explanation {
  31. // Output only. Feature attributions grouped by predicted outputs.
  32. //
  33. // For Models that predict only one output, such as regression Models that
  34. // predict only one score, there is only one attibution that explains the
  35. // predicted output. For Models that predict multiple outputs, such as
  36. // multiclass Models that predict multiple classes, each element explains one
  37. // specific item. [Attribution.output_index][google.cloud.aiplatform.v1beta1.Attribution.output_index] can be used to identify which
  38. // output this attribution is explaining.
  39. //
  40. // If users set [ExplanationParameters.top_k][google.cloud.aiplatform.v1beta1.ExplanationParameters.top_k], the attributions are sorted
  41. // by [instance_output_value][Attributions.instance_output_value] in
  42. // descending order. If [ExplanationParameters.output_indices][google.cloud.aiplatform.v1beta1.ExplanationParameters.output_indices] is specified,
  43. // the attributions are stored by [Attribution.output_index][google.cloud.aiplatform.v1beta1.Attribution.output_index] in the same
  44. // order as they appear in the output_indices.
  45. repeated Attribution attributions = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
  46. }
  47. // Aggregated explanation metrics for a Model over a set of instances.
  48. message ModelExplanation {
  49. // Output only. Aggregated attributions explaining the Model's prediction outputs over the
  50. // set of instances. The attributions are grouped by outputs.
  51. //
  52. // For Models that predict only one output, such as regression Models that
  53. // predict only one score, there is only one attibution that explains the
  54. // predicted output. For Models that predict multiple outputs, such as
  55. // multiclass Models that predict multiple classes, each element explains one
  56. // specific item. [Attribution.output_index][google.cloud.aiplatform.v1beta1.Attribution.output_index] can be used to identify which
  57. // output this attribution is explaining.
  58. //
  59. // The [baselineOutputValue][google.cloud.aiplatform.v1beta1.Attribution.baseline_output_value],
  60. // [instanceOutputValue][google.cloud.aiplatform.v1beta1.Attribution.instance_output_value] and
  61. // [featureAttributions][google.cloud.aiplatform.v1beta1.Attribution.feature_attributions] fields are
  62. // averaged over the test data.
  63. //
  64. // NOTE: Currently AutoML tabular classification Models produce only one
  65. // attribution, which averages attributions over all the classes it predicts.
  66. // [Attribution.approximation_error][google.cloud.aiplatform.v1beta1.Attribution.approximation_error] is not populated.
  67. repeated Attribution mean_attributions = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
  68. }
  69. // Attribution that explains a particular prediction output.
  70. message Attribution {
  71. // Output only. Model predicted output if the input instance is constructed from the
  72. // baselines of all the features defined in [ExplanationMetadata.inputs][google.cloud.aiplatform.v1beta1.ExplanationMetadata.inputs].
  73. // The field name of the output is determined by the key in
  74. // [ExplanationMetadata.outputs][google.cloud.aiplatform.v1beta1.ExplanationMetadata.outputs].
  75. //
  76. // If the Model's predicted output has multiple dimensions (rank > 1), this is
  77. // the value in the output located by [output_index][google.cloud.aiplatform.v1beta1.Attribution.output_index].
  78. //
  79. // If there are multiple baselines, their output values are averaged.
  80. double baseline_output_value = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
  81. // Output only. Model predicted output on the corresponding [explanation
  82. // instance][ExplainRequest.instances]. The field name of the output is
  83. // determined by the key in [ExplanationMetadata.outputs][google.cloud.aiplatform.v1beta1.ExplanationMetadata.outputs].
  84. //
  85. // If the Model predicted output has multiple dimensions, this is the value in
  86. // the output located by [output_index][google.cloud.aiplatform.v1beta1.Attribution.output_index].
  87. double instance_output_value = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
  88. // Output only. Attributions of each explained feature. Features are extracted from
  89. // the [prediction instances][google.cloud.aiplatform.v1beta1.ExplainRequest.instances] according to
  90. // [explanation metadata for inputs][google.cloud.aiplatform.v1beta1.ExplanationMetadata.inputs].
  91. //
  92. // The value is a struct, whose keys are the name of the feature. The values
  93. // are how much the feature in the [instance][google.cloud.aiplatform.v1beta1.ExplainRequest.instances]
  94. // contributed to the predicted result.
  95. //
  96. // The format of the value is determined by the feature's input format:
  97. //
  98. // * If the feature is a scalar value, the attribution value is a
  99. // [floating number][google.protobuf.Value.number_value].
  100. //
  101. // * If the feature is an array of scalar values, the attribution value is
  102. // an [array][google.protobuf.Value.list_value].
  103. //
  104. // * If the feature is a struct, the attribution value is a
  105. // [struct][google.protobuf.Value.struct_value]. The keys in the
  106. // attribution value struct are the same as the keys in the feature
  107. // struct. The formats of the values in the attribution struct are
  108. // determined by the formats of the values in the feature struct.
  109. //
  110. // The [ExplanationMetadata.feature_attributions_schema_uri][google.cloud.aiplatform.v1beta1.ExplanationMetadata.feature_attributions_schema_uri] field,
  111. // pointed to by the [ExplanationSpec][google.cloud.aiplatform.v1beta1.ExplanationSpec] field of the
  112. // [Endpoint.deployed_models][google.cloud.aiplatform.v1beta1.Endpoint.deployed_models] object, points to the schema file that
  113. // describes the features and their attribution values (if it is populated).
  114. google.protobuf.Value feature_attributions = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
  115. // Output only. The index that locates the explained prediction output.
  116. //
  117. // If the prediction output is a scalar value, output_index is not populated.
  118. // If the prediction output has multiple dimensions, the length of the
  119. // output_index list is the same as the number of dimensions of the output.
  120. // The i-th element in output_index is the element index of the i-th dimension
  121. // of the output vector. Indices start from 0.
  122. repeated int32 output_index = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
  123. // Output only. The display name of the output identified by [output_index][google.cloud.aiplatform.v1beta1.Attribution.output_index]. For example,
  124. // the predicted class name by a multi-classification Model.
  125. //
  126. // This field is only populated iff the Model predicts display names as a
  127. // separate field along with the explained output. The predicted display name
  128. // must has the same shape of the explained output, and can be located using
  129. // output_index.
  130. string output_display_name = 5 [(google.api.field_behavior) = OUTPUT_ONLY];
  131. // Output only. Error of [feature_attributions][google.cloud.aiplatform.v1beta1.Attribution.feature_attributions] caused by approximation used in the
  132. // explanation method. Lower value means more precise attributions.
  133. //
  134. // * For Sampled Shapley
  135. // [attribution][google.cloud.aiplatform.v1beta1.ExplanationParameters.sampled_shapley_attribution],
  136. // increasing [path_count][google.cloud.aiplatform.v1beta1.SampledShapleyAttribution.path_count] might reduce
  137. // the error.
  138. // * For Integrated Gradients
  139. // [attribution][google.cloud.aiplatform.v1beta1.ExplanationParameters.integrated_gradients_attribution],
  140. // increasing [step_count][google.cloud.aiplatform.v1beta1.IntegratedGradientsAttribution.step_count] might
  141. // reduce the error.
  142. // * For [XRAI attribution][google.cloud.aiplatform.v1beta1.ExplanationParameters.xrai_attribution],
  143. // increasing
  144. // [step_count][google.cloud.aiplatform.v1beta1.XraiAttribution.step_count] might reduce the error.
  145. //
  146. // See [this introduction](/vertex-ai/docs/explainable-ai/overview)
  147. // for more information.
  148. double approximation_error = 6 [(google.api.field_behavior) = OUTPUT_ONLY];
  149. // Output only. Name of the explain output. Specified as the key in
  150. // [ExplanationMetadata.outputs][google.cloud.aiplatform.v1beta1.ExplanationMetadata.outputs].
  151. string output_name = 7 [(google.api.field_behavior) = OUTPUT_ONLY];
  152. }
  153. // Specification of Model explanation.
  154. message ExplanationSpec {
  155. // Required. Parameters that configure explaining of the Model's predictions.
  156. ExplanationParameters parameters = 1 [(google.api.field_behavior) = REQUIRED];
  157. // Required. Metadata describing the Model's input and output for explanation.
  158. ExplanationMetadata metadata = 2 [(google.api.field_behavior) = REQUIRED];
  159. }
  160. // Parameters to configure explaining for Model's predictions.
  161. message ExplanationParameters {
  162. oneof method {
  163. // An attribution method that approximates Shapley values for features that
  164. // contribute to the label being predicted. A sampling strategy is used to
  165. // approximate the value rather than considering all subsets of features.
  166. // Refer to this paper for model details: https://arxiv.org/abs/1306.4265.
  167. SampledShapleyAttribution sampled_shapley_attribution = 1;
  168. // An attribution method that computes Aumann-Shapley values taking
  169. // advantage of the model's fully differentiable structure. Refer to this
  170. // paper for more details: https://arxiv.org/abs/1703.01365
  171. IntegratedGradientsAttribution integrated_gradients_attribution = 2;
  172. // An attribution method that redistributes Integrated Gradients
  173. // attribution to segmented regions, taking advantage of the model's fully
  174. // differentiable structure. Refer to this paper for
  175. // more details: https://arxiv.org/abs/1906.02825
  176. //
  177. // XRAI currently performs better on natural images, like a picture of a
  178. // house or an animal. If the images are taken in artificial environments,
  179. // like a lab or manufacturing line, or from diagnostic equipment, like
  180. // x-rays or quality-control cameras, use Integrated Gradients instead.
  181. XraiAttribution xrai_attribution = 3;
  182. }
  183. // If populated, returns attributions for top K indices of outputs
  184. // (defaults to 1). Only applies to Models that predicts more than one outputs
  185. // (e,g, multi-class Models). When set to -1, returns explanations for all
  186. // outputs.
  187. int32 top_k = 4;
  188. // If populated, only returns attributions that have
  189. // [output_index][google.cloud.aiplatform.v1beta1.Attribution.output_index] contained in output_indices. It
  190. // must be an ndarray of integers, with the same shape of the output it's
  191. // explaining.
  192. //
  193. // If not populated, returns attributions for [top_k][google.cloud.aiplatform.v1beta1.ExplanationParameters.top_k] indices of outputs.
  194. // If neither top_k nor output_indeices is populated, returns the argmax
  195. // index of the outputs.
  196. //
  197. // Only applicable to Models that predict multiple outputs (e,g, multi-class
  198. // Models that predict multiple classes).
  199. google.protobuf.ListValue output_indices = 5;
  200. }
  201. // An attribution method that approximates Shapley values for features that
  202. // contribute to the label being predicted. A sampling strategy is used to
  203. // approximate the value rather than considering all subsets of features.
  204. message SampledShapleyAttribution {
  205. // Required. The number of feature permutations to consider when approximating the
  206. // Shapley values.
  207. //
  208. // Valid range of its value is [1, 50], inclusively.
  209. int32 path_count = 1 [(google.api.field_behavior) = REQUIRED];
  210. }
  211. // An attribution method that computes the Aumann-Shapley value taking advantage
  212. // of the model's fully differentiable structure. Refer to this paper for
  213. // more details: https://arxiv.org/abs/1703.01365
  214. message IntegratedGradientsAttribution {
  215. // Required. The number of steps for approximating the path integral.
  216. // A good value to start is 50 and gradually increase until the
  217. // sum to diff property is within the desired error range.
  218. //
  219. // Valid range of its value is [1, 100], inclusively.
  220. int32 step_count = 1 [(google.api.field_behavior) = REQUIRED];
  221. // Config for SmoothGrad approximation of gradients.
  222. //
  223. // When enabled, the gradients are approximated by averaging the gradients
  224. // from noisy samples in the vicinity of the inputs. Adding
  225. // noise can help improve the computed gradients. Refer to this paper for more
  226. // details: https://arxiv.org/pdf/1706.03825.pdf
  227. SmoothGradConfig smooth_grad_config = 2;
  228. }
  229. // An explanation method that redistributes Integrated Gradients
  230. // attributions to segmented regions, taking advantage of the model's fully
  231. // differentiable structure. Refer to this paper for more details:
  232. // https://arxiv.org/abs/1906.02825
  233. //
  234. // Supported only by image Models.
  235. message XraiAttribution {
  236. // Required. The number of steps for approximating the path integral.
  237. // A good value to start is 50 and gradually increase until the
  238. // sum to diff property is met within the desired error range.
  239. //
  240. // Valid range of its value is [1, 100], inclusively.
  241. int32 step_count = 1 [(google.api.field_behavior) = REQUIRED];
  242. // Config for SmoothGrad approximation of gradients.
  243. //
  244. // When enabled, the gradients are approximated by averaging the gradients
  245. // from noisy samples in the vicinity of the inputs. Adding
  246. // noise can help improve the computed gradients. Refer to this paper for more
  247. // details: https://arxiv.org/pdf/1706.03825.pdf
  248. SmoothGradConfig smooth_grad_config = 2;
  249. }
  250. // Config for SmoothGrad approximation of gradients.
  251. //
  252. // When enabled, the gradients are approximated by averaging the gradients from
  253. // noisy samples in the vicinity of the inputs. Adding noise can help improve
  254. // the computed gradients. Refer to this paper for more details:
  255. // https://arxiv.org/pdf/1706.03825.pdf
  256. message SmoothGradConfig {
  257. // Represents the standard deviation of the gaussian kernel
  258. // that will be used to add noise to the interpolated inputs
  259. // prior to computing gradients.
  260. oneof GradientNoiseSigma {
  261. // This is a single float value and will be used to add noise to all the
  262. // features. Use this field when all features are normalized to have the
  263. // same distribution: scale to range [0, 1], [-1, 1] or z-scoring, where
  264. // features are normalized to have 0-mean and 1-variance. Learn more about
  265. // [normalization](https://developers.google.com/machine-learning/data-prep/transform/normalization).
  266. //
  267. // For best results the recommended value is about 10% - 20% of the standard
  268. // deviation of the input feature. Refer to section 3.2 of the SmoothGrad
  269. // paper: https://arxiv.org/pdf/1706.03825.pdf. Defaults to 0.1.
  270. //
  271. // If the distribution is different per feature, set
  272. // [feature_noise_sigma][google.cloud.aiplatform.v1beta1.SmoothGradConfig.feature_noise_sigma] instead
  273. // for each feature.
  274. float noise_sigma = 1;
  275. // This is similar to [noise_sigma][google.cloud.aiplatform.v1beta1.SmoothGradConfig.noise_sigma], but
  276. // provides additional flexibility. A separate noise sigma can be provided
  277. // for each feature, which is useful if their distributions are different.
  278. // No noise is added to features that are not set. If this field is unset,
  279. // [noise_sigma][google.cloud.aiplatform.v1beta1.SmoothGradConfig.noise_sigma] will be used for all
  280. // features.
  281. FeatureNoiseSigma feature_noise_sigma = 2;
  282. }
  283. // The number of gradient samples to use for
  284. // approximation. The higher this number, the more accurate the gradient
  285. // is, but the runtime complexity increases by this factor as well.
  286. // Valid range of its value is [1, 50]. Defaults to 3.
  287. int32 noisy_sample_count = 3;
  288. }
  289. // Noise sigma by features. Noise sigma represents the standard deviation of the
  290. // gaussian kernel that will be used to add noise to interpolated inputs prior
  291. // to computing gradients.
  292. message FeatureNoiseSigma {
  293. // Noise sigma for a single feature.
  294. message NoiseSigmaForFeature {
  295. // The name of the input feature for which noise sigma is provided. The
  296. // features are defined in
  297. // [explanation metadata inputs][google.cloud.aiplatform.v1beta1.ExplanationMetadata.inputs].
  298. string name = 1;
  299. // This represents the standard deviation of the Gaussian kernel that will
  300. // be used to add noise to the feature prior to computing gradients. Similar
  301. // to [noise_sigma][google.cloud.aiplatform.v1beta1.SmoothGradConfig.noise_sigma] but represents the
  302. // noise added to the current feature. Defaults to 0.1.
  303. float sigma = 2;
  304. }
  305. // Noise sigma per feature. No noise is added to features that are not set.
  306. repeated NoiseSigmaForFeature noise_sigma = 1;
  307. }
  308. // The [ExplanationSpec][google.cloud.aiplatform.v1beta1.ExplanationSpec] entries that can be overridden at [online
  309. // explanation][PredictionService.Explain][google.cloud.aiplatform.v1beta1.PredictionService.Explain] time.
  310. message ExplanationSpecOverride {
  311. // The parameters to be overridden. Note that the
  312. // [method][google.cloud.aiplatform.v1beta1.ExplanationParameters.method] cannot be changed. If not specified,
  313. // no parameter is overridden.
  314. ExplanationParameters parameters = 1;
  315. // The metadata to be overridden. If not specified, no metadata is overridden.
  316. ExplanationMetadataOverride metadata = 2;
  317. }
  318. // The [ExplanationMetadata][google.cloud.aiplatform.v1beta1.ExplanationMetadata] entries that can be overridden at
  319. // [online explanation][google.cloud.aiplatform.v1beta1.PredictionService.Explain] time.
  320. message ExplanationMetadataOverride {
  321. // The [input metadata][google.cloud.aiplatform.v1beta1.ExplanationMetadata.InputMetadata] entries to be
  322. // overridden.
  323. message InputMetadataOverride {
  324. // Baseline inputs for this feature.
  325. //
  326. // This overrides the `input_baseline` field of the
  327. // [ExplanationMetadata.InputMetadata][google.cloud.aiplatform.v1beta1.ExplanationMetadata.InputMetadata]
  328. // object of the corresponding feature's input metadata. If it's not
  329. // specified, the original baselines are not overridden.
  330. repeated google.protobuf.Value input_baselines = 1;
  331. }
  332. // Required. Overrides the [input metadata][google.cloud.aiplatform.v1beta1.ExplanationMetadata.inputs] of the features.
  333. // The key is the name of the feature to be overridden. The keys specified
  334. // here must exist in the input metadata to be overridden. If a feature is
  335. // not specified here, the corresponding feature's input metadata is not
  336. // overridden.
  337. map<string, InputMetadataOverride> inputs = 1 [(google.api.field_behavior) = REQUIRED];
  338. }