Skip to content

This project contains assets and information related to create a custom Watson NLP and Watson NLP for Embed models.

License

Notifications You must be signed in to change notification settings

thomassuedbroecker/watson-nlp-custom-model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Watson NLP custom model

This project contains assets and information related to create a custom Watson NLP for Embed models.

Related blog post Create a custom dictionary model for Watson NLP and Watson NLP for Embed customize a classification model.

Visit the list of the supported models for Watson NLP for Embed

Customize a classification model for Watson NLP for Embed

  • Step 1: Familiarize yourself with Watson Studio
  • Step 2: Clone the project to your local computer
  • Step 3: Open your Watson Studio project on IBM Cloud
  • Step 4: Select New asset
  • Step 5: Press Jupyther notebook editor
  • Step 6: Select runtime Jupyther notebook editor
  • Step 7: Upload the Jupyther notebook file watson-nlp-custom-model-for-text-classification.ipynb from your local machine and press Create
  • Step 8: Execute the steps in the Jupyter notebook

Step 1: Familiarize yourself with Watson Studio

Follow the steps of the blog post Customize a model for Watson NLP to get familiar with the Watson Studio.

Step 2: Clone the project to your local computer

git clone https://https://github.com/thomassuedbroecker/watson-nlp-custom-model.git
cd watson-nlp-custom-model

Step 3: Open your Watson Studio project on IBM Cloud

Step 4: Select New asset

Step 5: Press Jupyther notebook editor

Step 6: Select runtime Jupyther notebook editor

  • Runtime: DO + NLP Runtime 22.1 on Python 3.9 (2 CPU 8 GB RAM)

Step 7: Upload the Jupyther notebook file watson-nlp-custom-model-for-text-classification.ipynb from your local machine and press Create

Location of the file YOUR_PATH/watson-nlp-custom-model/juypter-notebook/watson-nlp-custom-model-for-text-classification.ipynb.

Step 8: Execute the steps in the Jupyter notebook

Link to the notebook: Watson NLP custom model for text classification.

Run Watson NLP for Embed with a customized model on the local computer

Note: Your need to create a customized model and save it in the docker/app/models folder. Please read the readme.

  • Step 1: Clone the repository
  • Step 2: Navigate to the docker folder
  • Step 3: Create a .env file
  • Step 4: Add an IBM Cloud access key to your local .env file
  • Step 5: Execute the bash automation
  • Step 6: Open a new terminal and insert following curl command

Step 1: Clone the repository

git clone https://https://github.com/thomassuedbroecker/watson-nlp-custom-model.git
cd watson-nlp-custom-model

Step 2: Navigate to the docker folder

cd docker

Step 3: Create a .env file

cat .env_template > .env

Step 4: Add an IBM Cloud access key to your local .env file

nano .env

Content of the file:

export IBM_ENTITLEMENT_KEY="YOUR_KEY"
export IMAGE_REGISTRY="cp.icr.io/cp/ai"
export RUNTIME_IMAGE="watson-nlp-runtime:1.0.20"
export WATSON_RUNTIME_BASE="$IMAGE_REGISTRY/$RUNTIME_IMAGE"

Step 5: Ensure you have copied your model to the folder docker/app/models.

Please read the readme.

Step 5: Execute the bash automation

The creation can take up to 10 minutes for the download of the runtime image.

sh run-watson-nlp-with-docker.sh
  • Example output:
# ******
# Connect to IBM Cloud Container Image Registry: cp.icr.io/cp/ai
# ******

IBM_ENTITLEMENT_KEY: 
...

Login Succeeded

# ******
# Build container image locally
# Runtime container image: cp.icr.io/cp/ai/watson-nlp-runtime:1.0.20
# ******
[+] Building 0.2s (7/7) FINISHED                                  
 => [internal] load build definition from 
 ...
 
# ******
# Run NLP
# ******

# Run the runtime with the models mounted

[STARTING RUNTIME]
...
"2023-01-25T20:25:07.040114"}
[STARTING GATEWAY]
2023/01/25 20:25:07 Running with INSECURE credentials
2023/01/25 20:25:07 Serving proxy calls INSECURE

Step 6: Open a new terminal and insert following curl command

curl -s -X POST "http://localhost:8080/v1/watson.runtime.nlp.v1/NlpService/ClassificationPredict" \
  -H "accept: application/json" \
  -H "grpc-metadata-mm-model-id: ensemble_model" \
  -H "content-type: application/json" \
  -d "{ \"rawDocument\": \
    { \"text\": \"The credit card doesn t work, and I look at the savings, but I need more money to spend.\" }}" | jq
  • Example output:
{
  "classes": [
    {
      "className": "Credit card or prepaid card",
      "confidence": 0.5404788
    },
    {
      "className": "Debt collection",
      "confidence": 0.22745371
    },
    {
      "className": "Credit reporting, credit repair services, or other personal consumer reports",
      "confidence": 0.22019744
    },
    {
      "className": "Checking or savings account",
      "confidence": 0.100063786
    },
    {
      "className": "Mortgage",
      "confidence": 0.043992974
    }
  ],
  "producerId": {
    "name": "Voting based Ensemble",
    "version": "0.0.1"
  }
}

About

This project contains assets and information related to create a custom Watson NLP and Watson NLP for Embed models.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published