UNPKG

1.97 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2020 Google LLC. All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 * =============================================================================
16 */
17/// <amd-module name="@tensorflow/tfjs-core/dist/ops/one_hot" />
18import { Tensor } from '../tensor';
19import { TensorLike } from '../types';
20/**
21 * Creates a one-hot `tf.Tensor`. The locations represented by `indices` take
22 * value `onValue` (defaults to 1), while all other locations take value
23 * `offValue` (defaults to 0). If `indices` is rank `R`, the output has rank
24 * `R+1` with the last axis of size `depth`.
25 * `indices` used to encode prediction class must start from 0. For example,
26 * if you have 3 classes of data, class 1 should be encoded as 0, class 2
27 * should be 1, and class 3 should be 2.
28 *
29 * ```js
30 * tf.oneHot(tf.tensor1d([0, 1], 'int32'), 3).print();
31 * ```
32 *
33 * @param indices `tf.Tensor` of indices with dtype `int32`. Indices must
34 * start from 0.
35 * @param depth The depth of the one hot dimension.
36 * @param onValue A number used to fill in the output when the index matches
37 * the location.
38 * @param offValue A number used to fill in the output when the index does
39 * not match the location.
40 *
41 * @doc {heading: 'Tensors', subheading: 'Creation'}
42 */
43declare function oneHot_(indices: Tensor | TensorLike, depth: number, onValue?: number, offValue?: number): Tensor;
44export declare const oneHot: typeof oneHot_;
45export {};