<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Versioning Example (Part 2/3)
In part 1, we trained and logged a tweet sentiment classifier using ModelDB's versioning system.
Now we'll see how that can come in handy when we need to revisit or even revert changes we make.
This workflow requires verta&gt;=0.14.4 and spaCy&gt;=2.0.0.
Setup
As before, import libraries we'll need...
Step1:  ...and instantiate Verta's ModelDB Client.
Step2:  Prepare Data
This time, things are a little different.
Let's say someone has provided us with a new, expermental dataset that supposedly will improve our model. Unbeknownst to everyone, this dataset actually only contains one of the two classes we're interested in. This is going to hurt our performance, but we don't know it yet.
Before, we trained a model on english-tweets.csv. Now, we're going to train with positive-english-tweets.csv.
Step3:  Capture and Version Model Ingredients
As with before, we'll capture and log our model ingredients directly onto our repository's master branch.
Step4:  You may verify through the Web App that this commit updates the dataset, as well as the Notebook.
Train and Log Model
Again as before, we'll train the model and log it along with the commit to an Experiment Run.
Step5:  Revert Commit
Looking back over our workflow, we might notice that there's something suspicious about the model's precision, recall, and F-score. This model isn't performing as it should, and we don't want it to be the latest commit in master. Using the Client, we'll revert the commit.
<ASSISTANT_TASK:>
Python Code:
from __future__ import unicode_literals, print_function
import boto3
import json
import numpy as np
import pandas as pd
import spacy
Explanation: Versioning Example (Part 2/3)
In part 1, we trained and logged a tweet sentiment classifier using ModelDB's versioning system.
Now we'll see how that can come in handy when we need to revisit or even revert changes we make.
This workflow requires verta&gt;=0.14.4 and spaCy&gt;=2.0.0.
Setup
As before, import libraries we'll need...
End of explanation
from verta import Client
client = Client('http://localhost:3000/')
proj = client.set_project('Tweet Classification')
expt = client.set_experiment('SpaCy')
Explanation: ...and instantiate Verta's ModelDB Client.
End of explanation
S3_BUCKET = "verta-starter"
S3_KEY = "positive-english-tweets.csv"
FILENAME = S3_KEY
boto3.client('s3').download_file(S3_BUCKET, S3_KEY, FILENAME)
import utils
data = pd.read_csv(FILENAME).sample(frac=1).reset_index(drop=True)
utils.clean_data(data)
data.head()
Explanation: Prepare Data
This time, things are a little different.
Let's say someone has provided us with a new, expermental dataset that supposedly will improve our model. Unbeknownst to everyone, this dataset actually only contains one of the two classes we're interested in. This is going to hurt our performance, but we don't know it yet.
Before, we trained a model on english-tweets.csv. Now, we're going to train with positive-english-tweets.csv.
End of explanation
from verta.code import Notebook
from verta.configuration import Hyperparameters
from verta.dataset import S3
from verta.environment import Python
code_ver = Notebook()  # Notebook & git environment
config_ver = Hyperparameters({'n_iter': 20})
dataset_ver = S3("s3://{}/{}".format(S3_BUCKET, S3_KEY))
env_ver = Python(Python.read_pip_environment())  # pip environment and Python version
repo = client.set_repository('Tweet Classification')
commit = repo.get_commit(branch='master')
commit.update("notebooks/tweet-analysis", code_ver)
commit.update("config/hyperparams", config_ver)
commit.update("data/tweets", dataset_ver)
commit.update("env/python", env_ver)
commit.save("Update tweet dataset")
commit
Explanation: Capture and Version Model Ingredients
As with before, we'll capture and log our model ingredients directly onto our repository's master branch.
End of explanation
nlp = spacy.load('en_core_web_sm')
import training
training.train(nlp, data, n_iter=20)
run = client.set_experiment_run()
run.log_model(nlp)
run.log_commit(
    commit,
    {
        'notebook': "notebooks/tweet-analysis",
        'hyperparameters': "config/hyperparams",
        'training_data': "data/tweets",
        'python_env': "env/python",
    },
)
Explanation: You may verify through the Web App that this commit updates the dataset, as well as the Notebook.
Train and Log Model
Again as before, we'll train the model and log it along with the commit to an Experiment Run.
End of explanation
commit
commit.revert()
commit
Explanation: Revert Commit
Looking back over our workflow, we might notice that there's something suspicious about the model's precision, recall, and F-score. This model isn't performing as it should, and we don't want it to be the latest commit in master. Using the Client, we'll revert the commit.
End of explanation
<END_TASK>