VOOZH about

URL: https://www.geeksforgeeks.org/machine-learning/what-is-tanhlayer-in-pybrain/

⇱ What is TanhLayer in PyBrain - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

What is TanhLayer in PyBrain

Last Updated : 15 Apr, 2026

The TanhLayer in PyBrain is a hidden layer that applies the Hyperbolic tangent (tanh) activation function. It transforms input values into a range between -1 and 1, helping neural networks learn complex patterns.

Syntax:

Import TanhLayer: from pybrain.structure import TanhLayer

Use in python code: net = buildNetwork(2, 3, 1, bias=True, hiddenclass=TanhLayer)

Example 1

In this example, we import the TanhLayer using the import command to create the network using buildNetwork() with input, hidden, and output layer. We take a hidden class as TanhLayer, Now give the sizes of input and output dataset using SupervisedDataSet(). To add sample dataset to AND table and NOR table. Then train this network using BackpropTrainer(). We have 2500 iterations and then testing starts and we can see the errors, corrections, max, errors, etc.In this case, the sample data we have taken in AND table are ((0,0), (0,)) and ((0,1),(1,)) and NOR table are ((0,0),(0,)) and (0,1),(1,))

Output:

👁 Image

Example 2

Under this example, the sample data we have taken in AND table are ((0,0), (1,)) and ((0,1),(1,)) and NOR table are ((0,0),(0,)) and (0,1),(0,)) and we can see the testing output with average errors, max errors, median errors, etc.

Output:

👁 Image
Comment