전체 글
(NIA 데이터셋 과제준비) Oxford-IIIT Pet Dataset
# Images: https://www.robots.ox.ac.uk/~vgg/data/pets/data/images.tar.gz # Annotations: https://www.robots.ox.ac.uk/~vgg/data/pets/data/annotations.tar.gz from IPython.display import Image, display from tensorflow.keras.preprocessing.image import load_img import PIL from PIL import ImageOps import os from tensorflow.keras import layers input_dir = "/root/yj/yj/Kaggle/data/images" target_dir = "/r..
Brain MRI Images for Brain Tumor Detection
def load_data(dir_list, image_size): # load all images in a directory X = [] y = [] image_width, image_height = image_size for directory in dir_list: for filename in listdir(directory): image = cv2.imread(directory+'/'+filename) image = crop_brain_contour(image, plot=False) image = cv2.resize(image, dsize=(image_width, image_height), interpolation=cv2.INTER_CUBIC) # normalize values image = imag..
2022_Ukraine Russia War visualization
import numpy as np import pandas as pd import plotly import plotly.graph_objs as go import plotly.express as px from plotly.subplots import make_subplots import seaborn as sns ru_losses_per = pd.read_csv('/root/yj/yj/Kaggle/data/Ukraine_war/russia_losses_personnel.csv') ru_losses_eq = pd.read_csv('/root/yj/yj/Kaggle/data/Ukraine_war/russia_losses_equipment.csv') x, y = ru_losses_per['date'], ru_..
Age, Gender & Ethnicity Prediction
import numpy as np import pandas as pd import tensorflow as tf import tensorflow.keras.layers as L import matplotlib.pyplot as plt import plotly.graph_objects as go import plotly.express as px from sklearn.model_selection import train_test_split Loading Dataset data = pd.read_csv("/root/yj/yj/Kaggle/data/age_gender/age_gender.csv") data['pixels'] = data['pixels'].apply(lambda x : np.array(x.spli..
(NLP 연구) The Long-Document Transformer 04.01 (데이터셋 LSH 코딩)
import glob import os import io import string import re import random import spacy import torchtext from torchtext.vocab import Vectors import re import numpy as np import itertools from random import shuffle import time from tqdm import tqdm from numba import jit def get_split(text: str): text = text.replace('\t', " ") text = text.replace('\\', "") text = text.replace('--', "") text = re.sub(' ..
(NLP 연구) The Long-Document Transformer 03.31 (LSH)
import glob import os import io import string import re import random import spacy import torchtext from torchtext.vocab import Vectors import re import numpy as np import itertools from random import shuffle def create_hash_func(size: int): hash_ex = list(range(1, len(vocab)+1)) shuffle(hash_ex) return hash_ex def build_minhash_func(vocab_size: int, nbits: int): hashes = [] for _ in range(nbits..
(NLP 연구) The Long-Document Transformer 03.28
LSH hashing 구현 def shingle(text: str, k:int): shingle_set = [] for i in range(len(text) - k + 1): shingle_set.append(text[i:i+k]) return set(shingle_set) k = 2 a = shingle(a,k) b = shingle(b,k) c = shingle(c,2) vocab = list(a.union(b).union(c)) a_1hot = [1 if x in a else 0 for x in vocab] b_1hot = [1 if x in b else 0 for x in vocab] c_1hot = [1 if x in c else 0 for x in vocab] hash_ex = list(ran..
(NLP 연구) The Long-Document Transformer 03.24
To address this issue, numerous methods are proposed recently, such as the sparse attention matrix (Zaheer et al., 2020; Beltagy et al., 2020; Tay et al., 2020a; Kitaev et al., 2019; Child et al., 2019),lowrank representations (Wang et al., 2020) or kernel-based methods (Peng et al., 2020; Choromanski et al., 2020; Katharopoulos et al., 2020), among many others. These methods achieve reduced com..
(NLP 연구) The Long-Document Transformer 03.18
Full attention 테스트 데이터 25000개의 정답률:0.8719 다시 Window attention 실험 (epoch 20) 실험 (window) window_size 4 : 테스트 데이터 25000개의 정답률:0.8461 window_size 8 : 테스트 데이터 25000개의 정답률:0.8544 (영어문장 단어의평균수) window_size 16 : 테스트 데이터 25000개의 정답률:0.8454(영어문장 단어의평균수) window_size 32 : 테스트 데이터 25000개의 정답률:0.8299 실험 (window16 + global) window16 + global 16 : 테스트 데이터 25000개의 정답률:0.8643 epoch 100번 기준 (20정도 적당)
(NLP 연구) The Long-Document Transformer 03.17
성능 확인 Full attention 테스트 데이터 25000개의 정답률:0.8719 Sparse_attention (only window) window 16 → 테스트 데이터 25000개의 정답률:0.8591 window 32 → 테스트 데이터 25000개의 정답률:0.8609 window 64 → 테스트 데이터 25000개의 정답률:0.8154 window 128 → 테스트 데이터 25000개의 정답률:0.8591 Sparse_attention ( window + global) window32 + global 1 : 테스트 데이터 25000개의 정답률:0.8561 window32 + global 32 : 테스트 데이터 25000개의 정답률:0.8633 num_epochs = 10 window 32 →..
(NLP 연구) The Long-Document Transformer 03.16
Global attention attention word length : 5 → epoch 10 → acc 0.86474
(NLP 연구) The Long-Document Transformer 03.15
LSH hashing 기법 공부 LSH 알고리즘 Shingling 비슷한 문서일수록 더욱 많은 shingles를 공유한다 문서 에 있는 단락들의 순서를 바꿔도 shingles에는 영향을 주지 않는다 k의 값은 실제 응용에서 8~10개정도 사용 너무 작은 k는 대부분의 문서에서 반복적으로 등장 ex) gist = {gi, is, st} shingle 집합으로 쪼개진다. Jaccard Index shingle형태로 표현되었으면 유사성을 측정하는 측정치가 필요하다. 두 문서의 교집합의 개수에서 합집합의 개수를 나누어주면 된다. The Jaccard similarity of two sets is the size of their intersection divided by the size of their union.
(NLP 연구) The Long-Document Transformer 03.14
- attention layer 별 코딩 Local - > wide - attention을 Layer 별로 시각화 함수구현 - attention map 코딩 좁게 보다가 넓게 보는 것을 확인 기타공부 nn.Linear에 대하여 들어오는 float32형 input 데이터에 대해 y=wx+b 형태의 선형 변환을 수행하는 메소드
(NLP 연구) Paper 정리
Atomic Sparse Attention https://github.com/vene/sparse-structured-attention Compound Sparse Attention (위의 Atomic 이 모여 구성) Star Transformer (NAACL, 2019, 123회 인용) https://arxiv.org/abs/1902.09113 https://github.com/fastnlp/fastNLP Longformer: The Long-Document Transformer ****(2020, 708회 인용 / AllenAI) https://arxiv.org/pdf/2004.05150.pdf https://github.com/allenai/longformer ETC: Encoding Long an..
(NLP 연구) The Long-Document Transformer 03.10
Efficient Transformers: A Survey 읽어보자 https://arxiv.org/pdf/2009.06732.pdf Introduction on-device applications, models are supposed to be able to operate with a limited computational budget In this paper, we propose a taxonomy of efficient Transformer models, characterizing them by the technical innovation and primary use case The efficiency might also refer to computational costs, e.g. number of FL..
(NLP 연구) The Long-Document Transformer 03.04
attention is all you need 구현 및 attention 시각화 논문 읽고 수식의 이해 Attention ⇒ Global , Band, Random 구현 Band Attention → BLEU Score , Exact match Global → BLEU Score , Exact match Random → BLEU Score , Exact match Band + Global + Random → BLEU Score , Exact match Encoder layer 마다 Attention 다르게 비교 → 성능차이 Cost 계산식 코딩 (Big bird 참고) BLEU Score , Exact match 성능비교 실험 설계 Translation Dataset : Multi30k Full Atte..
(NLP 연구) The Long-Document Transformer 03.03
Transformer 공부 INPUT Encoder, Maxlength = 6일때 Sent1: i am looking for happiness {x1, x2, x3, x4, x5, } Positional Encoding Transformer에는 시간적인 정보를 담아내지 못하기때문에 Positonal Embedding Multi-Head Attention Query Key 동일 Value 동일 Attention value 값이 커지면 gradient vanishing 문제 끝에 PAD가 있다면 ? Q x K → Scaled → Pad token masking Self-Attended 자기자신을 보고 자신이 어디가 중요한지 보게됨 Concat Add & Norm Layer Normalization Feed ..
(NLP 연구) The Long-Document Transformer 03.02
2022.03.02 Token마다 Attention Layer를 동일하게 적용하는게 맞을까? 어떤 Token은 Full Attention은 적용하고 어떤 Token은 Sparse Attention을 적용하는게 맞지 않을까? 즉 토큰마다의 Overfit과 Underfit이 있지 않을까? Attention optimization이라고 논문의 표현이 맞을까? Week Plan Attention 관련 논문 읽기(이번주) Longformer: The Long-Document Transformer ****(2020, 708회 인용 / AllenAI) https://arxiv.org/pdf/2004.05150.pdf https://github.com/allenai/longformer ETC: Encoding Long..
(NLP 연구) The Long-Document Transformer 03.01
Attention Weigthts가 Feature Importance와 유사한가? Input length가 Attention의 단서증폭효과의 영향을 주나? 즉 Input의 문장이 길어지면 Downstream Task에 사용되는 단서가 많아지나? Token마다 Attention Layer를 동일하게 적용하는게 맞을까? 어떤 Token은 Full Attention은 적용하고 어떤 Token은 Sparse Attention을 적용하는게 맞지 않을까? 즉 토큰마다의 Overfit과 Underfit이 있지 않을까? Attention optimization이라고 논문의 표현이 맞을까? Motivate BIgbird 문서의 최대길이를 512 Token → 4096 Token으로 증가 BigBird (NeurIPS, ..
(딥러닝) Face Mask Detection
import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib.patches as mpatches import seaborn as sns from collections import Counter import os import xmltodict import torch from torchvision import datasets,transforms,models from torch.utils.data import Dataset,DataLoader from PIL import Image import sys import torch.optim as optim import xmltodict print("PyTorch Ver..
(챗봇) NLP Transformer Attention 시각화 구현하기
import math import numpy as np import random import torch import torch.nn as nn import torch.nn.functional as F import torchtext # Setup seeds torch.manual_seed(1234) np.random.seed(1234) random.seed(1234) #각 단어를 벡터로 변환 #Vocabulary 총단어수 * 분산표현의 차원수 class Embedder(nn.Module): def __init__(self, text_embedding_vectors): super(Embedder, self).__init__() self.embeddings = nn.Embedding.from_pretraine..
(챗봇) open domain question answering - Hugging Face
import unicodedata import numpy import sqlite3 import os import json import pickle from sqlalchemy import false DB_PATH = '/root/torch/dilbert/wikipedia/docs.db' ##========== the function and class below come from https://github.com/facebookresearch/DrQA (please check their license) def normalize(text): """Resolve different type of unicode encodings.""" return unicodedata.normalize('NFD', text) ..