ibm_watson.natural_language_classifier_v1 module

IBM Watson™ Natural Language Classifier uses machine learning algorithms to return the top matching predefined classes for short text input. You create and train a classifier to connect predefined classes to example texts so that the service can apply those classes to new inputs.

class NaturalLanguageClassifierV1(authenticator: ibm_cloud_sdk_core.authenticators.authenticator.Authenticator = None, service_name: str = 'natural_language_classifier')[source]

Bases: ibm_cloud_sdk_core.base_service.BaseService

The Natural Language Classifier V1 service.

DEFAULT_SERVICE_URL = 'https://api.us-south.natural-language-classifier.watson.cloud.ibm.com'
DEFAULT_SERVICE_NAME = 'natural_language_classifier'
classify(classifier_id: str, text: str, **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[source]

Classify a phrase.

Returns label information for the input. The status must be Available before you can use the classifier to classify text.

Parameters
  • classifier_id (str) – Classifier ID to use.

  • text (str) – The submitted phrase. The maximum length is 2048 characters.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

classify_collection(classifier_id: str, collection: List[ClassifyInput], **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[source]

Classify multiple phrases.

Returns label information for multiple phrases. The status must be Available before you can use the classifier to classify text. Note that classifying Japanese texts is a beta feature.

Parameters
  • classifier_id (str) – Classifier ID to use.

  • collection (List[ClassifyInput]) – The submitted phrases.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

create_classifier(training_metadata: BinaryIO, training_data: BinaryIO, **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[source]

Create classifier.

Sends data to create and train a classifier and returns information about the new classifier.

Parameters
  • training_metadata (TextIO) – Metadata in JSON format. The metadata identifies the language of the data, and an optional name to identify the classifier. Specify the language with the 2-letter primary language code as assigned in ISO standard 639. Supported languages are English (en), Arabic (ar), French (fr), German, (de), Italian (it), Japanese (ja), Korean (ko), Brazilian Portuguese (pt), and Spanish (es).

  • training_data (TextIO) – Training data in CSV format. Each text value must have at least one class. The data can include up to 3,000 classes and 20,000 records. For details, see [Data preparation](https://cloud.ibm.com/docs/natural-language-classifier?topic=natural-language-classifier-using-your-data).

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

list_classifiers(**kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[source]

List classifiers.

Returns an empty array if no classifiers are available.

Parameters

headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

get_classifier(classifier_id: str, **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[source]

Get information about a classifier.

Returns status and other information about a classifier.

Parameters
  • classifier_id (str) – Classifier ID to query.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

delete_classifier(classifier_id: str, **kwargs) → ibm_cloud_sdk_core.detailed_response.DetailedResponse[source]

Delete classifier.

Parameters
  • classifier_id (str) – Classifier ID to delete.

  • headers (dict) – A dict containing the request headers

Returns

A DetailedResponse containing the result, headers and HTTP status code.

Return type

DetailedResponse

class Classification(*, classifier_id: str = None, url: str = None, text: str = None, top_class: str = None, classes: List[ClassifiedClass] = None)[source]

Bases: object

Response from the classifier for a phrase.

Attr str classifier_id

(optional) Unique identifier for this classifier.

Attr str url

(optional) Link to the classifier.

Attr str text

(optional) The submitted phrase.

Attr str top_class

(optional) The class with the highest confidence.

Attr List[ClassifiedClass] classes

(optional) An array of up to ten class-confidence pairs sorted in descending order of confidence.

classmethod from_dict(_dict: Dict)ibm_watson.natural_language_classifier_v1.Classification[source]

Initialize a Classification object from a json dictionary.

to_dict() → Dict[source]

Return a json dictionary representing this model.

class ClassificationCollection(*, classifier_id: str = None, url: str = None, collection: List[CollectionItem] = None)[source]

Bases: object

Response from the classifier for multiple phrases.

Attr str classifier_id

(optional) Unique identifier for this classifier.

Attr str url

(optional) Link to the classifier.

Attr List[CollectionItem] collection

(optional) An array of classifier responses for each submitted phrase.

classmethod from_dict(_dict: Dict)ibm_watson.natural_language_classifier_v1.ClassificationCollection[source]

Initialize a ClassificationCollection object from a json dictionary.

to_dict() → Dict[source]

Return a json dictionary representing this model.

class ClassifiedClass(*, confidence: float = None, class_name: str = None)[source]

Bases: object

Class and confidence.

Attr float confidence

(optional) A decimal percentage that represents the confidence that Watson has in this class. Higher values represent higher confidences.

Attr str class_name

(optional) Class label.

classmethod from_dict(_dict: Dict)ibm_watson.natural_language_classifier_v1.ClassifiedClass[source]

Initialize a ClassifiedClass object from a json dictionary.

to_dict() → Dict[source]

Return a json dictionary representing this model.

class Classifier(url: str, classifier_id: str, *, name: str = None, status: str = None, created: datetime.datetime = None, status_description: str = None, language: str = None)[source]

Bases: object

A classifier for natural language phrases.

Attr str name

(optional) User-supplied name for the classifier.

Attr str url

Link to the classifier.

Attr str status

(optional) The state of the classifier.

Attr str classifier_id

Unique identifier for this classifier.

Attr datetime created

(optional) Date and time (UTC) the classifier was created.

Attr str status_description

(optional) Additional detail about the status.

Attr str language

(optional) The language used for the classifier.

classmethod from_dict(_dict: Dict)ibm_watson.natural_language_classifier_v1.Classifier[source]

Initialize a Classifier object from a json dictionary.

to_dict() → Dict[source]

Return a json dictionary representing this model.

class StatusEnum(value)[source]

Bases: enum.Enum

The state of the classifier.

NON_EXISTENT = 'Non Existent'
TRAINING = 'Training'
FAILED = 'Failed'
AVAILABLE = 'Available'
UNAVAILABLE = 'Unavailable'
class ClassifierList(classifiers: List[Classifier])[source]

Bases: object

List of available classifiers.

Attr List[Classifier] classifiers

The classifiers available to the user. Returns an empty array if no classifiers are available.

classmethod from_dict(_dict: Dict)ibm_watson.natural_language_classifier_v1.ClassifierList[source]

Initialize a ClassifierList object from a json dictionary.

to_dict() → Dict[source]

Return a json dictionary representing this model.

class ClassifyInput(text: str)[source]

Bases: object

Request payload to classify.

Attr str text

The submitted phrase. The maximum length is 2048 characters.

classmethod from_dict(_dict: Dict)ibm_watson.natural_language_classifier_v1.ClassifyInput[source]

Initialize a ClassifyInput object from a json dictionary.

to_dict() → Dict[source]

Return a json dictionary representing this model.

class CollectionItem(*, text: str = None, top_class: str = None, classes: List[ClassifiedClass] = None)[source]

Bases: object

Response from the classifier for a phrase in a collection.

Attr str text

(optional) The submitted phrase. The maximum length is 2048 characters.

Attr str top_class

(optional) The class with the highest confidence.

Attr List[ClassifiedClass] classes

(optional) An array of up to ten class-confidence pairs sorted in descending order of confidence.

classmethod from_dict(_dict: Dict)ibm_watson.natural_language_classifier_v1.CollectionItem[source]

Initialize a CollectionItem object from a json dictionary.

to_dict() → Dict[source]

Return a json dictionary representing this model.