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

      break
    }
  }
}

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

    Context.local.learningPhase = .training
    var trainingLossSum: Float = 0
    var trainingBatchCount = 0
    let trainingBatchCountTotal = dataset.trainingPhrases.count
    for phrase in dataset.trainingPhrases {
      let sentence = phrase.numericalizedText
      let (loss, gradients) = valueWithGradient(at: model) { model -> Tensor<Float> in
