Skip to content

Commit

Permalink
Move some layers to keras.layers.preprocessing
Browse files Browse the repository at this point in the history
[pre-commit.ci] auto fixes from pre-commit.com hooks
  • Loading branch information
hoel-bagard committed Jan 28, 2024
1 parent 17f66ee commit 22c88bc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ from tensorflow._aliases import AnyArray, TensorLike
from tensorflow.keras.activations import _Activation
from tensorflow.keras.constraints import Constraint
from tensorflow.keras.initializers import _Initializer
from tensorflow.keras.layers.preprocessing import IntegerLookup as IntegerLookup, StringLookup as StringLookup
from tensorflow.keras.regularizers import Regularizer, _Regularizer
from tensorflow.python.feature_column.feature_column_v2 import DenseColumn, SequenceDenseColumn

Expand Down Expand Up @@ -244,47 +245,6 @@ class LayerNormalization(Layer[tf.Tensor, tf.Tensor]):
name: str | None = None,
) -> 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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import abc

from tensorflow._aliases import TensorLike
from tensorflow.keras.layers import Layer

class PreprocessingLayer(Layer[TensorLike, TensorLike], metaclass=abc.ABCMeta): ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from typing import Literal

from tensorflow import _TensorCompatible
from tensorflow.keras.layers.preprocessing.index_lookup import IndexLookup

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: ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from _typeshed import Incomplete

import tensorflow as tf
from tensorflow.keras.layers.experimental.preprocessing import PreprocessingLayer

class IndexLookup(PreprocessingLayer):
def compute_output_signature(self, input_spec: Incomplete) -> tf.TensorSpec: ...
def get_vocabulary(self, include_special_tokens: bool = True) -> list[Incomplete]: ...
def vocabulary_size(self) -> int: ...

0 comments on commit 22c88bc

Please sign in to comment.