New Torch Models

Hello! I have read that Deeppavlov is choosing pyTorch for new models rather than TensorFlow.

I have Ubuntu 20.04 with Python 3.8. So previous version pf Deeppavlov 0.15 couldn’t work since I couldn’t install TensorFlow 1.15.

Now with the release of Deeppavlov 0.16 and new torch models I have managed to test ner_ontonotes_bert_mult_torch and it is working great. Thank you very much for your work.

If there a sentiment classifier model now I could use with my setup?

1 Like

@vzhilov Thank you very much for your interest!

Currently there is no updated pre-trained version of the sentiment classifier. However, you can pre-train one strictly following the updated version of the insult classifier.

Thank you very much, @Vasily!

So I have changed the rusentiment_convers_bert.json to:

{
  "dataset_reader": {
    "class_name": "basic_classification_reader",
    "x": "text",
    "y": "label",
    "data_path": "{DOWNLOADS_PATH}/rusentiment/",
    "train": "rusentiment_random_posts.csv",
    "test": "rusentiment_test.csv"
  },
  "dataset_iterator": {
    "class_name": "basic_classification_iterator",
    "seed": 42,
    "split_seed": 23,
    "field_to_split": "train",
    "split_fields": [
      "train",
      "valid"
    ],
    "split_proportions": [
      0.9,
      0.1
    ]
  },
  "chainer": {
    "in": [
      "x"
    ],
    "in_y": [
      "y"
    ],
    "pipe": [
      {
        "class_name": "torch_transformers_preprocessor",
        "vocab_file": "{TRANSFORMER}", 
        "do_lower_case": true,
        "max_seq_length": 64,
        "in": [
          "x"
        ],
        "out": [
          "bert_features"
        ]
      },
      {
        "id": "classes_vocab",
        "class_name": "simple_vocab",
        "fit_on": [
          "y"
        ],
        "save_path": "{MODEL_PATH}/classes.dict",
        "load_path": "{MODEL_PATH}/classes.dict",
        "in":  [
			"y"
		],
        "out": [
			"y_ids"
		]
      },
      {
        "in": [
			"y_ids"
		],
        "out": [
			"y_onehot"
		],
        "class_name": "one_hotter",
        "depth": "#classes_vocab.len",
        "single_vector": true
      },
      {
        "class_name": "torch_transformers_classifier",
        "n_classes": "#classes_vocab.len",
        "return_probas": true,
        "pretrained_bert": "{TRANSFORMER}",
        "save_path": "{MODEL_PATH}/model",
        "load_path": "{MODEL_PATH}/model",
        "optimizer": "AdamW",
        "optimizer_parameters": {
          "lr": 1e-05
        },
        "learning_rate_drop_patience": 5,
        "learning_rate_drop_div": 2.0,
        "in": [
          "bert_features"
        ],
        "in_y": [
          "y_ids"
        ],
        "out": [
          "y_pred_probas"
        ]
      },
      {
        "in": [
			"y_pred_probas"
		],
        "out": [
			"y_pred_ids"
		],
        "class_name": "proba2labels",
        "max_proba": true
      },
      {
        "in": [
			"y_pred_ids"
		],
        "out": [
			"y_pred_labels"
		],
        "ref": "classes_vocab"
      }
    ],
    "out": [
      "y_pred_labels"
    ]
  },
  "train": {
    "batch_size": 64,
    "epochs": 100,
    "metrics": [
      "f1_weighted",
      "f1_macro",
      "accuracy",
      {
        "name": "roc_auc",
        "inputs": [
          "y_onehot",
          "y_pred_probas"
        ]
      }
    ],
    "show_examples": false,
    "pytest_max_batches": 2,
    "validation_patience": 5,
    "val_every_n_epochs": 1,
    "log_every_n_epochs": 1,
    "evaluation_targets": [
      "train",
      "valid",
      "test"
    ]
  },
  "metadata": {
    "variables": {
      "TRANSFORMER": "bert-base-uncased",
	  "ROOT_PATH": "~/.deeppavlov",
      "DOWNLOADS_PATH": "{ROOT_PATH}/downloads",
      "MODELS_PATH": "{ROOT_PATH}/models",
      "MODEL_PATH": "{MODELS_PATH}/classifiers/rusentiment_convers_bert/"
    },
    "download": [
      {
        "url": "http://files.deeppavlov.ai/deeppavlov_data/bert/ru_conversational_cased_L-12_H-768_A-12.tar.gz",
        "subdir": "{DOWNLOADS_PATH}/bert_models"
      },
      {
        "url": "http://files.deeppavlov.ai/deeppavlov_data/classifiers/rusentiment_convers_bert_v0.tar.gz",
        "subdir": "{MODELS_PATH}/classifiers/"
      }
    ]
  }
}

So I do:

from deeppavlov import configs, build_model, train_model
sent_model = train_model(configs.classifiers.rusentiment_convers_bert , download=True)

… it has started the training now, thank you!