코드 10-26 데이터 준비

    SOS_token = 0
    EOS_token = 1
    MAX_LENGTH = 20
    
    class Lang: ------ 딕셔너리를 만들기 위한 클래스
        def __init__(self): ------ 단어의 인덱스를 저장하기 위한 컨테이너를 초기화
            self.word2index = {}
            self.word2count = {}
            self.index2word = {0: "SOS", 1: "EOS"} ------ SOS(Start Of Sequence): 문장의 시작, EOS(End Of Sequence): 문장의 끝
            self.n_words = 2 ------ SOS와 EOS에 대한 카운트
    
        def addSentence(self, sentence): ------ 문장을 단어 단위로 분리한 후 컨테이너(word)에 추가
            for word in sentence.split(' '):
                self.addWord(word)
    
        def addWord(self, word): ------ 컨테이너에 단어가 없다면 추가되고, 있다면 카운트를 업데이트
            if word not in self.word2index:
                self.word2index[word] = self.n_words
                self.word2count[word] = 1
                self.index2word[self.n_words] = word
                self.n_words += 1
            else:
                self.word2count[word] += 1
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.