해결된 질문
작성
·
9
0
안녕하세요.
코드 2-3의 SimpleTokenizerV1을 실행한 결과에 대해 문의드립니다.
아래 코드를 실행해보니 원문 text와 decode로 복원한 text가 조금 다릅니다.
원문과 복원한 text가 다르면 문제가 있을지 문의드립니다.
class SimpleTokenizerV1:
def __init__(self, vocab):
self.str_to_int = vocab
self.int_to_str = {i:s for s,i in vocab.items()}
def encode(self, text):
preprocessed = re.split(r'([,.:;?_!"()\']|--|\s)', text) # 'hello,. world'
preprocessed = [
item.strip() for item in preprocessed if item.strip()
]
ids = [self.str_to_int[s] for s in preprocessed]
return ids
def decode(self, ids):
text = " ".join([self.int_to_str[i] for i in ids])
# 구둣점 문자 앞의 공백을 삭제합니다.
text = re.sub(r'\s+([,.?!"()\'])', r'\1', text)
return text
tokenizer = SimpleTokenizerV1(vocab)
text = """"It's the last he painted, you know," Mrs. Gisburn said with pardonable pride."""
ids = tokenizer.encode(text)
print(text)
print(ids)
print(tokenizer.decode(ids))
"It's the last he painted, you know," Mrs. Gisburn said with pardonable pride.
[1, 56, 2, 850, 988, 602, 533, 746, 5, 1126, 596, 5, 1, 67, 7, 38, 851, 1108, 754, 793, 7]
" It' s the last he painted, you know," Mrs. Gisburn said with pardonable pride.
답변 1
1
안녕하세요. 이 토크나이저 클래스는 예시를 위해 간단히 만든 거라 완벽하게 복원되지 않는 것이 정상입니다. 실제 모델을 훈련할 때는 tiktoken 라이브러리를 사용하게 됩니다. 감사합니다!
감사합니다!