O'Reilly logo

Hands-On Natural Language Processing with Python by Rajalingappaa Shanmugamani, Rajesh Arumugam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Training the model

We will train a model for matching these question pairs. Let's start by importing the relevant libraries, as follows:

import sysimport osimport pandas as pdimport numpy as npimport stringimport tensorflow as tf

Following is a function that takes a pandas series of text as input. Then, the series is converted to a list. Each item in the list is converted into a string, made lower case, and stripped of surrounding empty spaces. The entire list is converted into a NumPy array, to be passed back:

def read_x(x):    x = np.array([list(str(line).lower().strip()) for line in x.tolist()])    return x

Next up is a function that takes a pandas series as input, converts it to a list, and returns it as a NumPy array:

def read_y(y):    return ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required