Run an already trained model instance
git clone https://github.com/IBM/MAX-Text-Sentiment-Classifier.git
cd MAX-Text-Sentiment-Classifier
docker build -t max-text-sentiment-classifier .
docker run -it -p 5000:5000 max-text-sentiment-classifierIt will create a build in a docker container. We can check the application on port 5000.
http://localhost:5000
Open it by a domain / subdomain or it can be accessed by http://ip:5000
It will open a web interface. Since its model is already trained and it gives you output as positive and negative.
We need to pass the sentence and it will tell you, either the sentence is positive or negative. Once docker container is running, we can send the request using curl and collect the output in response.
curl -d "{ \"text\": [ \"The Model Asset Exchange is a crucial element of a developer's toolkit.\" ]}" -X POST "http://localhost:5000/model/predict" -H "Content-Type: application/json"
Response :
{
"status": "ok",
"predictions": [
[
{
"positive": 0.9977352619171143,
"negative": 0.0022646968718618155
}
]
]
}
To Train the Model :
We are already in the folder MAX-Text-Sentiment-Classifier, cd into training folder. Create a virtual env.
cd training/
pip install -r requirements.txt
python setup_max_model_training.py max-text-classifier-training-config.yaml
Now this command will need account set up in IBM Cloud. How much the output is accurate, it depends on the training tsv file.
https://cloud.ibm.com/login
Go On Manage > Access > API Keys > generate a key
Download the file apikey.json, copy on the server and Provide your key path.
Now run the docker instance, it will be launched based on this training.pip install -r requirements.txt
python setup_max_model_training.py max-text-classifier-training-config.yaml
docker build -t max-text-sentiment-classifier --build-arg use_pre_trained_model=false .
docker run -it -p 5000:5000 max-text-sentiment-classifierOpen url
http://ip:5000Now it will give us the response with neutral output too as it has been trained based on the given tsv input.
To reset everything on cloud, delete Created service and Created storage in the cloud IBM account.
Remove all keys Entries from /etc/environment, exit or close the terminal, open and login again and run
python setup_max_model_training.py max-text-classifier-training-config.yamlNote :
https://github.com/IBM/MAX-Text-Sentiment-Classifier