-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from boostcampaitech4lv23nlp2/feat/preprocess
Feat/preprocess add translation and replace
- Loading branch information
Showing
11 changed files
with
227 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ mlflow==2.0.1 | |
streamlit==1.14.1 | ||
seaborn==0.12.0 | ||
ipykernel==6.17.1 | ||
hanja==0.13.3 | ||
numpy==1.19.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from .arguments import DataTrainingArguments, ModelArguments, get_training_args | ||
from .control_mlflow import save_model_remote, set_mlflow_logger | ||
from .get_train_valid_split import get_train_valid_split | ||
from .representation import entity_representation | ||
from .preprocess import replace_symbol | ||
from .representation import representation | ||
from .set_seed import set_seed | ||
from .utils import label_to_num, num_to_label |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import re | ||
|
||
symbol_map = {"\"`'‘‘’“”'ˈ′": "'"} | ||
|
||
|
||
def remove_symbol(): | ||
pass | ||
|
||
|
||
def replace_symbol(sentence): | ||
for key, value in symbol_map.items(): | ||
sentence = re.sub(f"[{key}]", value, sentence) | ||
return sentence | ||
|
||
|
||
def remove_language(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,29 @@ | ||
import unittest | ||
|
||
from src.utils.preprocess import replace_symbol | ||
|
||
class PreprocessTester(unittest.TestCase): | ||
def test_run(self): | ||
pass | ||
test_quote_symbol_map = {"\"`'‘‘’“”'ˈ′": "'"} | ||
test_bracket_symbol_map = {"[[": "<", "]]": ">", "\[《〈「˹「⟪≪<⌜『«": "<", "\]》〉」˼」⟫≫>⌟»": ">", "({": "(", ")}": ")"} | ||
test_sentences = [ | ||
"비틀즈 [SEP] 조지 해리슨 [SEP] 〈Something〉는 조지 해리슨이 쓰고 비틀즈가 1969년 앨범 《Abbey Road》에 담은 노래다.{}", | ||
] | ||
|
||
test_quote_answers = [ | ||
"비틀즈 [SEP] 조지 해리슨 [SEP] 〈Something〉는 조지 해리슨이 쓰고 비틀즈가 1969년 앨범 《Abbey Road》에 담은 노래다.{}", | ||
] | ||
|
||
def test_chinese(self): | ||
pass | ||
test_bracket_answers = [ | ||
"비틀즈 [SEP] 조지 해리슨 [SEP] <Something>는 조지 해리슨이 쓰고 비틀즈가 1969년 앨범 <Abbey Road>에 담은 노래다.()", | ||
] | ||
|
||
def test_japanese(self): | ||
pass | ||
|
||
def test_etc_language(self): | ||
pass | ||
class PreprocessTester(unittest.TestCase): | ||
def test_replace_symbol(self): | ||
for sentence, answer in zip(test_sentences, test_quote_answers): | ||
generate_sentence = replace_symbol(sentence, test_quote_symbol_map) | ||
self.assertEqual(generate_sentence, answer) | ||
|
||
def test_korean(self): | ||
pass | ||
def test_bracket_symbol(self): | ||
for sentence, answer in zip(test_sentences, test_bracket_answers): | ||
generate_sentence = replace_symbol(sentence, test_bracket_symbol_map) | ||
self.assertEqual(generate_sentence, answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import unittest | ||
|
||
from src.utils.representation import representation | ||
|
||
test_objects = [ | ||
[ | ||
"〈Something〉는 조지 해리슨이 쓰고 비틀즈가 1969년 앨범 《Abbey Road》에 담은 노래다.", | ||
"{'word': '비틀즈', 'start_idx': 24, 'end_idx': 26, 'type': 'ORG'}", | ||
"{'word': '조지 해리슨', 'start_idx': 13, 'end_idx': 18, 'type': 'PER'}", | ||
], | ||
[ | ||
"K리그2에서 성적 1위를 달리고 있는 광주FC는 지난 26일 한국프로축구연맹으로부터 관중 유치 성과와 마케팅 성과를 인정받아 ‘풀 스타디움상’과 ‘플러스 스타디움상’을 수상했다.", | ||
"{'word': '광주FC', 'start_idx': 21, 'end_idx': 24, 'type': 'ORG'}", | ||
"{'word': '한국프로축구연맹', 'start_idx': 34, 'end_idx': 41, 'type': 'ORG'}", | ||
], | ||
[ | ||
"백한성(白漢成, 水原鶴人, 1899년 6월 15일 조선 충청도 공주 출생 ~ 1971년 10월 13일 대한민국 서울에서 별세.)은 대한민국의 정치가이며 법조인이다.", | ||
"{'word': '백한성', 'start_idx': 0, 'end_idx': 2, 'type': 'PER'}", | ||
"{'word': '조선 충청도 공주', 'start_idx': 28, 'end_idx': 36, 'type': 'LOC'}", | ||
], | ||
[ | ||
"KBS 전주방송총국(KBS 全州放送總局)은 전라북도 지역을 대상으로 하는 한국방송공사의 지역 방송 총국이다.", | ||
"{'word': 'KBS 전주방송총국', 'start_idx': 0, 'end_idx': 9, 'type': 'ORG'}", | ||
"{'word': 'KBS 全州放送總局', 'start_idx': 11, 'end_idx': 20, 'type': 'ORG'}", | ||
], | ||
] | ||
|
||
none_answers = [ | ||
"비틀즈 [SEP] 조지 해리슨 [SEP] 〈Something〉는 조지 해리슨이 쓰고 비틀즈가 1969년 앨범 《Abbey Road》에 담은 노래다.", | ||
"광주FC [SEP] 한국프로축구연맹 [SEP] K리그2에서 성적 1위를 달리고 있는 광주FC는 지난 26일 한국프로축구연맹으로부터 관중 유치 성과와 마케팅 성과를 인정받아 ‘풀 스타디움상’과 ‘플러스 스타디움상’을 수상했다.", | ||
"백한성 [SEP] 조선 충청도 공주 [SEP] 백한성(白漢成, 水原鶴人, 1899년 6월 15일 조선 충청도 공주 출생 ~ 1971년 10월 13일 대한민국 서울에서 별세.)은 대한민국의 정치가이며 법조인이다.", | ||
"KBS 전주방송총국 [SEP] KBS 全州放送總局 [SEP] KBS 전주방송총국(KBS 全州放送總局)은 전라북도 지역을 대상으로 하는 한국방송공사의 지역 방송 총국이다.", | ||
] | ||
|
||
|
||
chinese_answers = [ | ||
"비틀즈 [SEP] 조지 해리슨 [SEP] 〈Something〉는 조지 해리슨이 쓰고 비틀즈가 1969년 앨범 《Abbey Road》에 담은 노래다.", | ||
"광주FC [SEP] 한국프로축구연맹 [SEP] K리그2에서 성적 1위를 달리고 있는 광주FC는 지난 26일 한국프로축구연맹으로부터 관중 유치 성과와 마케팅 성과를 인정받아 ‘풀 스타디움상’과 ‘플러스 스타디움상’을 수상했다.", | ||
"백한성 [SEP] 조선 충청도 공주 [SEP] 백한성(백한성, 수원학인, 1899년 6월 15일 조선 충청도 공주 출생 ~ 1971년 10월 13일 대한민국 서울에서 별세.)은 대한민국의 정치가이며 법조인이다.", | ||
"KBS 전주방송총국 [SEP] KBS 전주방송총국 [SEP] KBS 전주방송총국(KBS 전주방송총국)은 전라북도 지역을 대상으로 하는 한국방송공사의 지역 방송 총국이다.", | ||
] | ||
|
||
replace_symbole_answers = [ | ||
"비틀즈 [SEP] 조지 해리슨 [SEP] 〈Something〉는 조지 해리슨이 쓰고 비틀즈가 1969년 앨범 《Abbey Road》에 담은 노래다.", | ||
"광주FC [SEP] 한국프로축구연맹 [SEP] K리그2에서 성적 1위를 달리고 있는 광주FC는 지난 26일 한국프로축구연맹으로부터 관중 유치 성과와 마케팅 성과를 인정받아 ‘풀 스타디움상’과 ‘플러스 스타디움상’을 수상했다.", | ||
"백한성 [SEP] 조선 충청도 공주 [SEP] 백한성(白漢成, 水原鶴人, 1899년 6월 15일 조선 충청도 공주 출생 ~ 1971년 10월 13일 대한민국 서울에서 별세.)은 대한민국의 정치가이며 법조인이다.", | ||
"KBS 전주방송총국 [SEP] KBS 全州放送總局 [SEP] KBS 전주방송총국(KBS 全州放送總局)은 전라북도 지역을 대상으로 하는 한국방송공사의 지역 방송 총국이다.", | ||
] | ||
|
||
|
||
class RepresentationTester(unittest.TestCase): | ||
def test_none(self): | ||
for example_object, answer in zip(test_objects, none_answers): | ||
sentence, subject, object = example_object | ||
generate_text = representation(subject, object, sentence, entity_method=None) | ||
self.assertEqual(generate_text, answer) | ||
|
||
def test_chinese(self): | ||
for example_object, answer in zip(test_objects, chinese_answers): | ||
sentence, subject, object = example_object | ||
generate_text = representation( | ||
subject, object, sentence, entity_method=None, translation_methods=["chinese"] | ||
) | ||
self.assertEqual(generate_text, answer) | ||
|
||
def test_replace(self): | ||
for example_object, answer in zip(test_objects, replace_symbole_answers): | ||
sentence, subject, object = example_object | ||
generate_text = representation( | ||
subject, object, sentence, entity_method=None, translation_methods=[None], is_replace=False | ||
) | ||
self.assertEqual(generate_text, answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import unittest | ||
|
||
from src.utils.representation import translation | ||
|
||
test_sentences = [ | ||
"백한성(白漢成, 水原鶴人, 1899년 6월 15일 조선 충청도 공주 출생 ~ 1971년 10월 13일 대한민국 서울에서 별세.)은 대한민국의 정치가이며 법조인이다.", | ||
'1904년 7월 1일, ""툰-운트 스포트버라인 바이어 04 레버쿠젠"" (Turn- und Spielverein Bayer 04 Leverkusen)의 이름으로 창단되었다.', | ||
"헌강왕(憲康王, ~ 886년, 재위: 875년 ~ 886년)은 신라의 제49대 왕이다.", | ||
"쇼니 씨(少弐氏)의 8대 당주로 쇼니 요리히사(少弐頼尚)의 둘째 아들이다.", | ||
"버턴 릭터(Burton Richter, 1931년 3월 22일 ~ 2018년 7월 18일)는 노벨 물리학상을 받은 미국의 물리학자이다.", | ||
"유한굉(劉漢宏, Liu Hanhong, ~ 887년)은 중국 당나라 말기에 활약했던 군벌로, 당초에는 당나라에 반기를 들었으나, 후에 당나라의 관직을 받고 의승군 절도사(義勝軍節度使, 본거지는 지금의 저장 성 사오싱 시)로서 절강 동부 일대를 지배하였다.", | ||
] | ||
|
||
chiense_sentences = [ | ||
"백한성(백한성, 수원학인, 1899년 6월 15일 조선 충청도 공주 출생 ~ 1971년 10월 13일 대한민국 서울에서 별세.)은 대한민국의 정치가이며 법조인이다.", | ||
'1904년 7월 1일, ""툰-운트 스포트버라인 바이어 04 레버쿠젠"" (Turn- und Spielverein Bayer 04 Leverkusen)의 이름으로 창단되었다.', | ||
"헌강왕(헌강왕, ~ 886년, 재위: 875년 ~ 886년)은 신라의 제49대 왕이다.", | ||
"쇼니 씨(소이씨)의 8대 당주로 쇼니 요리히사(소이뢰상)의 둘째 아들이다.", | ||
"버턴 릭터(Burton Richter, 1931년 3월 22일 ~ 2018년 7월 18일)는 노벨 물리학상을 받은 미국의 물리학자이다.", | ||
"유한굉(유한굉, Liu Hanhong, ~ 887년)은 중국 당나라 말기에 활약했던 군벌로, 당초에는 당나라에 반기를 들었으나, 후에 당나라의 관직을 받고 의승군 절도사(의승군절도사, 본거지는 지금의 저장 성 사오싱 시)로서 절강 동부 일대를 지배하였다.", | ||
] | ||
|
||
|
||
class TranlsationTester(unittest.TestCase): | ||
def test_run(self): | ||
pass | ||
|
||
def test_chinese(self): | ||
for sentence, answer in zip(test_sentences, chiense_sentences): | ||
translation_sentence = translation(sentence, method="chinese") | ||
self.assertEqual(translation_sentence, answer) |