<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/models/blob/v2.20.0/official/nlp/modeling/ops/segment_extractor.py#L75-L161) |

Extract segments and labels for sentence order prediction (SOP) task.

    tfm.nlp.ops.get_sentence_order_labels(
        sentences,
        random_threshold=0.5,
        random_next_threshold=0.5,
        random_fn=tf.random.uniform
    )

Extracts the segment and labels for the sentence order prediction task
defined in "ALBERT: A Lite BERT for Self-Supervised Learning of Language
Representations" (<https://arxiv.org/pdf/1909.11942.pdf>)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `sentences` | a `RaggedTensor` of shape \[batch, (num_sentences)\] with string dtype. |
| `random_threshold` | (optional) A float threshold between 0 and 1, used to determine whether to extract a random, out-of-batch sentence or a succeeding sentence. Higher value favors succeeding sentence. |
| `random_next_threshold` | (optional) A float threshold between 0 and 1, used to determine whether to extract either a random, out-of-batch, or succeeding sentence or a preceding sentence. Higher value favors preceding sentences. |
| `random_fn` | (optional) An op used to generate random float values. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| a tuple of (preceding_or_random_next, is_succeeding_or_random) where: preceding_or_random_next: a `RaggedTensor` of strings with the same shape as `sentences` and contains either a preceding, succeeding, or random out-of-batch sentence respective to its counterpart in `sentences` and dependent on its label in `is_preceding_or_random_next`. is_succeeding_or_random: a `RaggedTensor` of bool values with the same shape as `sentences` and is True if it's corresponding sentence in `preceding_or_random_next` is a random or succeeding sentence, False otherwise. ||

<br />