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 ...