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 chatbot model

We can pass the vectorized training data (using the method we defined in the previous section) to our chatbot and call the memory network's fit method to train over mini-batches of the training data while evaluating our model's performance on the validation set at fixed intervals:

    def predict_for_batch(self, facts, questions):        preds = []        # Iterate over mini-batches        for start in range(0, len(facts), self.batch_size):            end = start + self.batch_size            facts_batch = facts[start:end]            questions_batch = questions[start:end]            # Predict per batch            pred = self.model.predict(facts_batch, questions_batch)            preds += list(pred)        return preds     def train(self):        # Vectorize training and validation data train_facts, train_questions, train_answers ...

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