Experiment 3.3
Experiment 3.3
Experiment 3.3
CO1: Identify and describe soft computing techniques and their roles in building intelligent
machines.
AIM:
Write a program to implement a Recurrent Neural Network (RNN).
Theory
Recurrent Neural Networks (RNNs) are a class of neural networks that are powerful for
modeling sequence data such as time series or natural language. Unlike traditional
feedforward neural networks, RNNs have connections that form directed cycles, allowing
information to persist. This characteristic makes them suitable for tasks where context and
sequential information are crucial.
Procedure:
1. Install Anaconda:
o Follow the same installation steps as provided in EXPERIMENT – 1.1.
python
Copy code
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import SimpleRNN, Dense
from tensorflow.keras.datasets import imdb
from tensorflow.keras.preprocessing import sequence
Use the IMDB dataset, which contains movie reviews for sentiment analysis.
python
Copy code
max_features = 10000 # Number of words to consider as features
max_len = 500 # Cut texts after this number of words
batch_size = 32
python
Copy code
model = Sequential()
model.add(SimpleRNN(32, input_shape=(max_len, 1)))
model.add(Dense(1, activation='sigmoid'))
python
Copy code
model.compile(optimizer='rmsprop', loss='binary_crossentropy',
metrics=['accuracy'])
python
Copy code
model.fit(x_train, y_train, epochs=10, batch_size=batch_size,
validation_split=0.2)
python
Copy code
test_loss, test_acc = model.evaluate(x_test, y_test)
print(f'Test Loss: {test_loss}, Test Accuracy: {test_acc}')
Video Tutorial
Further Reading
Rolon-Mérette, D., Ross, M., Rolon-Mérette, T., & Church, K. (2016). Introduction to
Anaconda and Python: Installation and setup. Python for research in psychology, 16(5), S5-
S11.