7.6.2 GRU 셀 구현

    이번에는 GRU 셀을 파이토치로 구현해 보겠습니다. 데이터셋 및 대부분의 코드는 LSTM 셀과 동일합니다. 따라서 여기에서도 네트워크의 차이점 위주로 학습하면 좋습니다.

    필요한 라이브러리를 호출합니다.

    코드 7-52 라이브러리 호출

    import torch
    import torch.nn as nn
    import torchvision.transforms as transforms
    import torchvision.datasets as dataset
    from torch.autograd import Variable
    from torch.nn import Parameter
    from torch import Tensor
    import torch.nn.functional as F
    from torch.utils.data import DataLoader
    import math
    
    device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
    
    cuda = True if torch.cuda.is_available() else False
    
    Tensor = torch.cuda.FloatTensor if cuda 
    
    else torch.FloatTensor
    torch.manual_seed(125)
    if torch.cuda.is_available():
        torch.cuda.manual_seed_all(125)
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.