Skip to content

An open source library for building end-to-end dialog systems and training chatbots.

License

Notifications You must be signed in to change notification settings

MIPTDeepLearningLab/DeepPavlov

 
 

Repository files navigation

License Apache 2.0 Python 3.6

DeepPavlov

We are in a really early Alfa release. You have to be ready to hard adventures.

An open-source conversational AI library, built on TensorFlow and Keras, and designed for

  • NLP and dialog systems research
  • implementation and evaluation of complex conversational systems

Our goal is to provide researchers with:

  • a framework for implementing and testing their own dialog models with subsequent sharing of that models
  • set of predefined NLP models / dialog system components (ML/DL/Rule-based) and pipeline templates
  • benchmarking environment for conversational models and systematized access to relevant datasets

and AI-application developers with:

  • framework for building conversational software
  • tools for application integration with adjacent infrastructure (messengers, helpdesk software etc.)
  • Licensed under the Apache License, Version 2.0.

Features

Contents

Installation

  1. Create a virtual environment with Python 3.6
  2. Activate the environment.
  3. Clone the repo
    git clone https://github.com/deepmipt/DeepPavlov.git
    
  4. cd to the project root.
  5. Install the requirements:
    python install.py
    
  6. If there were errors during installation, try to run the previous command again.

Quick start

With the purpose to interact with our pre-trained models, they should be downloaded first:

cd deeppavlov/
python download.py [-all]
  • [-all] option is not required for basic examples; it will download all our pre-trained models.

  • Warning! [-all] requires about 10 GB of free space on disk.

Then the models can be interacted or trained with the following command:

python deep.py <mode> <path_to_config>
  • <mode> can be 'train', 'interact' or 'interactbot'
  • <path_to_config> should be a path to an NLP pipeline json config

For 'interactbot' mode you should specify Telegram bot token in -t parameter or in TELEGRAM_TOKEN environment variable.

Available model configs are:

skills/go_bot/config.json

models/classifiers/intents/config_dstc2.json

models/ner/config.json

models/spellers/error_model/config_en.json

Support & collaboration

If you have any questions, bug reports or feature requests, please feel free to post on our Github Issues page. Please tag your issue with 'bug', 'feature request', or 'question'. Also we’ll be glad to see your pull-requests to add new datasets, models, embeddings and etc.

The Team

DeepPavlov is built and maintained by Neural Networks and Deep Learning Lab at MIPT within iPavlov project (part of National Technology Initiative) and in partnership with Sberbank.

License

DeepPavlov is Apache 2.0 - licensed.


DeepPavlov overview

Project modules

deeppavlov.core.commands basic training and inferring functions
deeppavlov.core.common registration and classes initialization functionality, class method decorators
deeppavlov.core.data basic Dataset, DatasetReader and Vocab classes
deeppavlov.core.models abstract model classes and interfaces
deeppavlov.dataset_readers concrete DatasetReader classes
deeppavlov.datasets concrete Dataset classes
deeppavlov.models concrete Model classes
deeppavlov.skills Skill classes. Skills are dialog models.
deeppavlov.vocabs concrete Vocab classes

Config

An NLP pipeline config is a JSON file, which consists of four required elements:

{
  "dataset_reader": {
  },
  "dataset": {
  },
  "vocabs": {
  },
  "model": {
  }
}

Each class in the config has name parameter, which is its registered codename and can have any other parameters, repeating its __init__() method arguments. Default values of __init__() arguments will be overridden with the config values during class instance initialization.

DatasetReader

DatasetReader class reads data and returns it in a specified format. A concrete DatasetReader class should be inherited from base deeppavlov.data.dataset_reader.DatasetReader class and registered with a codename:

@register('dstc2_datasetreader')
class DSTC2DatasetReader(DatasetReader):

Dataset

Dataset forms needed sets of data ('train', 'valid', 'test') and forms data batches. A concrete Dataset class should be registered and can be inherited from deeppavlov.data.dataset_reader.Dataset class. deeppavlov.data.dataset_reader.Dataset is not an abstract class and can be used as Dataset as well.

Vocab

Vocab is a trainable class, which forms and serialize vocabs. Vocabs index any data. For example, tokens to indices and backwards, chars to indices, classes to indices, etc. It can index X (features) and y (answers) types of data. A concrete Vocab class should be registered and can be inherited from deeppavlov.data.vocab.DefaultVocabulary class. deeppavlov.data.vocab.DefaultVocabulary is not an abstract class and can be used as Vocab as well.

Model

Model is the main class which rules the training/inferring process and feature generation. If a model requires other models to produce features, they need to be passed in its constructor and config. All models can be nested as much as needed. For example, a skeleton of deeppavlov.skills.go_bot.go_bot.GoalOrientedBot consists of 11 separate model classes, 3 of which are neural networks:

{
  "model": {
    "name": "go_bot",
    "network": {
      "name": "go_bot_rnn"
    },
    "slot_filler": {
      "name": "dstc_slotfilling",
      "ner_network": {
         "name": "ner_tagging_network",
      }
    },
    "intent_classifier": {
      "name": "intent_model",
      "embedder": {
        "name": "fasttext"
      },
      "tokenizer": {
        "name": "nltk_tokenizer"
      }
    },
    "embedder": {
      "name": "fasttext"
    },
    "bow_encoder": {
      "name": "bow"
    },
    "tokenizer": {
      "name": "spacy_tokenizer"
    },
    "tracker": {
      "name": "featurized_tracker"
    }
  }
}

All models should be registered and inherited from deeppavlov.core.models.inferable.Inferable or from both Inferable and deeppavlov.core.models.trainable.Trainable interfaces. Models inherited from Trainable interface can be trained. Models inherited from Inferable interface can be only inferred. Usually Inferable models are rule-based models or pre-trained models that we import from third-party libraries (like NLTK, Spacy, etc.).

Training

All models inherited from deeppavlov.core.models.trainable.Trainable interface can be trained. The training process should be described in train() method:

@register("my_model")
class MyModel(Inferable, Trainable):

   def train(*args, **kwargs):
       """
       Implement training here.
       """

All parameters for training which can be changed during experiments (like num of epochs, batch size, patience, learning rate, optimizer) should be passed to a model's __init__(). The default parameters values from __init__() are overridden with JSON config values. To change these values, there is no need to rewrite the code, only the config should be changed.

The training process is managed by train_now attribute. If train_now is True, a model is being trained. This parameter is useful when using Vocab, because in a single model run some vocabs can be trained, while some only inferred by other models in pipeline. The training parameters in JSON config can look like this:

{
  "model": {
    "name": "my_model",
    "train_now": true,
    "optimizer": "Adam",
    "learning_rate": 0.2,
    "num_epochs": 1000
  }
}

Training is triggered by deeppavlov.core.commands.train.train_model_from_config() function.

Inferring

All models inherited from deeppavlov.core.models.inferable.Inferable interface can be inferred. The infer() method should return what a model can do. For example, a tokenizer should return tokens, a NER recognizer should return recognized entities, a bot should return a replica. A particular format of returned data should be defined in infer().

Inferring is triggered by deeppavlov.core.commands.train.infer_model_from_config() function. There is no need in s separate JSON for inferring. train_now parameter is ignored during inferring.

About

An open source library for building end-to-end dialog systems and training chatbots.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Python 100.0%