From f0fda217c5d9f715e7e544f33701fc7014a6c802 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 12:06:20 +0900 Subject: [PATCH 01/20] Add Korean translation of code comments --- resources/docs/KOR_docs/TUTORIAL_1_BASICS.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_1_BASICS.md b/resources/docs/KOR_docs/TUTORIAL_1_BASICS.md index 2819b65e56..d85d8e3035 100644 --- a/resources/docs/KOR_docs/TUTORIAL_1_BASICS.md +++ b/resources/docs/KOR_docs/TUTORIAL_1_BASICS.md @@ -29,9 +29,9 @@ Sentence: "The grass is green ." [− Tokens: 5] 다음과 같이 토큰의 ID 나 인덱스를 통해 문장의 토큰에 액세스할 수도 있습니다. ```python -# token id +# 토큰 id print(sentence.get_token(4)) -# index itself +# 인덱스 자체 print(sentence[3]) ``` @@ -172,12 +172,12 @@ print(f'"{token}" is tagged as "{tag.value}" with confidence score "{tag.score}" ```python sentence = Sentence('France is the current world cup winner.') -# add a label to a sentence +# 문장에 라벨 추가 sentence.add_label('topic', 'sports') print(sentence) -# Alternatively, you can also create a sentence with label in one line +# 또는 한 줄에 레이블이 있는 문장을 만들 수도 있습니다. sentence = Sentence('France is the current world cup winner.').add_label('topic', 'sports') print(sentence) @@ -198,7 +198,7 @@ Sentence: "France is the current world cup winner." [− Tokens: 7 − Senten ```python sentence = Sentence('France is the current world cup winner.') -# this sentence has multiple topic labels +# 이 문장에는 여러 주제 레이블들이 있습니다. sentence.add_label('topic', 'sports') sentence.add_label('topic', 'soccer') ``` @@ -208,11 +208,11 @@ sentence.add_label('topic', 'soccer') ```python sentence = Sentence('France is the current world cup winner.') -# this sentence has multiple "topic" labels +# 이 문장에는 여러 "주제"의 레이블들이 있습니다. sentence.add_label('topic', 'sports') sentence.add_label('topic', 'soccer') -# this sentence has a "language" label +# 이 문장에는 "언어" 레이블이 있습니다. sentence.add_label('language', 'English') print(sentence) From 5ee145afbefd226606b445b318017c35445f7547 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 12:24:26 +0900 Subject: [PATCH 02/20] Update TUTORIAL_2_TAGGING.md Add Korean translation of code comments --- resources/docs/KOR_docs/TUTORIAL_2_TAGGING.md | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_2_TAGGING.md b/resources/docs/KOR_docs/TUTORIAL_2_TAGGING.md index 43e7e2dee9..72e45b6e9b 100644 --- a/resources/docs/KOR_docs/TUTORIAL_2_TAGGING.md +++ b/resources/docs/KOR_docs/TUTORIAL_2_TAGGING.md @@ -20,10 +20,10 @@ tagger = SequenceTagger.load('ner') ```python sentence = Sentence('George Washington went to Washington.') -# predict NER tags +# NER 태그 예측 tagger.predict(sentence) -# print sentence with predicted tags +# 예측된 태그가 있는 문장 출력 print(sentence.to_tagged_string()) ``` @@ -75,13 +75,13 @@ print(sentence.to_dict(tag_type='ner')) ```python from flair.models import MultiTagger -# load tagger for POS and NER +# POS와 NER 용 tagger 로드 tagger = MultiTagger.load(['pos', 'ner']) -# make example sentence +# 예시 문장 만들기 sentence = Sentence("George Washington went to Washington.") -# predict with both models +# 두 모델로 예측 tagger.predict(sentence) print(sentence) @@ -168,16 +168,16 @@ NER 모델은 4개 언어(영어, 독일어, 네덜란드어 및 스페인어) ```python -# load model +# 모델 로드 tagger = SequenceTagger.load('de-ner') -# make German sentence +# 독일어 문장 만들기 sentence = Sentence('George Washington ging nach Washington.') -# predict NER tags +# NER 태그 예측 tagger.predict(sentence) -# print sentence with predicted tags +# 예측된 태그가 있는 문장 출력 print(sentence.to_tagged_string()) ``` @@ -191,16 +191,16 @@ George Washington ging nach Washington . Flair는 또한 오른쪽에서 왼쪽으로 쓰는 언어에서도 작동한다. 아랍어 문장에 태그를 지정하려면 적절한 모델을 로드하면 됩니다. ```python -# load model +# 모델 로드 tagger = SequenceTagger.load('ar-ner') -# make Arabic sentence +# 아랍어 문장 만들기 sentence = Sentence("احب برلين") -# predict NER tags +# NER 태그 예측 tagger.predict(sentence) -# print sentence with predicted tags +# 예측된 태그가 있는 문장 출력 for entity in sentence.get_labels('ner'): print(entity) ``` @@ -216,16 +216,16 @@ LOC [برلين (2)] (0.9803) ```python -# load model +# 모델 로드 tagger = SequenceTagger.load('pos-multi') -# text with English and German sentences +# 영어와 독일어 문장으로 된 텍스트 sentence = Sentence('George Washington went to Washington. Dort kaufte er einen Hut.') -# predict PoS tags +# PoS 태그 예측 tagger.predict(sentence) -# print sentence with predicted tags +# 예측된 태그가 있는 문장 출력 print(sentence.to_tagged_string()) ``` @@ -246,18 +246,18 @@ Dort kaufte er einen Hut . 예를 들어 보겠습니다. ```python -# load model +# 모델 로드 tagger = SequenceTagger.load('frame') -# make English sentence +# 영어 문장 만들기 sentence_1 = Sentence('George returned to Berlin to return his hat.') sentence_2 = Sentence('He had a look at different hats.') -# predict NER tags +# NER 태그 예측하기 tagger.predict(sentence_1) tagger.predict(sentence_2) -# print sentence with predicted tags +# 예측된 태그가 있는 문장 출력 print(sentence_1.to_tagged_string()) print(sentence_2.to_tagged_string()) ``` @@ -286,20 +286,20 @@ look은 단어를 연상시키는 틀이다. from flair.models import SequenceTagger from flair.tokenization import SegtokSentenceSplitter -# example text with many sentences +# 많은 문장이 포함된 예제 텍스트 text = "This is a sentence. This is another sentence. I love Berlin." -# initialize sentence splitter +# 문장 스플리터 초기화 splitter = SegtokSentenceSplitter() -# use splitter to split text into list of sentences +# 스플리터를 사용하여 텍스트를 문장 목록으로 분할 sentences = splitter.split(text) -# predict tags for sentences +# 문장에 대한 태그 예측 tagger = SequenceTagger.load('ner') tagger.predict(sentences) -# iterate through sentences and print predicted labels +# 문장을 반복하고 예측된 레이블을 출력 for sentence in sentences: print(sentence.to_tagged_string()) ``` @@ -317,20 +317,20 @@ for sentence in sentences: ```python from flair.models import TextClassifier -# load tagger +# tagger 로드 classifier = TextClassifier.load('sentiment') ``` 여러분은 문장에서 분류자의 `predict()`방법만 사용하면 됩니다. 예측 레이블에 추가하고, 긍정적인 느낌의 문장을 사용해봅시다. ```python -# make example sentence +# 예시 문장 만들기 sentence = Sentence("enormously entertaining for moviegoers of any age.") -# call predict +# predict 호출 classifier.predict(sentence) -# check prediction +# 예측 확인하기 print(sentence) ``` From 630c497ab015591881d9ed9579691812df6139fc Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 13:05:53 +0900 Subject: [PATCH 03/20] Update README.md --- resources/docs/KOR_docs/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/docs/KOR_docs/README.md b/resources/docs/KOR_docs/README.md index e1d9705388..5f1beca117 100644 --- a/resources/docs/KOR_docs/README.md +++ b/resources/docs/KOR_docs/README.md @@ -178,6 +178,9 @@ Flair 임베딩(PooledFlairEmbeddings)의 풀링 버전을 사용하는 경우 [ 질문이나 의견은 [Alan Akbik](http://alanakbik.github.io/)로 이메일을 보내주세요. +한국어 번역에 대한 의견은 +김한결 (hannn0414@naver.com), 박태현(abnc7800@gmail.com), 최완규(wanq123@gachon.ac.kr)로 이메일을 보내주세요. + ## Contributing contributing에 관심을 가져주셔서 감사합니다! 참여하는 방법에는 여러 가지가 있습니다. From 92a375593b084cceeccf72167bcda739c14bcfcb Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 13:22:35 +0900 Subject: [PATCH 04/20] added Korean translation of code comments --- .../KOR_docs/TUTORIAL_3_WORD_EMBEDDING.md | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_3_WORD_EMBEDDING.md b/resources/docs/KOR_docs/TUTORIAL_3_WORD_EMBEDDING.md index 46a41d43e3..41d7311825 100644 --- a/resources/docs/KOR_docs/TUTORIAL_3_WORD_EMBEDDING.md +++ b/resources/docs/KOR_docs/TUTORIAL_3_WORD_EMBEDDING.md @@ -25,20 +25,20 @@ GloVe 임베딩을 사용하려면 'glove' 문자열을 생성자에게 전달 from flair.embeddings import WordEmbeddings from flair.data import Sentence -# init embedding +# 임베딩 초기화 glove_embedding = WordEmbeddings('glove') ``` 이제 예제 문장을 만들고 임베딩의 `embed()` 메서드를 호출합니다. 일부 임베딩 유형은 속도를 높이기 위해 배치를 사용하기 때문에 문장 목록을 이 방법으로 전달할 수도 있습니다. ```python -# create sentence. +# 문장 만들기 sentence = Sentence('The grass is green .') -# embed a sentence using glove. +# glove를 사용하여 문장 삽입 glove_embedding.embed(sentence) -# now check out the embedded tokens. +# 이제 포함된 토큰을 확인하십시오. for token in sentence: print(token) print(token.embedding) @@ -74,13 +74,13 @@ Flair를 사용할 때, 표준 단어 임베딩과 같은 적절한 임베딩 ```python from flair.embeddings import FlairEmbeddings -# init embedding +# 임베딩 초기화 flair_embedding_forward = FlairEmbeddings('news-forward') -# create a sentence +# 문장 만들기 sentence = Sentence('The grass is green .') -# embed words in sentence +# 문장에 단어 삽입 flair_embedding_forward.embed(sentence) ``` @@ -111,10 +111,10 @@ flair_embedding_backward = FlairEmbeddings('de-backward') ```python from flair.embeddings import WordEmbeddings, FlairEmbeddings -# init standard GloVe embedding +# 표준 GloVe 임베딩 초기화 glove_embedding = WordEmbeddings('glove') -# init Flair forward and backwards embeddings +# Flair 정방향 및 역방향 임베딩 초기화 flair_embedding_forward = FlairEmbeddings('news-forward') flair_embedding_backward = FlairEmbeddings('news-backward') ``` @@ -124,7 +124,7 @@ flair_embedding_backward = FlairEmbeddings('news-backward') ```python from flair.embeddings import StackedEmbeddings -# create a StackedEmbedding object that combines glove and forward/backward flair embeddings +# glove와 정방향 및 역방향 Flair 임베딩을 결합하는 StackedEmbedding 개체를 만들기 stacked_embeddings = StackedEmbeddings([ glove_embedding, flair_embedding_forward, @@ -137,10 +137,10 @@ stacked_embeddings = StackedEmbeddings([ ```python sentence = Sentence('The grass is green .') -# just embed a sentence using the StackedEmbedding as you would with any single embedding. +# 단일 임베딩에서와 같이 StackedEmbedding을 사용하여 문장을 임베드하기만 하면 됩니다. stacked_embeddings.embed(sentence) -# now check out the embedded tokens. +# 이제 임베딩된 토큰을 확인하십시오. for token in sentence: print(token) print(token.embedding) From 5204bebf0f2f01701ba8dc97031693e8d2388230 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 13:23:08 +0900 Subject: [PATCH 05/20] Update TUTORIAL_3_WORD_EMBEDDING.md --- resources/docs/KOR_docs/TUTORIAL_3_WORD_EMBEDDING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_3_WORD_EMBEDDING.md b/resources/docs/KOR_docs/TUTORIAL_3_WORD_EMBEDDING.md index 41d7311825..eced7660a1 100644 --- a/resources/docs/KOR_docs/TUTORIAL_3_WORD_EMBEDDING.md +++ b/resources/docs/KOR_docs/TUTORIAL_3_WORD_EMBEDDING.md @@ -150,4 +150,4 @@ for token in sentence: ## Next 이러한 임베딩에 대한 자세한 내용과 지원되는 모든 단어 임베딩에 대한 전체 개요를 보려면 다음을 참조하십시오. -[튜토리얼](/resources/docs/KOR_docs/TUTORIAL_4_ELMO_BERT_FLAIR_EMBEDDING.md). +[TUTORIAL_4_ELMO_BERT_FLAIR_EMBEDDING](/resources/docs/KOR_docs/TUTORIAL_4_ELMO_BERT_FLAIR_EMBEDDING.md). From d8b4448a5cee4fa58766000dc6de59e5bf431f12 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 13:27:29 +0900 Subject: [PATCH 06/20] Add Korean translation of code comments --- resources/docs/KOR_docs/TUTORIAL_6_CORPUS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_6_CORPUS.md b/resources/docs/KOR_docs/TUTORIAL_6_CORPUS.md index 31727a2e73..ef9f0abc2a 100644 --- a/resources/docs/KOR_docs/TUTORIAL_6_CORPUS.md +++ b/resources/docs/KOR_docs/TUTORIAL_6_CORPUS.md @@ -35,7 +35,7 @@ Sentence: "What if Google Morphed Into GoogleOS ?" - 7 Tokens 이 문장은 통사적, 형태학적 정보가 tag되어 있습니다. POS 태그를 사용해 문장을 인쇄해보겠습니다 : ```python -# print the first Sentence in the training split +# 훈련중인 split에서 첫 번째 문장을 출력합니다. print(corpus.test[0].to_tagged_string('pos')) ``` 결과입니다 : From 9ed36fbad0d80a5cab8d096d55088dbbe7433104 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 13:29:38 +0900 Subject: [PATCH 07/20] Update README.md --- resources/docs/KOR_docs/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/docs/KOR_docs/README.md b/resources/docs/KOR_docs/README.md index 5f1beca117..79b249a150 100644 --- a/resources/docs/KOR_docs/README.md +++ b/resources/docs/KOR_docs/README.md @@ -67,11 +67,11 @@ pip install flair ```python from flair.data import Sentence from flair.models import SequenceTagger -# make a sentence +# 문장 만들기 sentence = Sentence('I love Berlin .') -# load the NER tagger +# NER tagger 로드하기 tagger = SequenceTagger.load('ner') -# run NER over sentence +# 문장에 대해 NER 실행 tagger.predict(sentence) ``` @@ -80,7 +80,7 @@ tagger.predict(sentence) ```python print(sentence) print('The following NER tags are found:') -# iterate over entities and print +# 엔티티를 반복하고 출력하기. for entity in sentence.get_spans('ner'): print(entity) ``` From 8098c94a4c91ee94bea1e7b377682957f0c5f198 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 13:30:00 +0900 Subject: [PATCH 08/20] Update README.md --- resources/docs/KOR_docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/docs/KOR_docs/README.md b/resources/docs/KOR_docs/README.md index 79b249a150..de46460264 100644 --- a/resources/docs/KOR_docs/README.md +++ b/resources/docs/KOR_docs/README.md @@ -80,7 +80,7 @@ tagger.predict(sentence) ```python print(sentence) print('The following NER tags are found:') -# 엔티티를 반복하고 출력하기. +# 엔티티를 반복하고 출력하기 for entity in sentence.get_spans('ner'): print(entity) ``` From 2f15c5fff6fb0b20f31ca33d74fea7d4927ad10e Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 13:30:23 +0900 Subject: [PATCH 09/20] Update README.md --- resources/docs/KOR_docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/docs/KOR_docs/README.md b/resources/docs/KOR_docs/README.md index de46460264..e01e0cf321 100644 --- a/resources/docs/KOR_docs/README.md +++ b/resources/docs/KOR_docs/README.md @@ -179,7 +179,7 @@ Flair 임베딩(PooledFlairEmbeddings)의 풀링 버전을 사용하는 경우 [ 질문이나 의견은 [Alan Akbik](http://alanakbik.github.io/)로 이메일을 보내주세요. 한국어 번역에 대한 의견은 -김한결 (hannn0414@naver.com), 박태현(abnc7800@gmail.com), 최완규(wanq123@gachon.ac.kr)로 이메일을 보내주세요. +김한결(hannn0414@naver.com), 박태현(abnc7800@gmail.com), 최완규(wanq123@gachon.ac.kr)로 이메일을 보내주세요. ## Contributing From 96ca94ab475959906509ac411e38d4fd29d800e8 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 13:53:24 +0900 Subject: [PATCH 10/20] Add Korean translation of code comments --- .../KOR_docs/TUTORIAL_7_TRAINING_A_MODEL.md | 108 +++++++++--------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_7_TRAINING_A_MODEL.md b/resources/docs/KOR_docs/TUTORIAL_7_TRAINING_A_MODEL.md index b057163570..f196a1b641 100644 --- a/resources/docs/KOR_docs/TUTORIAL_7_TRAINING_A_MODEL.md +++ b/resources/docs/KOR_docs/TUTORIAL_7_TRAINING_A_MODEL.md @@ -13,25 +13,23 @@ ## 품사 Tagging 모델 훈련 -다음 예제는 간단한 글로브(Glove) 임베딩을 이용하여 UD_ENGLISH (English universal dependency treebank) 데이터를 통해 훈련된 작은 품사 tagger -모델에 대한 코드입니다. -이 예제에서는 더 빠르게 작동시키기 위해 기존 데이터의 10%로 다운샘플링하여 진행했지만, 보통의 경우에는 전체 데이터셋으로 훈련 -시켜야 합니다: +다음 예제는 간단한 글로브(Glove) 임베딩을 이용하여 UD_ENGLISH (English universal dependency treebank) 데이터를 통해 훈련된 작은 품사 tagger 모델에 대한 코드입니다. +이 예제에서는 더 빠르게 작동시키기 위해 기존 데이터의 10%로 다운샘플링하여 진행했지만, 보통의 경우에는 전체 데이터셋으로 훈련시켜야 합니다: ```python from flair.datasets import UD_ENGLISH from flair.embeddings import WordEmbeddings, StackedEmbeddings from flair.models import SequenceTagger from flair.trainers import ModelTrainer -# 1. get the corpus +# 1. 말뭉치 가져오기 corpus = UD_ENGLISH().downsample(0.1) print(corpus) -# 2. what label do we want to predict? +# 2. 어떤 레이블을 예측하고 싶으신가요? label_type = 'upos' -# 3. make the label dictionary from the corpus +# 3. 말뭉치에서 레이블 사전 만들기 label_dict = corpus.make_label_dictionary(label_type=label_type) print(label_dict) -# 4. initialize embeddings +# 4. 임베딩 초기화하기 embedding_types = [ WordEmbeddings('glove'), # comment in this line to use character embeddings @@ -41,15 +39,15 @@ embedding_types = [ # FlairEmbeddings('news-backward'), ] embeddings = StackedEmbeddings(embeddings=embedding_types) -# 5. initialize sequence tagger +# 5. 시퀀스 tagger 초기화하기 tagger = SequenceTagger(hidden_size=256, embeddings=embeddings, tag_dictionary=label_dict, tag_type=label_type, use_crf=True) -# 6. initialize trainer +# 6. 트레이너 초기화하기 trainer = ModelTrainer(tagger, corpus) -# 7. start training +# 7. 훈련 시작 trainer.train('resources/taggers/example-upos', learning_rate=0.1, mini_batch_size=32, @@ -63,11 +61,11 @@ trainer.train('resources/taggers/example-upos', 모델이 학습되면 이를 사용하여 새 문장의 태그를 예측할 수 있습니다. 모델의 'predict' 메서드를 호출하기만 하면 됩니다. ```python -# load the model you trained +# 훈련한 모델 로드하기 model = SequenceTagger.load('resources/taggers/example-pos/final-model.pt') -# create example sentence +# 예시 문장 만들기 sentence = Sentence('I love Berlin') -# predict tags and print +# 태그 예측하고 출력하기 model.predict(sentence) print(sentence.to_tagged_string()) ``` @@ -86,30 +84,30 @@ from flair.datasets import CONLL_03 from flair.embeddings import WordEmbeddings, FlairEmbeddings, StackedEmbeddings from flair.models import SequenceTagger from flair.trainers import ModelTrainer -# 1. get the corpus +# 1. 말뭉치 가져오기 corpus = CONLL_03() print(corpus) -# 2. what label do we want to predict? +# 2. 어떤 레이블을 예측하고 싶으신가요? label_type = 'ner' -# 3. make the label dictionary from the corpus +# 3. 말뭉치에서 레이블 사전 만들기 label_dict = corpus.make_label_dictionary(label_type=label_type) print(label_dict) -# 4. initialize embedding stack with Flair and GloVe +# 4. Flair 및 GloVe로 임베딩 스택 초기화하기 embedding_types = [ WordEmbeddings('glove'), FlairEmbeddings('news-forward'), FlairEmbeddings('news-backward'), ] embeddings = StackedEmbeddings(embeddings=embedding_types) -# 5. initialize sequence tagger +# 5. 시퀀스 tagger 초기화하기 tagger = SequenceTagger(hidden_size=256, embeddings=embeddings, tag_dictionary=label_dict, tag_type=label_type, use_crf=True) -# 6. initialize trainer +# 6. 트레이너 초기화하기 trainer = ModelTrainer(tagger, corpus) -# 7. start training +# 7. 훈련 시작 trainer.train('resources/taggers/sota-ner-flair', learning_rate=0.1, mini_batch_size=32, @@ -133,15 +131,15 @@ from flair.models import SequenceTagger from flair.trainers import ModelTrainer import torch from torch.optim.lr_scheduler import OneCycleLR -# 1. get the corpus +# 1. 말뭉치 가져오기 corpus = CONLL_03() print(corpus) -# 2. what label do we want to predict? +# 2. 어떤 레이블을 예측하고 싶으신가요? label_type = 'ner' -# 3. make the label dictionary from the corpus +# 3. 말뭉치에서 레이블 사전 만들기 label_dict = corpus.make_label_dictionary(label_type=label_type) print(label_dict) -# 4. initialize fine-tuneable transformer embeddings WITH document context +# 4. 문서 컨텍스트로 미세 조정 가능한 변환기 임베딩 초기화 embeddings = TransformerWordEmbeddings( model='xlm-roberta-large', layers="-1", @@ -149,7 +147,7 @@ embeddings = TransformerWordEmbeddings( fine_tune=True, use_context=True, ) -# 5. initialize bare-bones sequence tagger (no CRF, no RNN, no reprojection) +# 5. bare-bones 시퀀스 태거 초기화하기 (CRF 없음, RNN 없음, 재투영 없음) tagger = SequenceTagger( hidden_size=256, embeddings=embeddings, @@ -159,9 +157,9 @@ tagger = SequenceTagger( use_rnn=False, reproject_embeddings=False, ) -# 6. initialize trainer with AdamW optimizer +# 6. AdamW 옵티마이저로 트레이너 초기화하기 trainer = ModelTrainer(tagger, corpus, optimizer=torch.optim.AdamW) -# 7. run training with XLM parameters (20 epochs, small LR, one-cycle learning rate scheduling) +# 7. XLM 매개변수로 훈련 실행(20 epochs, 작은 LR, 1주기 학습률 스케줄링) trainer.train('resources/taggers/sota-ner-flert', learning_rate=5.0e-6, mini_batch_size=4, @@ -193,19 +191,19 @@ from flair.datasets import TREC_6 from flair.embeddings import TransformerDocumentEmbeddings from flair.models import TextClassifier from flair.trainers import ModelTrainer -# 1. get the corpus +# 1. 말뭉치 가져오기 corpus: Corpus = TREC_6() -# 2. what label do we want to predict? +# 2. 어떤 레이블을 예측하고 싶으신가요? label_type = 'question_class' -# 3. create the label dictionary +# 3. 레이블 사전 만들기 label_dict = corpus.make_label_dictionary(label_type=label_type) -# 4. initialize transformer document embeddings (many models are available) +# 4. 변환기 문서 임베딩 초기화하기 (많은 모델 사용 가능) document_embeddings = TransformerDocumentEmbeddings('distilbert-base-uncased', fine_tune=True) -# 5. create the text classifier +# 5. 텍스트 분류 만들기 classifier = TextClassifier(document_embeddings, label_dictionary=label_dict, label_type=label_type) -# 6. initialize trainer with AdamW optimizer +# 6. AdamW 옵티마이저로 트레이너 초기화하기 trainer = ModelTrainer(classifier, corpus, optimizer=torch.optim.AdamW) -# 7. run training with fine-tuning +# 7. 미세 조정으로 훈련 실행 trainer.train('resources/taggers/question-classification-with-transformer', learning_rate=5.0e-5, mini_batch_size=4, @@ -220,9 +218,9 @@ trainer.train('resources/taggers/question-classification-with-transformer', ```python classifier = TextClassifier.load('resources/taggers/question-classification-with-transformer/final-model.pt') -# create example sentence +# 예시 문장 만들기 sentence = Sentence('Who built the Eiffel Tower ?') -# predict class and print +# 클래스를 예측하고 출력하기 classifier.predict(sentence) print(sentence.labels) ``` @@ -238,29 +236,29 @@ from flair.datasets import UD_ENGLISH, UD_GERMAN from flair.embeddings import FlairEmbeddings, StackedEmbeddings from flair.models import SequenceTagger from flair.trainers import ModelTrainer -# 1. get the corpora - English and German UD +# 1. 말뭉치 가져오기 - 영어 및 독일어 UD corpus = MultiCorpus([UD_ENGLISH(), UD_GERMAN()]).downsample(0.1) -# 2. what label do we want to predict? +# 2. 어떤 레이블을 예측하고 싶으신가요? label_type = 'upos' -# 3. make the label dictionary from the corpus +# 3. 말뭉치에서 레이블 사전 만들기 label_dict = corpus.make_label_dictionary(label_type=label_type) print(label_dict) -# 4. initialize embeddings +# 4. 임베딩 초기화하기 embedding_types = [ # we use multilingual Flair embeddings in this task FlairEmbeddings('multi-forward'), FlairEmbeddings('multi-backward'), ] embeddings = StackedEmbeddings(embeddings=embedding_types) -# 5. initialize sequence tagger +# 5. 시퀀스 tagger 초기화하기 tagger = SequenceTagger(hidden_size=256, embeddings=embeddings, tag_dictionary=label_dict, tag_type=label_type, use_crf=True) -# 6. initialize trainer +# 6. 트레이너 초기화하기 trainer = ModelTrainer(tagger, corpus) -# 7. start training +# 7. 훈련 시작 trainer.train('resources/taggers/example-universal-pos', learning_rate=0.1, mini_batch_size=32, @@ -278,13 +276,13 @@ Flair에는 신경망에서 훈련 곡선과 가중치를 표시하는 도우미 훈련 후 plotter가 다음 파일을 가리킬 것입니다: ```python -# set write_weights to True to write weights +# 가중치를 쓰려면 write_weights를 True로 설정하세요. trainer.train('resources/taggers/example-universal-pos', ... write_weights = True, ... ) -# visualize +# 가시화하기 from flair.visual.training_curves import Plotter plotter = Plotter() plotter.plot_training_curves('loss.tsv') @@ -308,33 +306,33 @@ from flair.embeddings import TokenEmbeddings, WordEmbeddings, StackedEmbeddings from typing import List from flair.models import SequenceTagger from flair.trainers import ModelTrainer -# 1. get the corpus +# 1. 말뭉치 가져오기 corpus: Corpus = WNUT_17().downsample(0.1) -# 2. what label do we want to predict? +# 2. 어떤 레이블을 예측하고 싶으신가요? label_type = 'ner' -# 3. make the label dictionary from the corpus +# 3. 말뭉치에서 레이블 사전 만들기 label_dict = corpus.make_label_dictionary(label_type=label_type) -# 4. initialize embeddings +# 4. 임베딩 초기화하기 embedding_types: List[TokenEmbeddings] = [ WordEmbeddings('glove') ] embeddings: StackedEmbeddings = StackedEmbeddings(embeddings=embedding_types) -# 5. initialize sequence tagger +# 5. 시퀀스 tagger 초기화하기 tagger: SequenceTagger = SequenceTagger(hidden_size=256, embeddings=embeddings, tag_dictionary=label_dict, tag_type=label_type, use_crf=True) -# 6. initialize trainer +# 6. 트레이너 초기화하기 trainer: ModelTrainer = ModelTrainer(tagger, corpus) -# 7. start training +# 7. 훈련 시작 trainer.train('resources/taggers/example-ner', learning_rate=0.1, mini_batch_size=32, max_epochs=10, checkpoint=True) -# 8. stop training at any point -# 9. continue trainer at later point +# 8. 언제든지 훈련을 중단하세요. +# 9. 나중에 트레이너를 계속하세요. checkpoint = 'resources/taggers/example-ner/checkpoint.pt' trainer = ModelTrainer.load_checkpoint(checkpoint, corpus) trainer.train('resources/taggers/example-ner', From ec6bcc6664762c8fc5322bdedf57a260a7fe9801 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 13:58:30 +0900 Subject: [PATCH 11/20] Added Korean translation of code --- .../KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md b/resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md index d3ebcfe0b9..7257b6c8e6 100644 --- a/resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md +++ b/resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md @@ -12,7 +12,7 @@ Flair에는 잘 알려진 하이퍼 매개변수 선택 도구인 [hyperopt](htt ```python from flair.datasets import TREC_6 -# load your corpus +# 당신의 말뭉치를 로드하세요. corpus = TREC_6() ``` @@ -21,7 +21,7 @@ corpus = TREC_6() ```python from hyperopt import hp from flair.hyperparameter.param_selection import SearchSpace, Parameter -# define your search space +# 검색 공간을 정의하세요. search_space = SearchSpace() search_space.add(Parameter.EMBEDDINGS, hp.choice, options=[ [ WordEmbeddings('en') ], @@ -53,7 +53,7 @@ hyperopt가 수행해야 하는 최대 평가 실행 횟수를 정의할 수 있 ```python from flair.hyperparameter.param_selection import TextClassifierParamSelector, OptimizationValue -# create the parameter selector +# 매개변수 선택기 생성 param_selector = TextClassifierParamSelector( corpus, False, @@ -63,7 +63,7 @@ param_selector = TextClassifierParamSelector( training_runs=3, optimization_value=OptimizationValue.DEV_SCORE ) -# start the optimization +# 최적화 시작 param_selector.optimize(search_space, max_evals=100) ``` @@ -82,11 +82,6 @@ SGD의 모든 배치 업데이트에서 학습률을 기하급수적으로 증 낮은 학습률의 경우 손실이 개선되지 않으며, 손실이 가장 급격하게 떨어지는 최적의 학습률 범위와 학습률이 너무 커지면 손실이 폭발하는 최종 단계입니다. 이러한 플롯을 사용하면 최적의 학습률을 선택하는 것이 최적의 단계에서 가장 높은 것을 선택하는 것만큼 쉽습니다. -In order to run such an experiment start with your initialized `ModelTrainer` and call `find_learning_rate()` with the -`base_path` and the file name in which to records the learning rates and losses. Then plot the generated results via the -`Plotter`'s `plot_learning_rate()` function and have a look at the `learning_rate.png` image to select the optimal -learning rate: - 이러한 실험을 실행하려면 초기화된 'ModelTrainer'로 시작하고 학습률과 손실을 기록할 파일 이름과 'base_path'와 함께 'find_learning_rate()'를 호출하십시오. 그런 다음 `Plotter`의 `plot_learning_rate()` 함수를 통해 생성된 결과를 플롯하고 `learning_rate.png` 이미지를 보고 최적의 학습률을 선택하세요: @@ -95,32 +90,32 @@ from flair.datasets import WNUT_17 from flair.embeddings import TokenEmbeddings, WordEmbeddings, StackedEmbeddings from flair.trainers import ModelTrainer from typing import List -# 1. get the corpus +# 1. 말뭉치 가져오기 corpus = WNUT_17().downsample(0.1) print(corpus) -# 2. what tag do we want to predict? +# 2. 우리는 예측하고 싶은 태그는 무엇인가요? tag_type = 'ner' -# 3. make the tag dictionary from the corpus +# 3. 말뭉치에서 태그 사전 만들기 tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type) print(tag_dictionary.idx2item) -# 4. initialize embeddings +# 4. 임베딩 초기화하기 embedding_types: List[TokenEmbeddings] = [ WordEmbeddings('glove'), ] embeddings: StackedEmbeddings = StackedEmbeddings(embeddings=embedding_types) -# 5. initialize sequence tagger +# 5. 시퀀스 tagger 초기화하기 from flair.models import SequenceTagger tagger: SequenceTagger = SequenceTagger(hidden_size=256, embeddings=embeddings, tag_dictionary=tag_dictionary, tag_type=tag_type, use_crf=True) -# 6. initialize trainer +# 6. 트레이너 초기화하기 trainer: ModelTrainer = ModelTrainer(tagger, corpus) -# 7. find learning rate +# 7. 학습률 찾기 learning_rate_tsv = trainer.find_learning_rate('resources/taggers/example-ner', 'learning_rate.tsv') -# 8. plot the learning rate finder curve +# 8. 학습률 찾기 곡선 그리기 from flair.visual.training_curves import Plotter plotter = Plotter() plotter.plot_learning_rate(learning_rate_tsv) From d966f5067bc66b5cf99f7c4c9c2eafdd3bb00675 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 13:59:03 +0900 Subject: [PATCH 12/20] Added Korean translation --- resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md b/resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md index 7257b6c8e6..528df15ce0 100644 --- a/resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md +++ b/resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md @@ -1,4 +1,4 @@ -# Tutorial 8: Model Tuning +# Tutorial 8: 모델 튜닝 튜토리얼 8에서는 올바른 모델 및 하이퍼 매개변수 셋을 선택하여 모델의 품질을 향상시킬 수 있는 방법을 살펴볼 것입니다. From 86b24ce8745a9548044b2636c9e663528ed3b410 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 14:08:55 +0900 Subject: [PATCH 13/20] Added Korean translation of code comments --- .../TUTORIAL_9_TRAINING_LM_EMBEDDINGS.md | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_9_TRAINING_LM_EMBEDDINGS.md b/resources/docs/KOR_docs/TUTORIAL_9_TRAINING_LM_EMBEDDINGS.md index a675a7d795..b30d009866 100644 --- a/resources/docs/KOR_docs/TUTORIAL_9_TRAINING_LM_EMBEDDINGS.md +++ b/resources/docs/KOR_docs/TUTORIAL_9_TRAINING_LM_EMBEDDINGS.md @@ -1,6 +1,6 @@ # Tutorial 9: 여러분만의 Flair 임베딩을 훈련하세요! -Flair Embeddings는 Flair의 비밀 소스이며, 이를 통해 다양한 NLP 작업에서 최첨단 정확도를 달성할 수 있습니다. +Flair 임베딩은 Flair의 비밀 소스이며, 이를 통해 다양한 NLP 작업에서 최첨단 정확도를 달성할 수 있습니다. 이 튜토리얼에서는 자신만의 Flair 임베딩을 훈련하는 방법을 알려줄 것입니다. 이는 Flair를 새로운 언어나 도메인에 적용하려는 경우에 유용할 수 있습니다. @@ -38,21 +38,21 @@ corpus/valid.txt from flair.data import Dictionary from flair.models import LanguageModel from flair.trainers.language_model_trainer import LanguageModelTrainer, TextCorpus -# are you training a forward or backward LM? +# 앞으로 혹은 뒤로 LM을 훈련하고 있나요? is_forward_lm = True -# load the default character dictionary +# 기본 문자 사전 로드 dictionary: Dictionary = Dictionary.load('chars') -# get your corpus, process forward and at the character level +# 당신의 말뭉치를 가져와서, 앞으로 그리고 문자 레벨에서 진행하세요. corpus = TextCorpus('/path/to/your/corpus', dictionary, is_forward_lm, character_level=True) -# instantiate your language model, set hidden size and number of layers +# 언어 모델 인스턴스화, 숨겨진 크기 및 레이어 사이즈 설정 language_model = LanguageModel(dictionary, is_forward_lm, hidden_size=128, nlayers=1) -# train your language model +# 언어 모델 훈련 trainer = LanguageModelTrainer(language_model, corpus) trainer.train('resources/taggers/language_model', sequence_length=10, @@ -71,9 +71,9 @@ LM을 학습하면 임베딩으로 사용하기 쉽습니다. 모델을 `FlairEm ```python sentence = Sentence('I love Berlin') -# init embeddings from your trained LM +# 훈련된 LM에서 임베딩 초기화 char_lm_embeddings = FlairEmbeddings('resources/taggers/language_model/best-lm.pt') -# embed sentence +# 임베딩된 문장 char_lm_embeddings.embed(sentence) ``` @@ -85,10 +85,10 @@ char_lm_embeddings.embed(sentence) 아랍어나 일본어와 같은 비라틴어 알파벳을 사용하는 언어에 대한 임베딩을 훈련하는 경우 먼저 고유한 문자 사전을 만들어야 합니다. 다음 코드로 이 작업을 수행할 수 있습니다: ```python -# make an empty character dictionary +# 빈 문자 사전 만들기 from flair.data import Dictionary char_dictionary: Dictionary = Dictionary() -# counter object +# counter 오브젝트 import collections counter = collections.Counter() processed = 0 @@ -103,9 +103,9 @@ for file in files: processed += 1 chars = list(line) tokens += len(chars) - # Add chars to the dictionary + # 사전에 문자 추가 counter.update(chars) - # comment this line in to speed things up (if the corpus is too large) + # 속도를 높이려면 이 줄을 주석 처리하세요. (말뭉치가 너무 큰 경우) # if tokens > 50000000: break # break total_count = 0 @@ -118,7 +118,7 @@ idx = 0 for letter, count in counter.most_common(): sum += count percentile = (sum / total_count) - # comment this line in to use only top X percentile of chars, otherwise filter later + # 문자의 상위 X 백분위수만 사용하려면 이 줄에 주석을 달고, 그렇지 않으면 나중에 필터링하세요. # if percentile < 0.00001: break char_dictionary.add_item(letter) idx += 1 @@ -158,18 +158,18 @@ dictionary = Dictionary.load_from_file('/path/to/your_char_mappings') from flair.data import Dictionary from flair.embeddings import FlairEmbeddings from flair.trainers.language_model_trainer import LanguageModelTrainer, TextCorpus -# instantiate an existing LM, such as one from the FlairEmbeddings +# FlairEmbeddings와 같은 기존 LM 인스턴스화 language_model = FlairEmbeddings('news-forward').lm -# are you fine-tuning a forward or backward LM? +# 앞으로 또는 뒤로 LM을 미세 조정하고 있나요? is_forward_lm = language_model.is_forward_lm -# get the dictionary from the existing language model +# 기존 언어 모델에서 사전 가져오기 dictionary: Dictionary = language_model.dictionary -# get your corpus, process forward and at the character level +# 당신의 말뭉치를 가져와서, 앞으로 그리고 문자 레벨에서 진행하세요. corpus = TextCorpus('path/to/your/corpus', dictionary, is_forward_lm, character_level=True) -# use the model trainer to fine-tune this model on your corpus +# 모델 트레이너를 사용하여 코퍼스에서 이 모델을 미세 조정하세요. trainer = LanguageModelTrainer(language_model, corpus) trainer.train('resources/taggers/language_model', sequence_length=100, From 141db1331f6eb16acc3fe98077e842d3801f5cd4 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 14:10:34 +0900 Subject: [PATCH 14/20] Update TUTORIAL_7_TRAINING_A_MODEL.md --- resources/docs/KOR_docs/TUTORIAL_7_TRAINING_A_MODEL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_7_TRAINING_A_MODEL.md b/resources/docs/KOR_docs/TUTORIAL_7_TRAINING_A_MODEL.md index f196a1b641..98a57dc5a6 100644 --- a/resources/docs/KOR_docs/TUTORIAL_7_TRAINING_A_MODEL.md +++ b/resources/docs/KOR_docs/TUTORIAL_7_TRAINING_A_MODEL.md @@ -1,4 +1,4 @@ -# Tutorial 7: Training a Model +# 튜토리얼 7: 모델 훈련하기 튜토리얼 7에서는 최첨단 word embedding을 사용하여 여러분의 시퀀스 레이블링(sequence labeling)과 텍스트 분류(text classification) 모델을 훈련하는 방법을 살펴볼 것입니다. From 327ba8c6dacc791ff43f187c945c2cde48826ece Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 14:11:00 +0900 Subject: [PATCH 15/20] Update TUTORIAL_8_MODEL_OPTIMIZATION.md --- resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md b/resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md index 528df15ce0..e9d890b3a0 100644 --- a/resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md +++ b/resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md @@ -1,4 +1,4 @@ -# Tutorial 8: 모델 튜닝 +# 튜토리얼 8: 모델 튜닝 튜토리얼 8에서는 올바른 모델 및 하이퍼 매개변수 셋을 선택하여 모델의 품질을 향상시킬 수 있는 방법을 살펴볼 것입니다. From cf9bcd4c68501f2ed4ed87a356d9d07f3621f4c8 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 14:11:28 +0900 Subject: [PATCH 16/20] Update TUTORIAL_9_TRAINING_LM_EMBEDDINGS.md --- resources/docs/KOR_docs/TUTORIAL_9_TRAINING_LM_EMBEDDINGS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_9_TRAINING_LM_EMBEDDINGS.md b/resources/docs/KOR_docs/TUTORIAL_9_TRAINING_LM_EMBEDDINGS.md index b30d009866..fb99f3a173 100644 --- a/resources/docs/KOR_docs/TUTORIAL_9_TRAINING_LM_EMBEDDINGS.md +++ b/resources/docs/KOR_docs/TUTORIAL_9_TRAINING_LM_EMBEDDINGS.md @@ -1,4 +1,4 @@ -# Tutorial 9: 여러분만의 Flair 임베딩을 훈련하세요! +# 튜토리얼 9: 여러분만의 Flair 임베딩을 훈련하세요! Flair 임베딩은 Flair의 비밀 소스이며, 이를 통해 다양한 NLP 작업에서 최첨단 정확도를 달성할 수 있습니다. 이 튜토리얼에서는 자신만의 Flair 임베딩을 훈련하는 방법을 알려줄 것입니다. 이는 Flair를 새로운 언어나 도메인에 적용하려는 경우에 유용할 수 있습니다. From 5f956f9890d46243481c8d337d99833342441ad5 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 14:23:42 +0900 Subject: [PATCH 17/20] Added Korean translation of code comments --- .../TUTORIAL_10_TRAINING_ZERO_SHOT_MODEL.md | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_10_TRAINING_ZERO_SHOT_MODEL.md b/resources/docs/KOR_docs/TUTORIAL_10_TRAINING_ZERO_SHOT_MODEL.md index d18a313a1e..75ae65a95c 100644 --- a/resources/docs/KOR_docs/TUTORIAL_10_TRAINING_ZERO_SHOT_MODEL.md +++ b/resources/docs/KOR_docs/TUTORIAL_10_TRAINING_ZERO_SHOT_MODEL.md @@ -1,4 +1,4 @@ -# Tutorial 10: Few-Shot과 Zero-Shot 분류 (TARS) +# 튜토리얼 10: Few-Shot과 Zero-Shot 분류 (TARS) TARS(Task-aware representation of sentence)는 [Halder et al. (2020)](https://kishaloyhalder.github.io/pdfs/tars_coling2020.pdf)이 **텍스트 분류를 위한 퓨샷 및 제로샷 학습**을 위한 간단하고 효과적인 방법으로 도입했습니다. 이것은 훈련 예제 없이도 텍스트를 분류할 수 있음을 의미합니다. @@ -7,7 +7,7 @@ TARS(Task-aware representation of sentence)는 [Halder et al. (2020)](https://ki 이번 튜토리얼에서는 TARS를 사용하는 다양한 방법을 보여줄 것입니다: -## Use Case #1: 훈련 데이터 없이 텍스트 분류(Zero-Shot) +## 사용 사례 #1: 훈련 데이터 없이 텍스트 분류(Zero-Shot) 때로 우리는 해결하려는 텍스트 분류 작업에 대한 훈련 데이터가 없을 때가 있습니다. 이 경우 기본 TARS 모델을 로드하고 제로샷 예측을 수행할 수 있습니다. 즉, TARS의 `predict_zero_shot` 방법을 사용하고 레이블 이름 목록을 제공하는 것입니다. 그런 다음 TARS는 이러한 레이블 중 하나를 텍스트와 일치시키려고 시도할 것입니다. @@ -18,15 +18,15 @@ TARS(Task-aware representation of sentence)는 [Halder et al. (2020)](https://ki ```python from flair.models import TARSClassifier from flair.data import Sentence -# 1. Load our pre-trained TARS model for English +# 1. 영어로 사전 훈련된 TARS 모델 로드 tars = TARSClassifier.load('tars-base') -# 2. Prepare a test sentence +# 2. 테스트 문장 준비 sentence = Sentence("I am so glad you liked it!") -# 3. Define some classes that you want to predict using descriptive names +# 3. 서술적인 이름을 사용하여 예측하려는 일부 클래스 정의 classes = ["happy", "sad"] -#4. Predict for these classes +# 4. 이 클래스들에 대한 예측 tars.predict_zero_shot(sentence, classes) -# Print sentence with predicted labels +# 예측된 레이블이 있는 문장 출력 print(sentence) ``` @@ -40,26 +40,26 @@ Sentence: "I am so glad you liked it !" [− Tokens: 8 − Sentence-Labels: { 다른 라벨과 함께 사용해 보세요! 제로샷 예측은 때때로 (*항상 그런 것은 아니지만*) 매우 잘 작동합니다. -## Use Case #2: TARS를 사용한 제로샷 NER(Named Entity Recognition) +## 사용 사례 #2: TARS를 사용한 제로샷 NER(Named Entity Recognition) TARS 제로샷 학습 접근 방식을 시퀀스 라벨링으로 확장하고 영어 NER에 대해 사전 훈련된 모델을 제공합니다. 일부 클래스를 정의하고 모델이 클래스를 찾을 수 있는지 확인하세요: ```python from flair.models import TARSTagger from flair.data import Sentence -# 1. Load zero-shot NER tagger +# 1. 제로샷 NER tagger 로드 tars = TARSTagger.load('tars-ner') -# 2. Prepare some test sentences +# 2. 테스트 문장 준비 sentences = [ Sentence("The Humboldt University of Berlin is situated near the Spree in Berlin, Germany"), Sentence("Bayern Munich played against Real Madrid"), Sentence("I flew with an Airbus A380 to Peru to pick up my Porsche Cayenne"), Sentence("Game of Thrones is my favorite series"), ] -# 3. Define some classes of named entities such as "soccer teams", "TV shows" and "rivers" +# 3. "축구팀", "TV 프로그램" 및 "강"과 같은 명명된 엔터티의 일부 클래스 정의 labels = ["Soccer Team", "University", "Vehicle", "River", "City", "Country", "Person", "Movie", "TV Show"] tars.add_and_switch_to_new_task('task 1', labels, label_type='ner') -# 4. Predict for these classes and print results +# 4. 이 클래스에 대한 예측 및 결과 출력 for sentence in sentences: tars.predict(sentence) print(sentence.to_tagged_string("ner")) @@ -82,7 +82,7 @@ Game of Thrones is my favorite series "soccer team" (_Bayern Munich_ and _Real Madrid_) 및 "river" (_Spree_) 와 같은 엔터티 클래스를 찾고 있습니다. 이는 진행중인 연구이며 예제는 약간 cherry-picked 된 것입니다. 제로샷 모델은 다음 릴리스까지 상당히 개선될 것으로 기대합니다. -## Use Case #3: TARS 모델 학습 +## 사용 사례 #3: TARS 모델 학습 또한 처음부터 또는 제공된 TARS 모델을 시작점으로 사용하여 고유한 TARS 모델을 훈련할 수 있습니다. 후자를 선택한 경우 새 작업을 훈련하는 데 필요한 훈련 데이터가 거의 없을 수 있습니다. @@ -98,7 +98,7 @@ from flair.data import Corpus from flair.datasets import TREC_6 from flair.models import TARSClassifier from flair.trainers import ModelTrainer -# 1. define label names in natural language since some datasets come with cryptic set of labels +# 1. 일부 데이터 세트에는 수수께끼의 레이블 세트가 제공되므로 자연어로 레이블 이름을 정의하십시오. label_name_map = {'ENTY': 'question about entity', 'DESC': 'question about description', 'ABBR': 'question about abbreviation', @@ -106,24 +106,24 @@ label_name_map = {'ENTY': 'question about entity', 'NUM': 'question about number', 'LOC': 'question about location' } -# 2. get the corpus +# 2. 말뭉치 가져오기 corpus: Corpus = TREC_6(label_name_map=label_name_map) -# 3. what label do you want to predict? +# 3. 어떤 레이블을 예측할 것인가요? label_type = 'question_class' -# 4. make a label dictionary +# 4. 레이블 사전 만들기 label_dict = corpus.make_label_dictionary(label_type=label_type) -# 5. start from our existing TARS base model for English +# 5. 영어용 기존 TARS 기본 모델에서 시작 tars = TARSClassifier.load("tars-base") -# 5a: alternatively, comment out previous line and comment in next line to train a new TARS model from scratch instead +# 5a: 또는 이전 줄에 주석을 달고 다음 줄에 주석을 달아 새로운 TARS 모델을 처음부터 훈련시키세요. # tars = TARSClassifier(embeddings="bert-base-uncased") -# 6. switch to a new task (TARS can do multiple tasks so you must define one) +# 6. 새 작업으로 전환 (TAS는 여러 작업을 수행할 수 있으므로 하나를 정의해야 함) tars.add_and_switch_to_new_task(task_name="question classification", label_dictionary=label_dict, label_type=label_type, ) -# 7. initialize the text classifier trainer +# 7. 텍스트 분류기 트레이너 초기화 trainer = ModelTrainer(tars, corpus) -# 8. start the training +# 8. 훈련 시작 trainer.train(base_path='resources/taggers/trec', # path to store the model artifacts learning_rate=0.02, # use very small learning rate mini_batch_size=16, @@ -147,21 +147,21 @@ TARS는 하나 이상의 분류 작업에서 학습하면 퓨샷 및 제로샷 from flair.datasets import GO_EMOTIONS from flair.models import TARSClassifier from flair.trainers import ModelTrainer -# 1. Load the trained model +# 1. 훈련된 모델 로드 tars = TARSClassifier.load('resources/taggers/trec/best-model.pt') -# 2. load a new flair corpus e.g., GO_EMOTIONS, SENTIMENT_140 etc +# 2. GO_EMOTIONS, SENTIMENT_140 등의 새로운 flair 말뭉치 로드 new_corpus = GO_EMOTIONS() -# 3. define label type +# 3. 레이블 유형 정의 label_type = "emotion" -# 4. make a label dictionary +# 4. 레이블 사전 만들기 label_dict = new_corpus.make_label_dictionary(label_type=label_type) -# 5. IMPORTANT: switch to new task +# 5. 중요: 새 작업으로 전환 tars.add_and_switch_to_new_task("GO_EMOTIONS", label_dictionary=label_dict, label_type=label_type) -# 6. initialize the text classifier trainer +# 6. 텍스트 분류기 트레이너 초기화 trainer = ModelTrainer(tars, new_corpus) -# 6. start the training +# 6. 훈련 시작 trainer.train(base_path='resources/taggers/go_emotions', # path to store the model artifacts learning_rate=0.02, # use very small learning rate mini_batch_size=16, @@ -180,14 +180,14 @@ TARS는 레이블 이름과 기본 언어 모델의 텍스트 간의 관계를 이것은 편의를 위해 내부적으로 레이블 집합을 다른 작업으로 그룹화합니다. 사용자는 TARS 모델이 훈련된 기존 작업을 조회한 다음 필요에 따라 그 중 하나로 전환할 수 있습니다. ```python -# 1. Load a pre-trained TARS model +# 1. 사전 훈련된 TARS 모델 로드 tars = TARSClassifier.load('tars-base') -# 2. Check out what datasets it was trained on +# 2. 어떤 데이터 세트에서 학습되었는지 확인하십시오. existing_tasks = tars.list_existing_tasks() print(f"Existing tasks are: {existing_tasks}") -# 3. Switch to a particular task that exists in the above list +# 3. 위 목록에 있는 특정 작업으로 전환 tars.switch_to_task("GO_EMOTIONS") -# 4. Prepare a test sentence +# 4. 테스트 문장 준비하기 sentence = Sentence("I absolutely love this!") tars.predict(sentence) print(sentence) @@ -198,7 +198,7 @@ Existing tasks are: {'AGNews', 'DBPedia', 'IMDB', 'SST', 'TREC_6', 'NEWS_CATEGOR Sentence: "I absolutely love this !" [− Tokens: 5 − Sentence-Labels: {'label': [LOVE (0.9708)]}] ``` -## TARS 사용 시 다음 논문을 인용하십시오: +## TARS 사용 시 다음 논문을 인용하세요: ``` @inproceedings{halder2020coling, From fe4ab0996f65893ea18069c18e474bee48ef26f3 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 14:24:32 +0900 Subject: [PATCH 18/20] Update TUTORIAL_10_TRAINING_ZERO_SHOT_MODEL.md --- .../docs/KOR_docs/TUTORIAL_10_TRAINING_ZERO_SHOT_MODEL.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_10_TRAINING_ZERO_SHOT_MODEL.md b/resources/docs/KOR_docs/TUTORIAL_10_TRAINING_ZERO_SHOT_MODEL.md index 75ae65a95c..65e7f77ade 100644 --- a/resources/docs/KOR_docs/TUTORIAL_10_TRAINING_ZERO_SHOT_MODEL.md +++ b/resources/docs/KOR_docs/TUTORIAL_10_TRAINING_ZERO_SHOT_MODEL.md @@ -26,7 +26,7 @@ sentence = Sentence("I am so glad you liked it!") classes = ["happy", "sad"] # 4. 이 클래스들에 대한 예측 tars.predict_zero_shot(sentence, classes) -# 예측된 레이블이 있는 문장 출력 +# 5. 예측된 레이블이 있는 문장 출력 print(sentence) ``` @@ -161,7 +161,7 @@ tars.add_and_switch_to_new_task("GO_EMOTIONS", label_type=label_type) # 6. 텍스트 분류기 트레이너 초기화 trainer = ModelTrainer(tars, new_corpus) -# 6. 훈련 시작 +# 7. 훈련 시작 trainer.train(base_path='resources/taggers/go_emotions', # path to store the model artifacts learning_rate=0.02, # use very small learning rate mini_batch_size=16, From 27fa4e3baf4f917382cbfc772ecb67435b69c11e Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Sun, 14 Nov 2021 14:26:23 +0900 Subject: [PATCH 19/20] Update README.md --- resources/docs/KOR_docs/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/docs/KOR_docs/README.md b/resources/docs/KOR_docs/README.md index e01e0cf321..3f3c753cb5 100644 --- a/resources/docs/KOR_docs/README.md +++ b/resources/docs/KOR_docs/README.md @@ -108,6 +108,7 @@ Span [3]: "Berlin" [− Labels: LOC (0.9992)] * [Tutorial 7: Training a Model](/resources/docs/KOR_docs/TUTORIAL_7_TRAINING_A_MODEL.md) * [Tutorial 8: Training your own Flair Embeddings](/resources/docs/KOR_docs/TUTORIAL_8_MODEL_OPTIMIZATION.md) * [Tutorial 9: Training a Zero Shot Text Classifier (TARS)](/resources/docs/KOR_docs/TUTORIAL_9_TRAINING_LM_EMBEDDINGS.md) +* [Tutorial 10: Few-Shot and Zero-Shot Classification (TARS)](/resources/docs/KOR_docs/TUTORIAL_10_TRAINING_ZERO_SHOT_MODEL.md) 튜토리얼에서는 기본 NLP 클래스가 작동하는 방법, 사전 훈련된 모델을 로드하여 텍스트에 태그를 지정하는 방법, 다른 단어 또는 문서 임베딩으로 텍스트를 포함하는 방법, 고유한 언어 모델, 시퀀스 레이블링 모델 및 텍스트 분류 모델에 대해 설명하고있습니다. 불분명한 것이 있으면 알려주세요. From fd52f2a7a7c0d5edf7cc947e2c490dc873aeca44 Mon Sep 17 00:00:00 2001 From: luoran852 <62210248+luoran852@users.noreply.github.com> Date: Mon, 15 Nov 2021 19:41:58 +0900 Subject: [PATCH 20/20] Update TUTORIAL_2_TAGGING.md --- resources/docs/KOR_docs/TUTORIAL_2_TAGGING.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/docs/KOR_docs/TUTORIAL_2_TAGGING.md b/resources/docs/KOR_docs/TUTORIAL_2_TAGGING.md index 72e45b6e9b..8fcdd26f02 100644 --- a/resources/docs/KOR_docs/TUTORIAL_2_TAGGING.md +++ b/resources/docs/KOR_docs/TUTORIAL_2_TAGGING.md @@ -269,11 +269,11 @@ George returned to Berlin to return his hat . He had a look at different hats . ``` -우리가 볼 수 있듯이, 프레임 감지기는 문장 1에서 '반환'이라는 단어의 두 가지 다른 의미 사이를 구별한다. -'return.01'은 위치로 돌아가는 것을 의미하고, 'return.02'는 무언가를 돌려주는 것을 의미한다. +우리가 볼 수 있듯이, 프레임 감지기는 문장 1에서 '반환'이라는 단어의 두 가지 다른 의미 사이를 구별합니다. +'return.01'은 위치로 돌아가는 것을 의미하고, 'return.02'는 무언가를 돌려주는 것을 의미합니다. -비슷하게, 문장 2에서 프레임 탐지기는 'have'가 라이트 동사인 경동사 구조를 찾는다. -look은 단어를 연상시키는 틀이다. +비슷하게, 문장 2에서 프레임 탐지기는 'have'가 라이트 동사인 경동사 구조를 찾습니다. +look은 단어를 연상시키는 틀입니다. ### 문장 목록 태그 지정 @@ -356,8 +356,8 @@ POSITION이라는 라벨이 문장에 추가되어 이 문장이 긍정적인 ## 교육 데이터 없이 새 클래스 태그 지정 포함되지 않은 클래스에 레이블을 지정해야 하는 경우 -사전 훈련된 제로샷 분류기 TARS -([제로샷 자습서](/resources/docs/TUTORIAL_10_TRA로 건너뛰기)INING_ZERO_SHOT_MODEL.md)). +사전 훈련된 제로샷 분류기 TARS를 사용해 볼 수도 있습니다. +([제로샷 튜토리얼](/resources/docs/KOR_docs/TUTORIAL_10_TRAINING_ZERO_SHOT_MODEL.md)로 건너뛰기) TARS는 임의 클래스에 대해 텍스트 분류를 수행할 수 있습니다. ## 다음