<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNSGraph/Builder/Tensor/bidirectionalLSTM(initialHiddenStates:initialCellStates:inputHiddenWeight:hiddenHiddenWeight:bias:inputHiddenWeightBack:hiddenHiddenWeightBack:biasBack:activation:recurrentActivation:cellActivation:outputSequence:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate9BNNSGraphO7BuilderV6TensorV17bidirectionalLSTM19initialHiddenStates0g4CellI005inputH6Weight06hiddenhL04bias0khL4Back0mhlO00nO010activation19recurrentActivation04cellR014outputSequenceAGy__xG0T0_AU0mI0AU06memoryI0tAU_A7uE0R0OA2ZSbtF"
  },
  "title" : "bidirectionalLSTM(initialHiddenStates:initialCellStates:inputHiddenWeight:hiddenHiddenWeight:bias:inputHiddenWeightBack:hiddenHiddenWeightBack:biasBack:activation:recurrentActivation:cellActivation:outputSequence:)"
}
-->

# bidirectionalLSTM(initialHiddenStates:initialCellStates:inputHiddenWeight:hiddenHiddenWeight:bias:inputHiddenWeightBack:hiddenHiddenWeightBack:biasBack:activation:recurrentActivation:cellActivation:outputSequence:)

Adds a bidirectional LSTM operation to the current graph.

```
func bidirectionalLSTM(initialHiddenStates: BNNSGraph.Builder.Tensor<T>, initialCellStates: BNNSGraph.Builder.Tensor<T>, inputHiddenWeight: BNNSGraph.Builder.Tensor<T>, hiddenHiddenWeight: BNNSGraph.Builder.Tensor<T>, bias: BNNSGraph.Builder.Tensor<T>, inputHiddenWeightBack: BNNSGraph.Builder.Tensor<T>, hiddenHiddenWeightBack: BNNSGraph.Builder.Tensor<T>, biasBack: BNNSGraph.Builder.Tensor<T>, activation: BNNSGraph.Builder.Activation, recurrentActivation: BNNSGraph.Builder.Activation, cellActivation: BNNSGraph.Builder.Activation, outputSequence: Bool) -> (output: BNNSGraph.Builder.Tensor<T>, hiddenStates: BNNSGraph.Builder.Tensor<T>, memoryStates: BNNSGraph.Builder.Tensor<T>)
```

## Parameters

`initialHiddenStates`

The initial hidden states with the shape `(N, 2*Hout)`.

`initialCellStates`

The initial hidden states with the shape `(N, 2*Hout)`.

`inputHiddenWeight`

The input-hidden weight with the shape `(4*Hout, Hin)`.

`bias`

The bias (the sum of input-hidden and hidden-hidden biases)  with the shape `(4*Hout,)`.

`inputHiddenWeightBack`

The backward input-hidden weight with the shape `(4*Hout, Hin)`.

`hiddenHiddenWeightBack`

The backward hidden-hidden weight with the shape `(4*Hout, Hout)`.

`biasBack`

The backward bias (the sum of input-hidden and hidden-hidden biases)  with the shape`(4*Hout,)`.

`activation`

An enumeration that controls the output activation function.

`recurrentActivation`

An enumeration that controls the recurrent activation function.

`cellActivation`

An enumeration that controls the cell activation function.

`outputSequence`

When `true`, `output` is of shape `(L, N, 2*Hout)` and contains
hidden states from every step, `h[:, ...]`. When `false`, ` output` is of shape `(1, N, 2*Hout)`
and contains hidden states from the last step, `h[-1, ...]`.

## Discussion

The input tensor `x` is of shape `(L, N, Hin)`

- Parameter hiddenHiddenWeight The hidden-hidden weight with the shape `(4*Hout, Hout)`.

`hiddenStates` is of shape `(N, 2*Hout)` and contains hidden states from the last step, `h[-1, ...]`

`memoryStates` is of shape `(N, 2*Hout)` and contains memory states from the last step, `c[-1, ...]`

> seealso:  ``doc://com.apple.accelerate/documentation/Accelerate/BNNSGraph/Builder/Tensor/lstm(initialHiddenStates:initialCellStates:inputHiddenWeight:hiddenHiddenWeight:bias:direction:activation:recurrentActivation:cellActivation:outputSequence:)``

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)