<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 NLP training example
In this example, we'll train an NLP model for sentiment analysis of tweets using spaCy.
First we download spaCy language libraries.
Step1:  And import the boilerplate code.
Step2:  Data prep
Download the dataset from S3.
Step3:  Clean and load data using our library.
Step4:  Train the model
We'll use a pre-trained model from spaCy and fine tune it in our new dataset.
Step5:  Update the model with the current data using our library.
Step6:  Now we save the model back into S3 to a well known location (make sure it's a location you can write to!) so that we can fetch it later.
<ASSISTANT_TASK:>
Python Code:
!python -m spacy download en_core_web_sm
Explanation: NLP training example
In this example, we'll train an NLP model for sentiment analysis of tweets using spaCy.
First we download spaCy language libraries.
End of explanation
from __future__ import unicode_literals, print_function
import boto3
import json
import numpy as np
import pandas as pd
import spacy
Explanation: And import the boilerplate code.
End of explanation
S3_BUCKET = "verta-strata"
S3_KEY = "english-tweets.csv"
FILENAME = S3_KEY
boto3.client('s3').download_file(S3_BUCKET, S3_KEY, FILENAME)
Explanation: Data prep
Download the dataset from S3.
End of explanation
import utils
data = pd.read_csv(FILENAME).sample(frac=1).reset_index(drop=True)
utils.clean_data(data)
data.head()
Explanation: Clean and load data using our library.
End of explanation
nlp = spacy.load('en_core_web_sm')
Explanation: Train the model
We'll use a pre-trained model from spaCy and fine tune it in our new dataset.
End of explanation
import training
training.train(nlp, data, n_iter=20)
Explanation: Update the model with the current data using our library.
End of explanation
filename = "/tmp/model.spacy"
with open(filename, 'wb') as f:
    f.write(nlp.to_bytes())
boto3.client('s3').upload_file(filename, S3_BUCKET, "models/01/model.spacy")
filename = "/tmp/model_metadata.json"
with open(filename, 'w') as f:
    f.write(json.dumps(nlp.meta))
boto3.client('s3').upload_file(filename, S3_BUCKET, "models/01/model_metadata.json")
Explanation: Now we save the model back into S3 to a well known location (make sure it's a location you can write to!) so that we can fetch it later.
End of explanation
<END_TASK>