Skip to content

Commit 2cd311a

Browse files
authored
updating documentation for CRF (#2168)
* updating documentation for CRF * changing output type * fixing grammar issues * reformatted * reformatting to avoid long lines * reformat * reformat
1 parent 1ccfe50 commit 2cd311a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

tensorflow_addons/layers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@
4040
from tensorflow_addons.layers.esn import ESN
4141
from tensorflow_addons.layers.stochastic_depth import StochasticDepth
4242
from tensorflow_addons.layers.noisy_dense import NoisyDense
43+
from tensorflow_addons.layers.crf import CRF

tensorflow_addons/layers/crf.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,38 @@
2727
class CRF(tf.keras.layers.Layer):
2828
"""Linear chain conditional random field (CRF).
2929
30+
Inherits from: `tf.keras.layers.Layer`.
31+
3032
References:
3133
- [Conditional Random Field](https://en.wikipedia.org/wiki/Conditional_random_field)
34+
35+
Example:
36+
37+
>>> layer = tfa.layers.CRF(4)
38+
>>> inputs = np.random.rand(2, 4, 8).astype(np.float32)
39+
>>> decoded_sequence, potentials, sequence_length, chain_kernel = layer(inputs)
40+
>>> decoded_sequence.shape
41+
TensorShape([2, 4])
42+
>>> potentials.shape
43+
TensorShape([2, 4, 4])
44+
>>> sequence_length
45+
<tf.Tensor: shape=(2,), dtype=int64, numpy=array([4, 4])>
46+
>>> chain_kernel.shape
47+
TensorShape([4, 4])
48+
49+
Arguments:
50+
units: Positive integer, dimensionality of the reservoir.
51+
chain_initializer: Orthogonal matrix. Default to `orthogonal`.
52+
use_boundary: `Boolean`, whether the layer uses a boundary vector. Default to `True`.
53+
boundary_initializer: Tensors initialized to 0. Default to `zeros`.
54+
use_kernel: `Boolean`, whether the layer uses a kernel weights. Default to `True`.
55+
Call Arguments:
56+
inputs: Positive integer, dimensionality of the output space.
57+
mask: A boolean `Tensor` of shape `[batch_size, sequence_length]`
58+
or `None`. Default to `None`.
59+
Raises:
60+
ValueError: If input mask doesn't have dim 2 or None.
61+
NotImplementedError: If left padding is provided.
3262
"""
3363

3464
@typechecked

0 commit comments

Comments
 (0)