       }
     }
 
-    let bpc = validationLossSum / Float(validationCharacterCount) / log(2)
+    let bpc = getBpc(loss: validationLossSum, characterCount: validationCharacterCount)
     let validationLoss = validationLossSum / Float(validationBatchCount)
 
     print(

        return Tensor(loss, on: device)
      }

      trainingLossSum += loss.scalarized()
      trainingBatchCount += 1
      optimizer.update(&model, along: gradients)
      LazyTensorBarrier()
      if hasNaN(gradients) {

      break
    }
  }
}

fileprivate func getBpc(loss: Float, characterCount: Int) -> Float {
  return loss / Float(characterCount) / log(2)
}

fileprivate func hasNaN<T: KeyPathIterable>(_ t: T) -> Bool {
