본문 바로가기

감성 분석3

yelp 리뷰 감성 분석 (3) 이 글은 파이토치로 배우는 자연어처리(O'REILLY, 한빛미디어)를 공부한 내용을 바탕으로 작성하였습니다. 훈련 반복 첫번째 for문 : epoch 수 만큼 반복 (전체 데이터셋) 두번째 for문 : batch 수 만큼 반복 train 데이터에 대해 param 학습 후 val 데이터로 검증 accuracy, loss 정보 저장 epoch_bar = tqdm.notebook.tqdm(desc='training routine', total=args.num_epochs, position=0) dataset.set_split('train') train_bar = tqdm.notebook.tqdm(desc='split=train', total=dataset.get_num_batches(args.batch_siz.. 2023. 3. 30.
yelp 리뷰 감성 분류 (2) 이 글은 파이토치로 배우는 자연어처리(O'REILLY, 한빛미디어)를 공부한 내용을 바탕으로 작성하였습니다. 퍼셉트론 분류기 완전연결(FC1) 계층 하나를 가진 퍼셉트론 분류기 손실 계산에서 BCEWithLogitsLoss()를 사용하도록 sigmoid를 거치지 않은 채 출력 class ReviewClassifier(nn.Module): """ 간단한 퍼셉트론 기반 분류기 """ def __init__(self, num_features): """ 매개변수: num_features (int): 입력 특성 벡터의 크기 """ super(ReviewClassifier, self).__init__() self.fc1 = nn.Linear(in_features=num_features, out_features=1).. 2023. 3. 30.
yelp 리뷰 감성 분류 (1) 이 글은 파이토치로 배우는 자연어처리(O'REILLY, 한빛미디어)를 공부한 내용을 바탕으로 작성하였습니다. yelp 레스토랑 리뷰 데이터셋 리뷰 텍스트(review)와 그에 맞는 평가 레이블(rating)를 준비하고, train, valid, test (0.7, 0.15, 0.15)로 분류 from argparse import Namespace from collections import Counter import json import os import re import string import numpy as np import pandas as pd import torch import torch.nn as nn import torch.nn.functional as F import torch.optim .. 2023. 3. 30.