nlp
-
문제 13. col1.txt와 col2.txt를 병합NLP/NLP100 2021. 1. 4. 18:27
12번 문제에서 만든 col1.txt와 col2.txt를 병합하고, 원래 파일의 1열과 2열을 탭으로 구분하여 텍스트 파일에 저장하시오. 확인을 위해 paste 명령을 사용하시오. import pandas as pd f1 = pd.read_csv("/Users/p1zz4/Downloads/col1.txt", header=None) f2 = pd.read_csv("/Users/p1zz4/Downloads/col2.txt", header=None) df = pd.concat((f1,f2),axis=1) df.to_csv("/Users/p1zz4/Downloads/13.txt", sep='\t',index=False,header=None)
-
문제 11. 탭을 공백으로 변환NLP/NLP100 2021. 1. 4. 18:25
모든 탭을 공백 문자로 변환하시오. 확인을 위해 sed명령어, tr명령어, expand명령어를 사용하시오. datapath = "/Users/p1zz4/Downloads/popular-names.txt" with open(datapath) as p: f = [line.replace("\t", " ").rstrip() for line in p] print(f[:10]) # 전체 출력하느라 오래걸리므로 일부만 출력해서 확인 [확인] - sed (base) P1ZZ4:Downloads p1zz4$ sed "s/\t/ /g" re_popular-names.txt - tr (base) P1ZZ4:Downloads p1zz4$ tr '\tr' ' ' < re_popular-names.txt - expand (bas..
-
문제 06. 집합NLP/NLP100 2021. 1. 4. 18:17
"paraparaparadise"와 "paragraph"에 포함되는 문자 Bigram의 집합을 각각, X와 Y로 구하고, X와 Y의 합집합, 곱집합, 차집합을 구하시오. 그리고, "se"라는 Bigram이 X와 Y 중 어느 집합에 포함되는지 확인하시오. Xs = "paraparaparadise" Ys = "paragraph" def ngram(idx, n): return [idx[i:i+n] for i in range(len(idx)-n+1)] X = set(ngram(Xs,2)) Y = set(ngram(Ys,2)) print(f'union: {X | Y}') #합집합 print(f'intersection: {X & Y}') #교집합 print(f'difference of sets: {X - Y}') ..
-
문제 04. 원소 기호NLP/NLP100 2021. 1. 4. 18:09
Hi He Lied Because Boron Could Not Oxidize Fluorine. New Nations Might Also Sign Peace Security Clause. Arthur King Can 라는 문장을 단어 단위로 분할하고, 1,5,6,7,8,9,15,16,19 번째 단어는 앞글자, 그 밖의 단어는 앞에서 두 글자씩 추출하여 꺼낸 문자열에서 단어의 위치순으로 나열한 배열을 만드시오. def sol(i, word): if i in [1, 5, 6, 7, 8, 9, 15, 16, 19]: return (word[0], i) else: return (word[:2], i) text = 'Hi He Lied Because Boron Could Not Oxidize Fluorine. Ne..
-
문제 03. 원주율NLP/NLP100 2021. 1. 4. 18:08
"Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics." 라는 문장을 단어로 분할하여 각 단어의(알파벳) 글자 수를 앞에서부터 나열한 배열을 만드시오. s = "Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics." s = s.split(' ') s1 = [len(w.rstrip(',.')) for w in s] print(s1) [출력 결과] [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9]
-
NLP100 문제 풀이NLP/NLP100 2021. 1. 4. 17:59
https://nlp100.github.io/ko/about.html 100문제로 두드려 보는 자연어처리에 대하여 NLP 100 Exercise is a workbook designed for learning skills for programming, data analysis, and research activities by taking practical and exciting assignments. nlp100.github.io 총 10개의 챕터로 구성된 자연어처리의 기본을 공부하기 좋은 사이트이다. 1. 준비운동 2. UNIX 명령어 3. 정규표현식 4. 형태소 분석 5. 구문 분석 6. 기계 학습 7. 단어 벡터 8. 신경망 9. RNN과 CNN 10. 기계 번역 원 사이트는 일본 사이트로, 현재 ..