-
Notifications
You must be signed in to change notification settings - Fork 0
/
layers.pyi
319 lines (301 loc) · 10.8 KB
/
layers.pyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
from abc import ABC
from collections.abc import Mapping
from typing import (
Any,
Callable,
Generic,
Iterable,
Literal,
Sequence,
TypedDict,
TypeVar,
final,
overload,
)
import tensorflow as tf
from tensorflow import DTypeLike, Tensor, Variable
from tensorflow._aliases import (
ContainerInputSpec,
TensorCompatible,
TensorLike,
float_array,
)
from tensorflow.distribute import Strategy
from tensorflow.keras.activations import ActivationT
from tensorflow.keras.constraints import ConstraintT
from tensorflow.keras.initializers import InitializerT
from tensorflow.keras.regularizers import RegularizerT
from tensorflow.python.feature_column.feature_column_v2 import (
DenseColumn,
SequenceDenseColumn,
)
from typing_extensions import Self, Unpack
_InputT = TypeVar("_InputT", contravariant=True)
_OutputT = TypeVar("_OutputT", covariant=True)
class InputSpec:
dtype: str | None
shape: tf.TensorShape | None
ndim: int | None
max_ndim: int | None
min_ndim: int | None
axes: dict[int, int | None] | None
def __init__(
self,
dtype: tf.DTypeLike | None = None,
shape: Iterable[int | None] | None = None,
ndim: int | None = None,
max_ndim: int | None = None,
min_ndim: int | None = None,
axes: dict[int, int | None] | None = None,
allow_last_axis_squeeze: bool = False,
): ...
class _LayerKwargs(TypedDict, total=False):
trainable: bool
name: str | None
dtype: DTypeLike | None
dynamic: bool
class Layer(Generic[_InputT, _OutputT], tf.Module, ABC):
input_spec: ContainerInputSpec
trainable: bool
def __init__(self, **kwargs: Unpack[_LayerKwargs]) -> None: ...
@final
def __call__(self, inputs: _InputT, *, training: bool = False) -> _OutputT: ...
@overload
def build(self: Layer[tf.Tensor, object], input_shape: tf.TensorShape) -> None: ...
@overload
def build(self, input_shape: Any) -> None: ...
# Real type here in _InputShapeT and _OutputShapeT. If Higher order kinds
# existed we could derive these from the input and output types. Without them
# we would need to make this class have more generic arguments. Overloads at least
# handle one common case.
@overload
def compute_output_shape(self, input_shape: Any) -> Any: ...
@overload
def compute_output_shape(
self: Layer[tf.Tensor, tf.Tensor], input_shape: tf.TensorShape
) -> tf.TensorShape: ...
def add_weight(
self,
name: str | None = None,
shape: Iterable[int | None] | None = None,
dtype: tf.DTypeLike | None = None,
initializer: InitializerT | None = None,
regularizer: tf.keras.regularizers.Regularizer
| Callable[[tf.Tensor], tf.Tensor]
| None = None,
constraint: tf.keras.constraints.Constraint
| Callable[[tf.Tensor], tf.Tensor]
| None = None,
trainable: bool | None = None,
) -> tf.Variable: ...
def add_loss(
self, losses: tf.Tensor | Sequence[tf.Tensor] | Callable[[], tf.Tensor]
) -> None: ...
def call(
self,
inputs: _InputT,
/,
) -> _OutputT: ...
def count_params(self) -> int: ...
@property
def trainable_variables(self) -> list[Variable]: ...
@property
def non_trainable_variables(self) -> list[Variable]: ...
@property
def trainable_weights(self) -> list[Variable]: ...
@property
def non_trainable_weights(self) -> list[Variable]: ...
@property
def losses(self) -> list[Tensor]: ...
built: bool
def get_weights(self) -> list[float_array]: ...
def set_weights(self, weights: Sequence[float_array]) -> None: ...
def get_config(self) -> dict[str, Any]: ...
@classmethod
def from_config(cls: type[Self], config: dict[str, Any]) -> Self: ...
@property
def distribute_strategy(self) -> Strategy: ...
@property
def dtype(self) -> tf.DType: ...
@property
def variable_dtype(self) -> tf.DType: ...
@property
def compute_dtype(self) -> tf.DType: ...
class Dense(Layer[tf.Tensor, tf.Tensor]):
input_spec: InputSpec
def __init__(
self,
units: int,
activation: ActivationT = None,
use_bias: bool = True,
kernel_initializer: InitializerT = "glorot_uniform",
bias_initializer: InitializerT = "zeros",
kernel_regularizer: RegularizerT = None,
bias_regularizer: RegularizerT = None,
activity_regularizer: RegularizerT = None,
kernel_constraint: ConstraintT = None,
bias_constraint: ConstraintT = None,
**kwargs: Unpack[_LayerKwargs],
) -> None: ...
def compute_output_shape(self, input_shape: tf.TensorShape) -> tf.TensorShape: ...
def call(self, inputs: tf.Tensor) -> tf.Tensor: ...
class BatchNormalization(Layer[tf.Tensor, tf.Tensor]):
def __init__(
self,
axis: int | list[int] | tuple[int, ...] = -1,
momentum: float = 0.99,
epsilon: float = 0.001,
center: bool = True,
scale: bool = True,
beta_initializer: InitializerT = "zeros",
gamma_initializer: InitializerT = "ones",
moving_mean_initializer: InitializerT = "zeros",
moving_variance_initializer: InitializerT = "ones",
beta_regularizer: RegularizerT = None,
gamma_regularizer: RegularizerT = None,
beta_constraint: ConstraintT = None,
gamma_constraint: ConstraintT = None,
renorm: bool = False,
**kwargs: Unpack[_LayerKwargs],
): ...
def compute_output_shape(self, input_shape: tf.TensorShape) -> tf.TensorShape: ...
def call(self, inputs: tf.Tensor) -> tf.Tensor: ...
class ReLU(Layer[tf.Tensor, tf.Tensor]):
def __init__(
self,
max_value: float | None = None,
negative_slope: float | None = 0.0,
threshold: float | None = 0.0,
**kwargs: Unpack[_LayerKwargs],
) -> None: ...
def compute_output_shape(self, input_shape: tf.TensorShape) -> tf.TensorShape: ...
def call(self, inputs: tf.Tensor) -> tf.Tensor: ...
class Dropout(Layer[tf.Tensor, tf.Tensor]):
def __init__(
self,
rate: float,
noise_shape: TensorCompatible | Sequence[int | None] | None = None,
seed: int | None = None,
**kwargs: Unpack[_LayerKwargs],
) -> None: ...
def compute_output_shape(self, input_shape: tf.TensorShape) -> tf.TensorShape: ...
def call(self, inputs: tf.Tensor) -> tf.Tensor: ...
class Embedding(Layer[TensorLike, tf.Tensor]):
def __init__(
self,
input_dim: int,
output_dim: int,
embeddings_initializer: InitializerT = "uniform",
embeddings_regularizer: RegularizerT = None,
embeddings_constraint: ConstraintT = None,
mask_zero: bool = False,
input_length: int | None = None,
**kwargs: Unpack[_LayerKwargs],
): ...
def compute_output_shape(self, input_shape: tf.TensorShape) -> tf.TensorShape: ...
def call(self, inputs: TensorLike) -> tf.Tensor: ...
class LayerNormalization(Layer[tf.Tensor, tf.Tensor]):
def __init__(
self,
axis: int = -1,
epsilon: float = 0.001,
center: bool = True,
scale: bool = True,
beta_initializer: InitializerT = "zeros",
gamma_initializer: InitializerT = "ones",
beta_regularizer: RegularizerT = None,
gamma_regularizer: RegularizerT = None,
beta_constraint: ConstraintT = None,
gamma_constraint: ConstraintT = None,
**kwargs: Unpack[_LayerKwargs],
) -> None: ...
class _IndexLookup(Layer[TensorLike, TensorLike]):
@overload
def __call__(self, inputs: tf.Tensor) -> tf.Tensor: ...
@overload
def __call__(self, inputs: tf.SparseTensor) -> tf.SparseTensor: ...
@overload
def __call__(self, inputs: tf.RaggedTensor) -> tf.RaggedTensor: ...
def vocabulary_size(self) -> int: ...
class StringLookup(_IndexLookup):
def __init__(
self,
max_tokens: int | None = None,
num_oov_indices: int = 1,
mask_token: str | None = None,
oov_token: str = "[UNK]",
vocabulary: str | None | TensorCompatible = None,
idf_weights: TensorCompatible | None = None,
encoding: str = "utf-8",
invert: bool = False,
output_mode: Literal["int", "count", "multi_hot", "one_hot", "tf_idf"] = "int",
sparse: bool = False,
pad_to_max_tokens: bool = False,
) -> None: ...
class IntegerLookup(_IndexLookup):
def __init__(
self,
max_tokens: int | None = None,
num_oov_indices: int = 1,
mask_token: int | None = None,
oov_token: int = -1,
vocabulary: str | None | TensorCompatible = None,
vocabulary_dtype: Literal["int64", "int32"] = "int64",
idf_weights: TensorCompatible | None = None,
invert: bool = False,
output_mode: Literal["int", "count", "multi_hot", "one_hot", "tf_idf"] = "int",
sparse: bool = False,
pad_to_max_tokens: bool = False,
) -> None: ...
class DenseFeatures(Layer[Mapping[str, TensorLike], tf.Tensor]):
def __init__(
self,
feature_columns: Sequence[DenseColumn | SequenceDenseColumn],
**kwargs: Unpack[_LayerKwargs],
) -> None: ...
class MultiHeadAttention(Layer[Any, tf.Tensor]):
def __init__(
self,
num_heads: int,
key_dim: int | None,
value_dim: int | None = None,
dropout: float = 0.0,
use_bias: bool = True,
output_shape: tuple[int, ...] | None = None,
attention_axes: tuple[int, ...] | None = None,
kernel_initialize: InitializerT = "glorot_uniform",
bias_initializer: InitializerT = "zeros",
kernel_regularizer: RegularizerT = None,
bias_regularizer: RegularizerT = None,
activity_regularizer: RegularizerT = None,
kernel_constraint: ConstraintT = None,
bias_constraint: ConstraintT = None,
**kwargs: Unpack[_LayerKwargs],
) -> None: ...
@overload
def __call__(
self,
query: tf.Tensor,
value: tf.Tensor,
key: tf.Tensor | None = None,
attention_mask: tf.Tensor | None = None,
return_attention_scores: Literal[False] = False,
training: bool = False,
use_causal_mask: bool = False,
) -> tf.Tensor: ...
@overload
def __call__(
self,
query: tf.Tensor,
value: tf.Tensor,
key: tf.Tensor | None = None,
attention_mask: tf.Tensor | None = None,
return_attention_scores: Literal[True] = True,
training: bool = False,
use_causal_mask: bool = False,
) -> tuple[tf.Tensor, tf.Tensor]: ...
class GaussianDropout(Layer[tf.Tensor, tf.Tensor]):
def __init__(
self, rate: float, seed: int | None = None, **kwargs: Unpack[_LayerKwargs]
) -> None: ...
def __getattr__(name: str) -> Any: ...