Back to Tensorflow

tflite_support.task.text.NLClassifier

tensorflow/lite/g3doc/api_docs/python/tflite_support/task/text/NLClassifier.md

2.21.05.9 KB
Original Source

page_type: reference description: Class that performs NL classification on text.

<link rel="stylesheet" href="/site-assets/css/style.css"> <!-- DO NOT EDIT! Automatically generated file. --> <div itemscope itemtype="http://developers.google.com/ReferenceObject"> <meta itemprop="name" content="tflite_support.task.text.NLClassifier" /> <meta itemprop="path" content="Stable" /> <meta itemprop="property" content="__init__"/> <meta itemprop="property" content="classify"/> <meta itemprop="property" content="create_from_file"/> <meta itemprop="property" content="create_from_options"/> </div>

tflite_support.task.text.NLClassifier

<!-- Insert buttons and diff --> <table class="tfo-notebook-buttons tfo-api nocontent" align="left"> <td> <a target="_blank" href="https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/text/nl_classifier.py#L39-L104">
View source on GitHub
</a> </td> </table>

Class that performs NL classification on text.

<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>tflite_support.task.text.NLClassifier( options: <a href="../../../tflite_support/task/text/NLClassifierOptions"><code>tflite_support.task.text.NLClassifierOptions</code></a>, cpp_classifier: _CppNLClassifier ) -> None </code></pre> <!-- Placeholder for "Used in" --> <!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2"><h2 class="add-link">Attributes</h2></th></tr> <tr> <td> `options`<a id="options"></a> </td> <td> </td> </tr> </table>

Methods

<h3 id="classify"><code>classify</code></h3>

<a target="_blank" class="external" href="https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/text/nl_classifier.py#L86-L100">View source</a>

<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>classify( text: str ) -> <a href="../../../tflite_support/task/processor/ClassificationResult"><code>tflite_support.task.processor.ClassificationResult</code></a> </code></pre>

Performs actual NL classification on the provided text.

<!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Args</th></tr> <tr> <td> <a href="https://www.tensorflow.org/text/api_docs/python/text"><code>text</code></a> </td> <td> the input text, used to extract the feature vectors. </td> </tr> </table> <!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Returns</th></tr> <tr class="alt"> <td colspan="2"> The classification result. </td> </tr> </table> <!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Raises</th></tr> <tr> <td> `ValueError` </td> <td> If any of the input arguments is invalid. </td> </tr><tr> <td> `RuntimeError` </td> <td> If failed to perform the classification. </td> </tr> </table> <h3 id="create_from_file"><code>create_from_file</code></h3>

<a target="_blank" class="external" href="https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/text/nl_classifier.py#L49-L65">View source</a>

<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>@classmethod</code> <code>create_from_file( file_path: str ) -> 'NLClassifier' </code></pre>

Creates the NLClassifier object from a TensorFlow Lite model.

<!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Args</th></tr> <tr> <td> `file_path` </td> <td> Path to the model. </td> </tr> </table> <!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Returns</th></tr> <tr class="alt"> <td colspan="2"> `NLClassifier` object that's created from the model file. </td> </tr> </table> <!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Raises</th></tr> <tr> <td> `ValueError` </td> <td> If failed to create `NLClassifier` object from the provided file such as invalid file. </td> </tr><tr> <td> `RuntimeError` </td> <td> If other types of error occurred. </td> </tr> </table> <h3 id="create_from_options"><code>create_from_options</code></h3>

<a target="_blank" class="external" href="https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/text/nl_classifier.py#L67-L84">View source</a>

<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link"> <code>@classmethod</code> <code>create_from_options( options: <a href="../../../tflite_support/task/text/NLClassifierOptions"><code>tflite_support.task.text.NLClassifierOptions</code></a> ) -> 'NLClassifier' </code></pre>

Creates the NLClassifier object from NL classifier options.

<!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Args</th></tr> <tr> <td> `options` </td> <td> Options for the NL classifier task. </td> </tr> </table> <!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Returns</th></tr> <tr class="alt"> <td colspan="2"> `NLClassifier` object that's created from `options`. </td> </tr> </table> <!-- Tabular view --> <table class="responsive fixed orange"> <colgroup><col width="214px"><col></colgroup> <tr><th colspan="2">Raises</th></tr> <tr> <td> `ValueError` </td> <td> If failed to create `NLClassifier` object from `NLClassifierOptions` such as missing the model or if any of the classification options is invalid. </td> </tr><tr> <td> `RuntimeError` </td> <td> If other types of error occurred. </td> </tr> </table>