# EditDistance

public final class **EditDistance** Computes the (possibly normalized) Levenshtein Edit Distance.


The inputs are variable-length sequences provided by SparseTensors
(hypothesis_indices, hypothesis_values, hypothesis_shape)
and
(truth_indices, truth_values, truth_shape).


The inputs are:

<br />

<br />

### Nested Classes

|---|---|---|---|
| class | [EditDistance.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/EditDistance.Options) || Optional attributes for `https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/EditDistance` |

### Public Methods

|---|---|
| [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<Float\> | [asOutput](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/EditDistance#asOutput())() Returns the symbolic handle of a tensor. |
| static \<T\> [EditDistance](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/EditDistance) | [create](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/EditDistance#create(org.tensorflow.op.Scope,%20org.tensorflow.Operand<java.lang.Long>,%20org.tensorflow.Operand<T>,%20org.tensorflow.Operand<java.lang.Long>,%20org.tensorflow.Operand<java.lang.Long>,%20org.tensorflow.Operand<T>,%20org.tensorflow.Operand<java.lang.Long>,%20org.tensorflow.op.core.EditDistance.Options...))([Scope](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Long\> hypothesisIndices, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<T\> hypothesisValues, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Long\> hypothesisShape, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Long\> truthIndices, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<T\> truthValues, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Long\> truthShape, [Options...](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/EditDistance.Options) options) Factory method to create a class wrapping a new EditDistance operation. |
| static [EditDistance.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/EditDistance.Options) | [normalize](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/EditDistance#normalize(java.lang.Boolean))(Boolean normalize) |
| [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<Float\> | [output](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/EditDistance#output())() A dense float tensor with rank R - 1. |

### Inherited Methods

From class [org.tensorflow.op.PrimitiveOp](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp)

|---|---|
| final boolean | [equals](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#equals(java.lang.Object))(Object obj) |
| final int | [hashCode](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#hashCode())() |
| [Operation](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operation) | [op](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#op())() Returns the underlying `https://www.tensorflow.org/api_docs/java/org/tensorflow/Operation` |
| final String | [toString](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#toString())() |

From class java.lang.Object

|---|---|
| boolean | equals(Object arg0) |
| final Class\<?\> | getClass() |
| int | hashCode() |
| final void | notify() |
| final void | notifyAll() |
| String | toString() |
| final void | wait(long arg0, int arg1) |
| final void | wait(long arg0) |
| final void | wait() |

From interface [org.tensorflow.Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)

|---|---|
| abstract [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<Float\> | [asOutput](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand#asOutput())() Returns the symbolic handle of a tensor. |

## Public Methods

#### public [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<Float\>
**asOutput**
()

Returns the symbolic handle of a tensor.

Inputs to TensorFlow operations are outputs of another TensorFlow operation. This method is
used to obtain a symbolic handle that represents the computation of the input.

<br />

#### public static [EditDistance](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/EditDistance)
**create**
([Scope](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Long\> hypothesisIndices, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<T\> hypothesisValues, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Long\> hypothesisShape, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Long\> truthIndices, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<T\> truthValues, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Long\> truthShape, [Options...](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/EditDistance.Options) options)

Factory method to create a class wrapping a new EditDistance operation.

##### Parameters

| scope | current scope |
| hypothesisIndices | The indices of the hypothesis list SparseTensor. This is an N x R int64 matrix. |
| hypothesisValues | The values of the hypothesis list SparseTensor. This is an N-length vector. |
| hypothesisShape | The shape of the hypothesis list SparseTensor. This is an R-length vector. |
| truthIndices | The indices of the truth list SparseTensor. This is an M x R int64 matrix. |
| truthValues | The values of the truth list SparseTensor. This is an M-length vector. |
| truthShape | truth indices, vector. |
| options | carries optional attributes values |
|---|---|

##### Returns

- a new instance of EditDistance

#### public static [EditDistance.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/EditDistance.Options)
**normalize**
(Boolean normalize)

<br />

##### Parameters

| normalize | boolean (if true, edit distances are normalized by length of truth). The output is: |
|---|---|

#### public [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<Float\>
**output**
()

A dense float tensor with rank R - 1.


For the example input:


// hypothesis represents a 2x1 matrix with variable-length values:
// (0,0) = \["a"\]
// (1,0) = \["b"\]
hypothesis_indices = \[\[0, 0, 0\],
\[1, 0, 0\]\]
hypothesis_values = \["a", "b"\]
hypothesis_shape = \[2, 1, 1\]


// truth represents a 2x2 matrix with variable-length values:
// (0,0) = \[\]
// (0,1) = \["a"\]
// (1,0) = \["b", "c"\]
// (1,1) = \["a"\]
truth_indices = \[\[0, 1, 0\],
\[1, 0, 0\],
\[1, 0, 1\],
\[1, 1, 0\]\]
truth_values = \["a", "b", "c", "a"\]
truth_shape = \[2, 2, 2\]
normalize = true


The output will be:


// output is a 2x2 matrix with edit distances normalized by truth lengths.
output = \[\[inf, 1.0\], // (0,0): no truth, (0,1): no hypothesis
\[0.5, 1.0\]\] // (1,0): addition, (1,1): no hypothesis

<br />

<br />

<br />

<br />

<br />