import torch


def mean_squared_error(true, pred):
    return torch.mean((true - pred)**2)


def binary_crossentropy(true, pred, eps=1e-9):
    p1 = true * torch.log(pred + eps)
    p2 = (1 - true) * torch.log(1 - pred + eps)
    return torch.mean(-(p1 + p2))


def categorical_crossentropy(true, pred, eps=1e-9):
    return torch.mean(-torch.sum(true * torch.log(pred + eps), dim=1))


# aliases short names
mse = mean_squared_error


def get(obj):
    if callable(obj):
        return obj
    elif type(obj) is str:
        if obj in globals():
            return globals()[obj]
        else:
            raise Exception(f'Unknown objective: {obj}')
    else:
        raise Exception('Objective must be a callable or str')

import torch


def mean_squared_error(true, pred):
    return ((true - pred)**2).mean()


def binary_crossentropy(true, pred, eps=1e-9):
    p1 = true * torch.log(pred + eps)
    p2 = (1 - true) * torch.log(1 - pred + eps)
    return torch.mean(-(p1 + p2))


def categorical_crossentropy(true, pred, eps=1e-9):
    return torch.mean(-torch.sum(true * torch.log(pred + eps), dim=1))


# aliases short names
mse = mean_squared_error


def get(obj):
    if callable(obj):
        return obj
    elif type(obj) is str:
        if obj in globals():
            return globals()[obj]
        else:
            raise Exception(f'Unknown loss: {obj}')
    else:
        raise Exception('Loss must be a callable or str')

Change error message to loss
Change error message to loss

  import torch
  
  
  def mean_squared_error(true, pred):
-     return torch.mean((true - pred)**2)
+     return ((true - pred)**2).mean()
  
  
  def binary_crossentropy(true, pred, eps=1e-9):
      p1 = true * torch.log(pred + eps)
      p2 = (1 - true) * torch.log(1 - pred + eps)
      return torch.mean(-(p1 + p2))
  
  
  def categorical_crossentropy(true, pred, eps=1e-9):
      return torch.mean(-torch.sum(true * torch.log(pred + eps), dim=1))
  
  
  # aliases short names
  mse = mean_squared_error
  
  
  def get(obj):
      if callable(obj):
          return obj
      elif type(obj) is str:
          if obj in globals():
              return globals()[obj]
          else:
-             raise Exception(f'Unknown objective: {obj}')
+             raise Exception(f'Unknown loss: {obj}')
      else:
-         raise Exception('Objective must be a callable or str')
+         raise Exception('Loss must be a callable or str')
  
Change error message to loss
## Code Before:
import torch


def mean_squared_error(true, pred):
    return torch.mean((true - pred)**2)


def binary_crossentropy(true, pred, eps=1e-9):
    p1 = true * torch.log(pred + eps)
    p2 = (1 - true) * torch.log(1 - pred + eps)
    return torch.mean(-(p1 + p2))


def categorical_crossentropy(true, pred, eps=1e-9):
    return torch.mean(-torch.sum(true * torch.log(pred + eps), dim=1))


# aliases short names
mse = mean_squared_error


def get(obj):
    if callable(obj):
        return obj
    elif type(obj) is str:
        if obj in globals():
            return globals()[obj]
        else:
            raise Exception(f'Unknown objective: {obj}')
    else:
        raise Exception('Objective must be a callable or str')

## Instruction:
Change error message to loss
## Code After:
import torch


def mean_squared_error(true, pred):
    return ((true - pred)**2).mean()


def binary_crossentropy(true, pred, eps=1e-9):
    p1 = true * torch.log(pred + eps)
    p2 = (1 - true) * torch.log(1 - pred + eps)
    return torch.mean(-(p1 + p2))


def categorical_crossentropy(true, pred, eps=1e-9):
    return torch.mean(-torch.sum(true * torch.log(pred + eps), dim=1))


# aliases short names
mse = mean_squared_error


def get(obj):
    if callable(obj):
        return obj
    elif type(obj) is str:
        if obj in globals():
            return globals()[obj]
        else:
            raise Exception(f'Unknown loss: {obj}')
    else:
        raise Exception('Loss must be a callable or str')
