Evaluation dataset. Must be a TextClassifier Dataset.
batch_size
Number of samples per evaluation step.
desired_precisions
If specified, adds a RecallAtPrecision metric per
desired_precisions[i] entry which tracks the recall given the constraint
on precision. Only supported for binary classification.
desired_recalls
If specified, adds a PrecisionAtRecall metric per
desired_recalls[i] entry which tracks the precision given the constraint
on recall. Only supported for binary classification.
Returns
The loss value and accuracy.
Raises
ValueError if data is not a TextClassifier Dataset.
Converts and saves the model to a TFLite file with metadata included.
Note that only the TFLite file is needed for deployment. This function also
saves a metadata.json file to the same directory as the TFLite file which
can be used to interpret the metadata content in the TFLite file.
Args
model_name
File name to save TFLite model with metadata. The full export
path is {self._hparams.export_dir}/{model_name}.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-05-07 UTC."],[],[],null,["# mediapipe_model_maker.text_classifier.TextClassifier\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/google/mediapipe/blob/master/mediapipe/model_maker/python/text/text_classifier/text_classifier.py#L76-L249) |\n\nAPI for creating and training a text classification model. \n\n mediapipe_model_maker.text_classifier.TextClassifier(\n model_spec: Any, label_names: Sequence[str], shuffle: bool\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|-----------------------------------------|\n| `model_spec` | Specification for the model. |\n| `label_names` | A list of label names for the classes. |\n| `shuffle` | Whether the dataset should be shuffled. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `create`\n\n[View source](https://github.com/google/mediapipe/blob/master/mediapipe/model_maker/python/text/text_classifier/text_classifier.py#L88-L135) \n\n @classmethod\n create(\n train_data: ../../mediapipe_model_maker/text_classifier/Dataset,\n validation_data: ../../mediapipe_model_maker/text_classifier/Dataset,\n options: ../../mediapipe_model_maker/text_classifier/TextClassifierOptions\n ) -\u003e 'TextClassifier'\n\nFactory function that creates and trains a text classifier.\n\nNote that `train_data` and `validation_data` are expected to share the same\n`label_names` since they should be split from the same dataset.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-------------------|--------------------------------------------------------|\n| `train_data` | Training data. |\n| `validation_data` | Validation data. |\n| `options` | Options for creating and training the text classifier. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A text classifier. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|---|---|\n| ValueError if `train_data` and `validation_data` do not have the same label_names or `options` contains an unknown `supported_model` ||\n\n\u003cbr /\u003e\n\n### `evaluate`\n\n[View source](https://github.com/google/mediapipe/blob/master/mediapipe/model_maker/python/text/text_classifier/text_classifier.py#L153-L188) \n\n evaluate(\n data: ../../mediapipe_model_maker/model_util/dataset/Dataset,\n batch_size: int = 32,\n desired_precisions: Optional[Sequence[float]] = None,\n desired_recalls: Optional[Sequence[float]] = None\n ) -\u003e Any\n\nOverrides Classifier.evaluate().\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `data` | Evaluation dataset. Must be a TextClassifier Dataset. |\n| `batch_size` | Number of samples per evaluation step. |\n| `desired_precisions` | If specified, adds a RecallAtPrecision metric per desired_precisions\\[i\\] entry which tracks the recall given the constraint on precision. Only supported for binary classification. |\n| `desired_recalls` | If specified, adds a PrecisionAtRecall metric per desired_recalls\\[i\\] entry which tracks the precision given the constraint on recall. Only supported for binary classification. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The loss value and accuracy. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|---|---|\n| ValueError if `data` is not a TextClassifier Dataset. ||\n\n\u003cbr /\u003e\n\n### `export_labels`\n\n[View source](https://github.com/google/mediapipe/blob/master/mediapipe/model_maker/python/core/tasks/classifier.py#L143-L157) \n\n export_labels(\n export_dir: str, label_filename: str = 'labels.txt'\n )\n\nExports classification labels into a label file.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|------------------|----------------------------------------------------------------------------------------|\n| `export_dir` | The directory to save exported files. |\n| `label_filename` | File name to save labels model. The full export path is {export_dir}/{label_filename}. |\n\n\u003cbr /\u003e\n\n### `export_model`\n\n[View source](https://github.com/google/mediapipe/blob/master/mediapipe/model_maker/python/text/text_classifier/text_classifier.py#L209-L241) \n\n export_model(\n model_name: str = 'model.tflite',\n quantization_config: Optional[../../mediapipe_model_maker/quantization/QuantizationConfig] = None\n )\n\nConverts and saves the model to a TFLite file with metadata included.\n\nNote that only the TFLite file is needed for deployment. This function also\nsaves a metadata.json file to the same directory as the TFLite file which\ncan be used to interpret the metadata content in the TFLite file.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-----------------------|----------------------------------------------------------------------------------------------------------------|\n| `model_name` | File name to save TFLite model with metadata. The full export path is {self._hparams.export_dir}/{model_name}. |\n| `quantization_config` | The configuration for model quantization. |\n\n\u003cbr /\u003e\n\n### `export_tflite`\n\n[View source](https://github.com/google/mediapipe/blob/master/mediapipe/model_maker/python/core/tasks/custom_model.py#L56-L84) \n\n export_tflite(\n export_dir: str,\n tflite_filename: str = 'model.tflite',\n quantization_config: Optional[../../mediapipe_model_maker/quantization/QuantizationConfig] = None,\n preprocess: Optional[Callable[..., bool]] = None\n )\n\nConverts the model to requested formats.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|\n| `export_dir` | The directory to save exported files. |\n| `tflite_filename` | File name to save TFLite model. The full export path is {export_dir}/{tflite_filename}. |\n| `quantization_config` | The configuration for model quantization. |\n| `preprocess` | A callable to preprocess the representative dataset for quantization. The callable takes three arguments in order: feature, label, and is_training. |\n\n\u003cbr /\u003e\n\n### `load_bert_classifier`\n\n[View source](https://github.com/google/mediapipe/blob/master/mediapipe/model_maker/python/text/text_classifier/text_classifier.py#L137-L151) \n\n @classmethod\n load_bert_classifier(\n options: ../../mediapipe_model_maker/text_classifier/TextClassifierOptions,\n saved_model_path: str,\n label_names: Sequence[str]\n ) -\u003e 'TextClassifier'\n\n### `save_model`\n\n[View source](https://github.com/google/mediapipe/blob/master/mediapipe/model_maker/python/text/text_classifier/text_classifier.py#L190-L207) \n\n save_model(\n model_name: str = 'saved_model'\n )\n\nSaves the model in SavedModel format.\n\nFor more information, see \u003chttps://www.tensorflow.org/guide/saved_model\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------------|--------------------------|\n| `model_name` | Name of the saved model. |\n\n\u003cbr /\u003e\n\n### `summary`\n\n[View source](https://github.com/google/mediapipe/blob/master/mediapipe/model_maker/python/core/tasks/custom_model.py#L51-L53) \n\n summary()\n\nPrints a summary of the model."]]