tf.nn.learned_unigram_candidate_sampler function causes silent breakdown
@rubbberrabbit Thanks for reporting the issue.

The code produces seg fault in TF 2.7 but produces `InvalidArgumentError: {{function_node __wrapped__LearnedUnigramCandidateSampler_device_/job:localhost/replica:0/task:0/device:CPU:0}} `true_candidate` out of range [0, 19), received 250 [Op:LearnedUnigramCandidateSampler]` error in TF 2.11 and TF Nightly. 

Please find the gist [here](https://colab.research.google.com/gist/pjpratik/36d64d8528852a0e15aa7bdaa8ddc9b2/59752.ipynb).

As per the [documentation](https://www.tensorflow.org/api_docs/python/tf/random/learned_unigram_candidate_sampler?version=nightly) and the error suggests, the `true_classes` argument expects between `[0, range_max)`, which is the number of possible classes.

The error can be resolved by changing the `true_classes` argument to take values from `[0,range_max)`. 

Please find the working gist [here](https://colab.research.google.com/gist/pjpratik/e38efa01ce483ea31f91ff2a95553682/59752.ipynb) and let us know if it helps. Thank you. I find this problem still exists in the latest docker images tensorflow/tensorflow:nightly-gpu or in the enviroment using pip to install tf-nightly in my own computer(RTX3090 CUDA 11.6/8.6 Ubuntu 18.04), I am not sure it  may be a version release issue. It was confirmed on colab that this issue has been fixed with latest nightly version. tensorflow/tensorflow:nightly-gpu docker enviroment
![image](https://user-images.githubusercontent.com/38725110/220814294-aff5995e-47d7-439b-80db-fd8dc28a90bd.png)
the execution result show the code pass the check but raise Segmentation fault error after. Hi, @rubbberrabbit 

Apologize for the delay and I was able to replicate the same issue with `tensorflow/tensorflow:nightly-gpu` docker image and I was getting below error message and it's seems like expected behaviour. 

If issue still persists please let us know or Could you please confirm if this issue is resolved for you ? Please feel free to close the issue if it is resolved ? Thank you!

```
2023-02-26 12:01:25.948205: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1635] Created device /job:localhost/replica:0/task:0/device:GPU:1 with 14582 MB memory:  -> device: 1, name: Tesla V100-SXM2-16GB, pci bus id: 0000:00:05.0, compute capability: 7.0
Traceback (most recent call last):
  File "_59752_test.py", line 14, in <module>
    output = tf.nn.learned_unigram_candidate_sampler(tensor,2,10,True,19)
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/ops.py", line 7133, in raise_from_not_ok_status
    raise core._status_to_exception(e) from None  # pylint: disable=protected-access
tensorflow.python.framework.errors_impl.InvalidArgumentError: {{function_node __wrapped__LearnedUnigramCandidateSampler_device_/job:localhost/replica:0/task:0/device:CPU:0}} `true_candidate` out of range [0, 19), received 204 [Op:LearnedUnigramCandidateSampler]
``` Hi，I am not sure which image you use，my replicate the script in [image is ](https://hub.docker.com/r/tensorflow/tensorflow/tags) which pushed 17 hours ago by tensorflowpackages using command
docker pull tensorflow/tensorflow:nightly-gpu and still cause Segment fault.
 Is the bug related with some environment setting or the bug handle code did not update with the release yet？ ```
2023-03-09 07:03:10.340519: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1446] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 22322 MB memory) -> physical GPU (device: 0, name: NVIDIA GeForce RTX 3090, pci bus id: 0000:09:00.0, compute capability: 8.6)
2023-03-09 07:03:10.340743: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2023-03-09 07:03:10.340852: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1446] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 10484 MB memory) -> physical GPU (device: 1, name: NVIDIA GeForce RTX 3090, pci bus id: 0000:0a:00.0, compute capability: 8.6)
Segmentation fault (core dumped)
```
 I notice your environment is Tesla V100-SXM2-16GB with CUDA 7.0. I'm using CUDA 8.6 and an RTX3090, could this be the reason for the bug? I switch to the the latest 2.13.0, and it's seems like expected behaviour. Hi, @rubbberrabbit 

Thank you for the confirmation and if it's working as expected with latest nightly docker image then Could you please confirm if this issue is resolved for you ? Please feel free to close the issue if it is resolved ? 

If you need any further assistance please let us know ? Thank you! This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59752">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59752">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

Yes

### Source

source

### Tensorflow Version

tf2.7,tf2.11.0,tf-nightly

### Custom Code

Yes

### OS Platform and Distribution

Linux Ubuntu18.04

### Mobile device

_No response_

### Python version

3.8.10

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

11.6/8.6

### GPU model and memory

GPU

### Current Behaviour?

```shell
# code trigger bug
import tensorflow as tf
tensor= tf.random.uniform([2, 2], minval=-256, maxval=257, dtype=tf.int64)
output = tf.nn.learned_unigram_candidate_sampler(tensor,2,10,True,19)
print("Anything")
print(output)
```


### Standalone code to reproduce the issue

```shell
In tf2.7.0 the execution will directly lead to segment fault without any error information.
In tf2.11.0 and the latest nightly version, the execution will silently break down at line 4, which means that the "Anything" will not be output, and neither does the next line "print(output)".
```


### Relevant log output

```shell
Segment fault in tf2.7.0.
no output but silently shutdown in tf2.11.0 and nightly version.
```
</details>