TensorFlow implementation