{user_name} commited on
Commit ·
b1a244b
1
Parent(s): 8abf10e
rag 다시 활성화
Browse files- Document/Knowledge.md +48 -0
- rag.py +51 -39
- requirements.txt +153 -3
Document/Knowledge.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ONNX 런타임
|
| 2 |
+
* [GitHub 링크](https://github.com/microsoft/onnxruntime)
|
| 3 |
+
|
| 4 |
+
ONNX 런타임 추론은 PyTorch 및 TensorFlow/Keras와 같은 딥 러닝 프레임워크와 scikit-learn, LightGBM, XGBoost 등과 같은 기존 기계 학습 라이브러리의 모델을 지원하여 더 빠른 고객 경험과 더 낮은 비용을 가능하게 할 수 있습니다. ONNX 런타임은 다양한 하드웨어, 드라이버 및 운영 체제와 호환되며, 그래프 최적화 및 변환과 함께 해당하는 경우 하드웨어 가속기를 활용하여 최적의 성능을 제공합니다.
|
| 5 |
+
|
| 6 |
+
다음은 주어진 내용을 마크다운 형식으로 정리한 것입니다:
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# TODO
|
| 11 |
+
|
| 12 |
+
## 전공 지식 공부하기
|
| 13 |
+
- 논문 읽고 구현하며 기초를 다지기
|
| 14 |
+
- 전공 지식 커리큘럼 따라 배우기
|
| 15 |
+
|
| 16 |
+
## 인공지능 프로그래밍 쪽 준비
|
| 17 |
+
- 자료구조, 알고리즘
|
| 18 |
+
- 알고리즘 + 코딩 테스트
|
| 19 |
+
- Python 등...
|
| 20 |
+
|
| 21 |
+
## 포트폴리오
|
| 22 |
+
- 가능한 안 만들고 포트폴리오를 만드는 방향
|
| 23 |
+
|
| 24 |
+
출처: [https://f-lab.kr/insight/becoming-an-ai-developer](https://f-lab.kr/insight/becoming-an-ai-developer)
|
| 25 |
+
|
| 26 |
+
## 온라인 코스, 대학원 과정, 실무 경험으로 배우는 방법
|
| 27 |
+
- 대학원 과정은 보다 심도 있는 학습을 원하는 사람들에게 적합
|
| 28 |
+
- 실무 경험을 통해 이론적 지식을 실제 프로젝트에 적용해 볼 수 있음
|
| 29 |
+
- GitHub, Kaggle과 같은 플랫폼에서는 다양한 AI 프로젝트에 참여해볼 수 있음
|
| 30 |
+
|
| 31 |
+
## 네트워킹과 커뮤니티 참여를 통해
|
| 32 |
+
- AI 관련 컨퍼런스, 워크샵, 해커톤 등에 참여하여
|
| 33 |
+
- 최신 기술 동향을 파악하고
|
| 34 |
+
- 업계 전문가와 교류하는 것이 좋음
|
| 35 |
+
|
| 36 |
+
## 프로그래밍 언어
|
| 37 |
+
- Python
|
| 38 |
+
|
| 39 |
+
## 수학 및 통계학
|
| 40 |
+
- 선형대수학, 확률론, 미적분학 등
|
| 41 |
+
|
| 42 |
+
## 기계 학습(ML)
|
| 43 |
+
- 딥러닝
|
| 44 |
+
- 인공지능 관련 알고리즘 숙지 및 실제 프로젝트에 적용해보기
|
| 45 |
+
- 자연어 처리(NLP), 컴퓨터 비전 등 특정 분야에 대한 전문 지식
|
| 46 |
+
|
| 47 |
+
## 기타
|
| 48 |
+
- 끊임없이 발전하고 있으므로, 최신 기술 동향을 지속적으로 학습하는 자세도 중요
|
rag.py
CHANGED
|
@@ -1,40 +1,52 @@
|
|
| 1 |
-
#
|
| 2 |
-
#
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
#
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
#
|
| 30 |
-
#
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
#
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
################
|
| 2 |
+
# PDF 파일을 로드하고 문서를 쪼개서 문서벡터화 한 후 질의하기
|
| 3 |
+
################
|
| 4 |
+
import tiktoken
|
| 5 |
+
tokenizer = tiktoken.get_encoding('cl100k_base')
|
| 6 |
+
def tiktoken_len(text):
|
| 7 |
+
tokens = tokenizer.encode(text)
|
| 8 |
+
return len(tokens)
|
| 9 |
|
| 10 |
+
from langchain.embeddings.sentence_transformer import SentenceTransformerEmbeddings
|
| 11 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 12 |
+
from langchain.document_loaders import UnstructuredMarkdownLoader
|
| 13 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 14 |
+
from langchain_community.vectorstores.utils import filter_complex_metadata
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
## pdf 파일로드 하고 쪼개기
|
| 18 |
+
# https://python.langchain.com/v0.2/docs/how_to/document_loader_markdown/
|
| 19 |
+
|
| 20 |
+
# 마크다운 파일을 로드하고 분할
|
| 21 |
+
loader = UnstructuredMarkdownLoader('Document/Knowledge.md', mode="elements")
|
| 22 |
+
pages = loader.load_and_split()
|
| 23 |
+
|
| 24 |
+
# 텍스트를 청크로 분할
|
| 25 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=80, length_function=tiktoken_len)
|
| 26 |
+
sourceDocs = text_splitter.split_documents(pages)
|
| 27 |
+
sourceDocs = filter_complex_metadata(sourceDocs)
|
| 28 |
+
|
| 29 |
+
################
|
| 30 |
+
# HuggingFace 모델로 문서벡터화 후 유사도 탐색
|
| 31 |
+
################
|
| 32 |
+
from langchain.vectorstores import Chroma
|
| 33 |
+
|
| 34 |
+
model_huggingface = HuggingFaceEmbeddings(model_name = 'jhgan/ko-sroberta-multitask',
|
| 35 |
+
model_kwargs = {'device':'cpu'},
|
| 36 |
+
encode_kwargs = {'normalize_embeddings' : True})
|
| 37 |
+
|
| 38 |
+
## Chroma 기반 pdf(docs 벡터화)
|
| 39 |
+
db = Chroma.from_documents(sourceDocs, model_huggingface)
|
| 40 |
+
|
| 41 |
+
## 질의하기
|
| 42 |
+
def SearchDocs(question, k=1):
|
| 43 |
+
results = db.similarity_search_with_relevance_scores(question, k = k)
|
| 44 |
+
merged = ''
|
| 45 |
+
for result in results:
|
| 46 |
+
merged += '\n\n' + result[0].page_content
|
| 47 |
+
return merged
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
# # 질의 테스트
|
| 51 |
+
# question = "자연어 처리란 무엇인가요?"
|
| 52 |
+
# print(SearchDocs(question, k=1))
|
requirements.txt
CHANGED
|
@@ -1,4 +1,154 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
tiktoken==0.7.0
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
aiohttp==3.9.5
|
| 2 |
+
aiosignal==1.3.1
|
| 3 |
+
annotated-types==0.7.0
|
| 4 |
+
anyio==4.4.0
|
| 5 |
+
asgiref==3.8.1
|
| 6 |
+
async-timeout==4.0.3
|
| 7 |
+
attrs==23.2.0
|
| 8 |
+
backoff==2.2.1
|
| 9 |
+
bcrypt==4.1.3
|
| 10 |
+
beautifulsoup4==4.12.3
|
| 11 |
+
build==1.2.1
|
| 12 |
+
cachetools==5.3.3
|
| 13 |
+
certifi==2024.6.2
|
| 14 |
+
chardet==5.2.0
|
| 15 |
+
charset-normalizer==3.3.2
|
| 16 |
+
chroma-hnswlib==0.7.3
|
| 17 |
+
chromadb==0.5.3
|
| 18 |
+
click==8.1.7
|
| 19 |
+
colorama==0.4.6
|
| 20 |
+
coloredlogs==15.0.1
|
| 21 |
+
dataclasses-json==0.6.7
|
| 22 |
+
deepdiff==7.0.1
|
| 23 |
+
Deprecated==1.2.14
|
| 24 |
+
dnspython==2.6.1
|
| 25 |
+
email_validator==2.2.0
|
| 26 |
+
emoji==2.12.1
|
| 27 |
+
exceptiongroup==1.2.1
|
| 28 |
+
fastapi==0.111.0
|
| 29 |
+
fastapi-cli==0.0.4
|
| 30 |
+
filelock==3.15.4
|
| 31 |
+
filetype==1.2.0
|
| 32 |
+
flatbuffers==24.3.25
|
| 33 |
+
frozenlist==1.4.1
|
| 34 |
+
fsspec==2024.6.0
|
| 35 |
+
google-auth==2.30.0
|
| 36 |
+
googleapis-common-protos==1.63.1
|
| 37 |
+
graphlib_backport==1.1.0
|
| 38 |
+
greenlet==3.0.3
|
| 39 |
+
grpcio==1.64.1
|
| 40 |
+
h11==0.14.0
|
| 41 |
+
httpcore==1.0.5
|
| 42 |
+
httptools==0.6.1
|
| 43 |
+
httpx==0.27.0
|
| 44 |
+
huggingface-hub==0.23.4
|
| 45 |
+
humanfriendly==10.0
|
| 46 |
+
idna==3.7
|
| 47 |
+
importlib_metadata==7.1.0
|
| 48 |
+
importlib_resources==6.4.0
|
| 49 |
+
intel-openmp==2021.4.0
|
| 50 |
+
Jinja2==3.1.4
|
| 51 |
+
joblib==1.4.2
|
| 52 |
+
jsonpatch==1.33
|
| 53 |
+
jsonpath-python==1.0.6
|
| 54 |
+
jsonpointer==3.0.0
|
| 55 |
+
kubernetes==30.1.0
|
| 56 |
+
langchain==0.2.5
|
| 57 |
+
langchain-community==0.2.5
|
| 58 |
+
langchain-core==0.2.9
|
| 59 |
+
langchain-huggingface==0.0.3
|
| 60 |
+
langchain-text-splitters==0.2.1
|
| 61 |
+
langdetect==1.0.9
|
| 62 |
+
langsmith==0.1.81
|
| 63 |
+
lxml==5.2.2
|
| 64 |
+
Markdown==3.6
|
| 65 |
+
markdown-it-py==3.0.0
|
| 66 |
+
MarkupSafe==2.1.5
|
| 67 |
+
marshmallow==3.21.3
|
| 68 |
+
mdurl==0.1.2
|
| 69 |
+
mkl==2021.4.0
|
| 70 |
+
mmh3==4.1.0
|
| 71 |
+
monotonic==1.6
|
| 72 |
+
mpmath==1.3.0
|
| 73 |
+
multidict==6.0.5
|
| 74 |
+
mypy-extensions==1.0.0
|
| 75 |
+
nest-asyncio==1.6.0
|
| 76 |
+
networkx==3.1
|
| 77 |
+
nltk==3.8.1
|
| 78 |
+
numpy==1.24.4
|
| 79 |
+
oauthlib==3.2.2
|
| 80 |
+
onnxruntime==1.18.0
|
| 81 |
+
opentelemetry-api==1.25.0
|
| 82 |
+
opentelemetry-exporter-otlp-proto-common==1.25.0
|
| 83 |
+
opentelemetry-exporter-otlp-proto-grpc==1.25.0
|
| 84 |
+
opentelemetry-instrumentation==0.46b0
|
| 85 |
+
opentelemetry-instrumentation-asgi==0.46b0
|
| 86 |
+
opentelemetry-instrumentation-fastapi==0.46b0
|
| 87 |
+
opentelemetry-proto==1.25.0
|
| 88 |
+
opentelemetry-sdk==1.25.0
|
| 89 |
+
opentelemetry-semantic-conventions==0.46b0
|
| 90 |
+
opentelemetry-util-http==0.46b0
|
| 91 |
+
ordered-set==4.1.0
|
| 92 |
+
orjson==3.10.5
|
| 93 |
+
overrides==7.7.0
|
| 94 |
+
packaging==24.1
|
| 95 |
+
pillow==10.3.0
|
| 96 |
+
posthog==3.5.0
|
| 97 |
+
protobuf==4.25.3
|
| 98 |
+
pyasn1==0.6.0
|
| 99 |
+
pyasn1_modules==0.4.0
|
| 100 |
+
pydantic==2.7.4
|
| 101 |
+
pydantic_core==2.18.4
|
| 102 |
+
Pygments==2.18.0
|
| 103 |
+
pypdf==4.2.0
|
| 104 |
+
PyPika==0.48.9
|
| 105 |
+
pyproject_hooks==1.1.0
|
| 106 |
+
pyreadline3==3.4.1
|
| 107 |
+
python-dateutil==2.9.0.post0
|
| 108 |
+
python-dotenv==1.0.1
|
| 109 |
+
python-iso639==2024.4.27
|
| 110 |
+
python-magic==0.4.27
|
| 111 |
+
python-multipart==0.0.9
|
| 112 |
+
PyYAML==6.0.1
|
| 113 |
+
rapidfuzz==3.9.3
|
| 114 |
+
regex==2024.5.15
|
| 115 |
+
requests==2.32.3
|
| 116 |
+
requests-oauthlib==2.0.0
|
| 117 |
+
requests-toolbelt==1.0.0
|
| 118 |
+
rich==13.7.1
|
| 119 |
+
rsa==4.9
|
| 120 |
+
safetensors==0.4.3
|
| 121 |
+
scikit-learn==1.3.2
|
| 122 |
+
scipy==1.10.1
|
| 123 |
+
sentence-transformers==3.0.1
|
| 124 |
+
shellingham==1.5.4
|
| 125 |
+
six==1.16.0
|
| 126 |
+
sniffio==1.3.1
|
| 127 |
+
soupsieve==2.5
|
| 128 |
+
SQLAlchemy==2.0.31
|
| 129 |
+
starlette==0.37.2
|
| 130 |
+
sympy==1.12.1
|
| 131 |
+
tabulate==0.9.0
|
| 132 |
+
tbb==2021.13.0
|
| 133 |
+
tenacity==8.4.1
|
| 134 |
+
threadpoolctl==3.5.0
|
| 135 |
tiktoken==0.7.0
|
| 136 |
+
tokenizers==0.19.1
|
| 137 |
+
tomli==2.0.1
|
| 138 |
+
torch==2.3.1
|
| 139 |
+
tqdm==4.66.4
|
| 140 |
+
transformers==4.41.2
|
| 141 |
+
typer==0.12.3
|
| 142 |
+
typing-inspect==0.9.0
|
| 143 |
+
typing_extensions==4.12.2
|
| 144 |
+
ujson==5.10.0
|
| 145 |
+
unstructured==0.11.8
|
| 146 |
+
unstructured-client==0.23.7
|
| 147 |
+
urllib3==2.2.2
|
| 148 |
+
uvicorn==0.30.1
|
| 149 |
+
watchfiles==0.22.0
|
| 150 |
+
websocket-client==1.8.0
|
| 151 |
+
websockets==12.0
|
| 152 |
+
wrapt==1.16.0
|
| 153 |
+
yarl==1.9.4
|
| 154 |
+
zipp==3.19.2
|