[NLP Project] F1 Score
·
Project/캡스톤디자인2
f1score란.. 블로그에서 해당 내용에 대해 다룬 게시글이 있으므로 나중에 링크 걸어두겠다. https://bestkcs1234.tistory.com/61 Tensorflow addons 을 이용한 F1 score 출력 tensorflow는 모델을 compile 할 때 다양한 metrics를 제공해준다. 다음과 같이 설정하면 매 epoch 마다 해당하는 수치들을 계산하여 출력해준다. 하지만 f1 score는 tf.metrics에서 찾아볼 수 없는데 Tensorflow a bestkcs1234.tistory.com from sklearn.metrics import classification_report,f1_score # f1 score p = model.predict(np.array(X_test)) ..
[NLP Project] LSTM + self-attention
·
Project/캡스톤디자인2
모델에 attention 층 추가 model.add(Bidirectional(LSTM(units=128, return_sequences=True, dropout=0.2, recurrent_dropout=0.2))) model.add(SeqSelfAttention(attention_activation='sigmoid')) model.add(Bidirectional(LSTM(units=64, return_sequences=True, dropout=0.2, recurrent_dropout=0.2))) model.add(SeqSelfAttention(attention_activation='sigmoid')) model.add(Dense(1, activation='sigmoid')) model.py from ke..
[NLP Project] input 값을 넣어 개체명 인식하기 - 오류 해결
·
Project/캡스톤디자인2
지난번 게시글에 학습한 모델을 바탕으로 새로운 input값을 넣어 개채명을 인식해보겠습니다. 지난번 코드와 출력결과는 아래와 같습니다. input_predict.py from keras.preprocessing.text import text_to_word_sequence from tensorflow.keras.preprocessing.text import Tokenizer from tensorflow.keras.preprocessing.sequence import pad_sequences from tensorflow.keras.models import load_model import numpy as np def tokenize(samples): tokenizer = Tokenizer() tokenizer..
[NLP Project] 성능 기록
·
Project/캡스톤디자인2
모델명: test_model.h5 파라미터 설정 test-train split : 8:2 Optimaizer: Adam Epoch = 3 batch_size=128 Learning_rate = 0.001 성능 loss: 0.1447 - accuracy: 0.7625 모델명: test_model2.h5 파라미터 설정 test-train split : 8:2 Optimaizer: Adam Epoch = 20 batch_size=128 Learning_rate = 0.005 성능 loss: 0.1796 - accuracy: 0.7463 학습로그 더보기 Epoch 1/20 2022-11-06 01:29:32.795455: I tensorflow/stream_executor/platform/default/dso_..
[NLP Project] 5. 정답 예측하기
·
Project/캡스톤디자인2
출력한 값을 토대로 정답을 예측하는 함수를 만들었다. 이번에는 모델을 학습 시키고 저장한 뒤 로드한 모델로 출력하는 함수까지 구현하였다. def model_predict(src_tokenizer,tar_tokenizer,model): # 예측 idx2word = src_tokenizer.index_word idx2ner = tar_tokenizer.index_word idx2ner[0] = 'PAD' i = 10 y_predicted = model.predict(np.array([X_test[i]])) y_predicted = np.argmax(y_predicted, axis = -1) # 가장 높은 확률을 추출 (예측값) true = np.argmax(y_test[i],-1) # 실제 값 print("..
[NLP Project] 4. LSTM 모델 구축
·
Project/캡스톤디자인2
모델 구축에는 keras 함수를 이용하였다. 그리고 옵티마이저는 Adam 모델의 구성은 다음과 같다. 1. 입력을 실수 벡터로 임베딩 2. 양방향 LSTM 구성 3. Dense Layer를 통한 각 태그에 속할 확률을 예측 TimeDistributed는 상위 layer의 출력이 step에 따라 여러개로 출력되어 이를 적절하게 분배해주는 역할을 한다. model.py from keras.models import Sequential from keras.layers import Dense, Embedding, LSTM, Bidirectional, TimeDistributed from keras.optimizers import Adam def modeling(vocab_size, max_len,tag_size)..
[NLP Project] 2. 토큰화 하기
·
Project/캡스톤디자인2
먼저 main.py를 생성하여 전체적인 실행을 관리할 파일을 만들었다. data_load.py import os # 파일 로드하고 텍스트파일 전처리하기 def file_load(file_path): tagged_sentences = [] sentences = [] with open(file_path,"r") as f: for line in f: if len(line) == 0 or line[0] == "\n": if len(sentences) > 0: tagged_sentences.append(sentences) sentences = [] splits = line.rstrip('\n').split('\t') if len(splits) == 3: sentences.append([splits[1],split..
[NLP Project] 1. 데이터 로드하고 전처리하기
·
Project/캡스톤디자인2
데이터를 로드하고 전처리해봅시다 사용한 데이터는 네이버 ner 데이터 셋을 이용하였습니다. 데이터셋 출처 -> https://github.com/naver/nlp-challenge GitHub - naver/nlp-challenge: NLP Shared tasks (NER, SRL) using NSML NLP Shared tasks (NER, SRL) using NSML. Contribute to naver/nlp-challenge development by creating an account on GitHub. github.com 해당 데이터셋을 텍스트파일로 바꾸어 사용하였습니다. 데이터는 이렇게 각 문장의 인덱스와 단어, 개체명 순서로 있습니다. 그럼 데이터를 사용하기 편하도록 전처리 해보겠습니다. ..
[캡스톤디자인2] OCR + NLP APP 제작 - 1
·
Project/App Project
보호되어 있는 글입니다.