{ "cells": [ { "cell_type": "markdown", "id": "0ac71446-117f-4073-8cf2-1fb225a37a4d", "metadata": {}, "source": [ "# LangChain Indexes Getting Started\n", "- https://python.langchain.com/en/latest/modules/indexes/getting_started.html" ] }, { "cell_type": "markdown", "id": "6a2c4013-32a1-40a1-a8d7-f9b0228a9239", "metadata": {}, "source": [ "# 1. 입력 데이터 확인" ] }, { "cell_type": "markdown", "id": "6e6062e4-e8a2-4cb3-8ddd-4673496ba09a", "metadata": {}, "source": [ " 722 6469 39027 data/state_of_the_union.txt\n", " - 722 lines\n", " - 6469 words\n", " - 39027 characters" ] }, { "cell_type": "code", "execution_count": 69, "id": "05e39cb9-9d68-4861-831b-dfdad6eecdd6", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 722 6469 39027 data/state_of_the_union.txt\n" ] } ], "source": [ "! wc data/state_of_the_union.txt" ] }, { "cell_type": "code", "execution_count": 65, "id": "0d806cb6-dbe8-4be2-95f9-4e5787c59021", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Madam Speaker, Madam Vice President, our First Lady and Second Gentleman. Members of Congress and the Cabinet. Justices of the Supreme Court. My fellow Americans. \n", "\n", "Last year COVID-19 kept us apart. This year we are finally together again. \n" ] } ], "source": [ "! head -n3 data/state_of_the_union.txt" ] }, { "cell_type": "code", "execution_count": 66, "id": "d2126eab-b736-44b9-8de4-e2ac8dc7d759", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The United States of America. \n", "\n", "May God bless you all. May God protect our troops." ] } ], "source": [ "! tail -n3 data/state_of_the_union.txt" ] }, { "cell_type": "markdown", "id": "7a6c34f9-0078-4a92-b079-37ec1fb2304f", "metadata": {}, "source": [ "# 2. OpenAI LLM" ] }, { "cell_type": "code", "execution_count": 13, "id": "26e47671-422c-41df-9954-f370e7663805", "metadata": { "tags": [] }, "outputs": [], "source": [ "# import os\n", "# os.environ[\"OPENAI_API_KEY\"]='' \n" ] }, { "cell_type": "code", "execution_count": 14, "id": "ff251114-01e7-42b6-b121-6831c28ef28a", "metadata": { "tags": [] }, "outputs": [], "source": [ "from langchain.chains import RetrievalQA\n", "from langchain.llms import OpenAI" ] }, { "cell_type": "code", "execution_count": 15, "id": "87a68378-da2a-4d19-a088-b32eb7f446e4", "metadata": { "tags": [] }, "outputs": [], "source": [ "from langchain.document_loaders import TextLoader\n", "loader = TextLoader('data/state_of_the_union.txt', encoding='utf8')" ] }, { "cell_type": "code", "execution_count": 16, "id": "49069b30-f3bc-4b50-b454-bba3a079cf57", "metadata": { "tags": [] }, "outputs": [], "source": [ "from langchain.indexes import VectorstoreIndexCreator" ] }, { "cell_type": "code", "execution_count": 18, "id": "d42f39fa-cda6-49ea-a072-4edb83acfe5a", "metadata": { "tags": [] }, "outputs": [], "source": [ "index = VectorstoreIndexCreator().from_loaders([loader])" ] }, { "cell_type": "code", "execution_count": 19, "id": "efb48d65-c368-4c4b-a8bc-8813cb117cb1", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "\" The president said that Ketanji Brown Jackson is one of the nation's top legal minds, a former top litigator in private practice, a former federal public defender, and from a family of public school educators and police officers. He also said that she is a consensus builder and has received a broad range of support from the Fraternal Order of Police to former judges appointed by Democrats and Republicans.\"" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query = \"What did the president say about Ketanji Brown Jackson\"\n", "index.query(query)" ] }, { "cell_type": "code", "execution_count": 20, "id": "abf242fe-dc91-4b5a-9485-c76bf50c9009", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "{'question': 'What did the president say about Ketanji Brown Jackson',\n", " 'answer': \" The president said that he nominated Circuit Court of Appeals Judge Ketanji Brown Jackson, one of the nation's top legal minds, to continue Justice Breyer's legacy of excellence, and that she has received a broad range of support from the Fraternal Order of Police to former judges appointed by Democrats and Republicans.\\n\",\n", " 'sources': 'data/state_of_the_union.txt'}" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query = \"What did the president say about Ketanji Brown Jackson\"\n", "index.query_with_sources(query)" ] }, { "cell_type": "code", "execution_count": 21, "id": "44e3f374-ff20-45e9-9f21-1c8040f17d31", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "index.vectorstore" ] }, { "cell_type": "code", "execution_count": 22, "id": "f478db3e-7277-42bc-91b6-60342ee3c4b1", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "VectorStoreRetriever(vectorstore=, search_type='similarity', search_kwargs={})" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "index.vectorstore.as_retriever()" ] }, { "cell_type": "markdown", "id": "0facc254-522d-41e4-aae7-9ee4905cfda2", "metadata": {}, "source": [ "# 3. Walkthrough" ] }, { "cell_type": "markdown", "id": "eef79cb5-c606-45f0-982b-e06a1e9cfced", "metadata": {}, "source": [ "## 문서 파일 로딩\n", "- 1000 개의 Characters 를 1개의 Chunk 로 해서 42 개 생성 함." ] }, { "cell_type": "code", "execution_count": 23, "id": "b0ee7508-cb3b-475f-8b3c-3028034b938f", "metadata": { "tags": [] }, "outputs": [], "source": [ "documents = loader.load()" ] }, { "cell_type": "code", "execution_count": 24, "id": "8be23a29-defb-4925-9b81-26728887006f", "metadata": { "tags": [] }, "outputs": [], "source": [ "from langchain.text_splitter import CharacterTextSplitter\n", "text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n", "texts = text_splitter.split_documents(documents)" ] }, { "cell_type": "code", "execution_count": 34, "id": "b6461a5e-2e47-4a94-8157-12276f9973ec", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "# of textx: 42\n" ] } ], "source": [ "print(\"# of textx: \" , len(texts))" ] }, { "cell_type": "code", "execution_count": 37, "id": "7d004324-77c8-4e8c-bbd8-7e1223391cab", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "first text: \n", " [Document(page_content='Madam Speaker, Madam Vice President, our First Lady and Second Gentleman. Members of Congress and the Cabinet. Justices of the Supreme Court. My fellow Americans. \\n\\nLast year COVID-19 kept us apart. This year we are finally together again. \\n\\nTonight, we meet as Democrats Republicans and Independents. But most importantly as Americans. \\n\\nWith a duty to one another to the American people to the Constitution. \\n\\nAnd with an unwavering resolve that freedom will always triumph over tyranny. \\n\\nSix days ago, Russia’s Vladimir Putin sought to shake the foundations of the free world thinking he could make it bend to his menacing ways. But he badly miscalculated. \\n\\nHe thought he could roll into Ukraine and the world would roll over. Instead he met a wall of strength he never imagined. \\n\\nHe met the Ukrainian people. \\n\\nFrom President Zelenskyy to every Ukrainian, their fearlessness, their courage, their determination, inspires the world.', metadata={'source': 'data/state_of_the_union.txt'}), Document(page_content='Groups of citizens blocking tanks with their bodies. Everyone from students to retirees teachers turned soldiers defending their homeland. \\n\\nIn this struggle as President Zelenskyy said in his speech to the European Parliament “Light will win over darkness.” The Ukrainian Ambassador to the United States is here tonight. \\n\\nLet each of us here tonight in this Chamber send an unmistakable signal to Ukraine and to the world. \\n\\nPlease rise if you are able and show that, Yes, we the United States of America stand with the Ukrainian people. \\n\\nThroughout our history we’ve learned this lesson when dictators do not pay a price for their aggression they cause more chaos. \\n\\nThey keep moving. \\n\\nAnd the costs and the threats to America and the world keep rising. \\n\\nThat’s why the NATO Alliance was created to secure peace and stability in Europe after World War 2. \\n\\nThe United States is a member along with 29 other nations. \\n\\nIt matters. American diplomacy matters. American resolve matters.', metadata={'source': 'data/state_of_the_union.txt'})]\n" ] } ], "source": [ "print(\"first text: \\n\" , texts[0:2])" ] }, { "cell_type": "markdown", "id": "04d82544-75a0-455e-93c4-a0e29a8db1df", "metadata": {}, "source": [ "## OpenAI text-embedding-ada-002 모델 로딩" ] }, { "cell_type": "code", "execution_count": 38, "id": "6917db36-cbd8-4456-abd3-29c435ebcdf7", "metadata": { "tags": [] }, "outputs": [], "source": [ "from langchain.embeddings import OpenAIEmbeddings\n", "embeddings = OpenAIEmbeddings()" ] }, { "cell_type": "code", "execution_count": 40, "id": "3313a5b4-ea90-4040-b224-17c3e1341287", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "OpenAIEmbeddings(client=, model='text-embedding-ada-002', document_model_name='text-embedding-ada-002', query_model_name='text-embedding-ada-002', embedding_ctx_length=-1, openai_api_key=None, chunk_size=1000, max_retries=6)" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "embeddings" ] }, { "cell_type": "code", "execution_count": 42, "id": "897cbbeb-cecb-48a9-b123-1b274973735b", "metadata": { "tags": [] }, "outputs": [], "source": [ "from langchain.vectorstores import Chroma\n", "db = Chroma.from_documents(texts, embeddings)" ] }, { "cell_type": "code", "execution_count": 43, "id": "a160adc2-f758-4833-b8f4-e009ffa522b9", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db" ] }, { "cell_type": "markdown", "id": "f8411805-23f1-4419-9ea7-218dda67a953", "metadata": {}, "source": [ "## text-davinci-003 (GPT3.5) 모델 로딩" ] }, { "cell_type": "code", "execution_count": 44, "id": "3495195e-3cef-4a6e-a207-c4ab1d69066f", "metadata": { "tags": [] }, "outputs": [], "source": [ "retriever = db.as_retriever()" ] }, { "cell_type": "code", "execution_count": 45, "id": "7da55cf3-af6d-4e56-afb9-afcd02f96086", "metadata": { "tags": [] }, "outputs": [], "source": [ "llm=OpenAI()" ] }, { "cell_type": "code", "execution_count": 47, "id": "800f8116-6df3-4f71-9a13-96e50dfc3a86", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "OpenAI(cache=None, verbose=False, callback_manager=, client=, model_name='text-davinci-003', temperature=0.7, max_tokens=256, top_p=1, frequency_penalty=0, presence_penalty=0, n=1, best_of=1, model_kwargs={}, openai_api_key=None, batch_size=20, request_timeout=None, logit_bias={}, max_retries=6, streaming=False)" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "llm" ] }, { "cell_type": "markdown", "id": "0ff32904-2f8d-4217-8c5d-c04735724f0f", "metadata": {}, "source": [ "## 추정: Chaing 을 통하여 \"질문\" --> VectorStore() 유사 Chunks 추출 --> 프롬프트 생성 --> LLM 질의" ] }, { "cell_type": "code", "execution_count": 49, "id": "9287acb9-0a9a-4c53-98a1-431fa2ff91bd", "metadata": { "tags": [] }, "outputs": [], "source": [ "qa = RetrievalQA.from_chain_type(llm=llm, chain_type=\"stuff\", retriever=retriever)" ] }, { "cell_type": "code", "execution_count": 50, "id": "f8add04f-9ee7-4e13-bbf6-cc3aa117613a", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "\" The president said that Ketanji Brown Jackson is one of the nation's top legal minds, a former top litigator in private practice, a former federal public defender, and from a family of public school educators and police officers. He also said she is a consensus builder and has received a broad range of support since being nominated.\"" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query = \"What did the president say about Ketanji Brown Jackson\"\n", "qa.run(query)" ] }, { "cell_type": "markdown", "id": "8b1a41ad-3c91-4f6a-bcac-f61c8841c9f0", "metadata": {}, "source": [ "## VectorstoreIndexCreator 생성\n", "- 위의 과정에 대한 Wrapper" ] }, { "cell_type": "code", "execution_count": 51, "id": "93ee3786-c1ff-4aab-81a9-7e8fca1b1b46", "metadata": { "tags": [] }, "outputs": [], "source": [ "index_creator = VectorstoreIndexCreator(\n", " vectorstore_cls=Chroma, \n", " embedding=OpenAIEmbeddings(),\n", " text_splitter=CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n", ")" ] }, { "cell_type": "code", "execution_count": 54, "id": "4c7bfb87-536b-4aa5-b6c2-964b46ecb06a", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "OpenAIEmbeddings(client=, model='text-embedding-ada-002', document_model_name='text-embedding-ada-002', query_model_name='text-embedding-ada-002', embedding_ctx_length=-1, openai_api_key=None, chunk_size=1000, max_retries=6)" ] }, "execution_count": 54, "metadata": {}, "output_type": "execute_result" } ], "source": [ "index_creator.embedding" ] }, { "cell_type": "code", "execution_count": 57, "id": "0956d54a-431a-491d-a3e4-5a74521e2d6e", "metadata": { "tags": [] }, "outputs": [], "source": [ "index = index_creator.from_loaders([loader])" ] }, { "cell_type": "code", "execution_count": 58, "id": "e8598fc5-f0c5-4cfa-ba8b-1087da08af34", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "VectorStoreIndexWrapper(vectorstore=)" ] }, "execution_count": 58, "metadata": {}, "output_type": "execute_result" } ], "source": [ "index" ] }, { "cell_type": "markdown", "id": "deb40505-7874-4131-931c-9588469448bd", "metadata": {}, "source": [ "## 시맨틱 검색\n", "- 질문: \"What did the president say about Ketanji Brown Jackson\" \n", "- 4개의 유사 문서 제공" ] }, { "cell_type": "code", "execution_count": 73, "id": "fecda406-022a-4476-a451-6acc04369d6e", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "[Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', metadata={'source': 'data/state_of_the_union.txt'}),\n", " Document(page_content='A former top litigator in private practice. A former federal public defender. And from a family of public school educators and police officers. A consensus builder. Since she’s been nominated, she’s received a broad range of support—from the Fraternal Order of Police to former judges appointed by Democrats and Republicans. \\n\\nAnd if we are to advance liberty and justice, we need to secure the Border and fix the immigration system. \\n\\nWe can do both. At our border, we’ve installed new technology like cutting-edge scanners to better detect drug smuggling. \\n\\nWe’ve set up joint patrols with Mexico and Guatemala to catch more human traffickers. \\n\\nWe’re putting in place dedicated immigration judges so families fleeing persecution and violence can have their cases heard faster. \\n\\nWe’re securing commitments and supporting partners in South and Central America to host more refugees and secure their own borders.', metadata={'source': 'data/state_of_the_union.txt'}),\n", " Document(page_content='And for our LGBTQ+ Americans, let’s finally get the bipartisan Equality Act to my desk. The onslaught of state laws targeting transgender Americans and their families is wrong. \\n\\nAs I said last year, especially to our younger transgender Americans, I will always have your back as your President, so you can be yourself and reach your God-given potential. \\n\\nWhile it often appears that we never agree, that isn’t true. I signed 80 bipartisan bills into law last year. From preventing government shutdowns to protecting Asian-Americans from still-too-common hate crimes to reforming military justice. \\n\\nAnd soon, we’ll strengthen the Violence Against Women Act that I first wrote three decades ago. It is important for us to show the nation that we can come together and do big things. \\n\\nSo tonight I’m offering a Unity Agenda for the Nation. Four big things we can do together. \\n\\nFirst, beat the opioid epidemic.', metadata={'source': 'data/state_of_the_union.txt'}),\n", " Document(page_content='Tonight, I’m announcing a crackdown on these companies overcharging American businesses and consumers. \\n\\nAnd as Wall Street firms take over more nursing homes, quality in those homes has gone down and costs have gone up. \\n\\nThat ends on my watch. \\n\\nMedicare is going to set higher standards for nursing homes and make sure your loved ones get the care they deserve and expect. \\n\\nWe’ll also cut costs and keep the economy going strong by giving workers a fair shot, provide more training and apprenticeships, hire them based on their skills not degrees. \\n\\nLet’s pass the Paycheck Fairness Act and paid leave. \\n\\nRaise the minimum wage to $15 an hour and extend the Child Tax Credit, so no one has to raise a family in poverty. \\n\\nLet’s increase Pell Grants and increase our historic support of HBCUs, and invest in what Jill—our First Lady who teaches full-time—calls America’s best-kept secret: community colleges.', metadata={'source': 'data/state_of_the_union.txt'})]" ] }, "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ "index.vectorstore.similarity_search(\"What did the president say about Ketanji Brown Jackson\")" ] }, { "cell_type": "markdown", "id": "f9d6b824-2080-4e73-938a-24e6f57f4a7d", "metadata": {}, "source": [ "## Question --> Answer 분석 \n", "- 아래 질문 및 답변을 생성" ] }, { "cell_type": "markdown", "id": "0d81ebec-d1d8-46bb-8fe2-036756e52724", "metadata": {}, "source": [ "```python\n", "query = \"What did the president say about Ketanji Brown Jackson\"\n", "qa.run(query)\n", "\n", "\" The president said that Ketanji Brown Jackson is one of the nation's top legal minds, a former top litigator in private practice, a former federal public defender, and from a family of public school educators and police officers. He also said she is a consensus builder and has received a broad range of support since being nominated.\"\n", "```" ] }, { "cell_type": "markdown", "id": "fe5bcaf4-45d6-476a-9835-772e59e1061e", "metadata": {}, "source": [ "#### 위의 시맨틱 검색 ( \"What did the president say about Ketanji Brown Jackson\") \n", "- 아래에는 시멘틱 검색에 대한 4개의 문서 중에서 첫번째, 두번째 문서에 빨간색 글씨들이 LLM 이 Context 를 추출하여 답변을 생성한 것으로 보임\n", "\n", "Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.\n", "\n", "A former top litigator in private practice. A former federal public defender. And from a family of public school educators and police officers. A consensus builder. Since she’s been nominated, she’s received a broad range of support—from the Fraternal Order of Police to former judges appointed by Democrats and Republicans. \\n\\nAnd if we are to advance liberty and justice, we need to secure the Border and fix the immigration system. \\n\\nWe can do both. At our border, we’ve installed new technology like cutting-edge scanners to better detect drug smuggling. \\n\\nWe’ve set up joint patrols with Mexico and Guatemala to catch more human traffickers. \\n\\nWe’re putting in place dedicated immigration judges so families fleeing persecution and violence can have their cases heard faster. \\n\\nWe’re securing commitments and supporting partners in South and Central America to host more refugees and secure their own borders.\n" ] }, { "cell_type": "markdown", "id": "80a05748-eeb0-4a59-9c70-0156123992d2", "metadata": {}, "source": [ "### 추가 \"living with COVID-19\" 시맨틱 검색 예시" ] }, { "cell_type": "code", "execution_count": 64, "id": "c8bf56c0-5019-4778-9755-127ae72a4c10", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "[Document(page_content='And based on the projections, more of the country will reach that point across the next couple of weeks. \\n\\nThanks to the progress we have made this past year, COVID-19 need no longer control our lives. \\n\\nI know some are talking about “living with COVID-19”. Tonight – I say that we will never just accept living with COVID-19. \\n\\nWe will continue to combat the virus as we do other diseases. And because this is a virus that mutates and spreads, we will stay on guard. \\n\\nHere are four common sense steps as we move forward safely. \\n\\nFirst, stay protected with vaccines and treatments. We know how incredibly effective vaccines are. If you’re vaccinated and boosted you have the highest degree of protection. \\n\\nWe will never give up on vaccinating more Americans. Now, I know parents with kids under 5 are eager to see a vaccine authorized for their children. \\n\\nThe scientists are working hard to get that done and we’ll be ready with plenty of vaccines when they do.', metadata={'source': 'data/state_of_the_union.txt'}),\n", " Document(page_content='And with 75% of adult Americans fully vaccinated and hospitalizations down by 77%, most Americans can remove their masks, return to work, stay in the classroom, and move forward safely. \\n\\nWe achieved this because we provided free vaccines, treatments, tests, and masks. \\n\\nOf course, continuing this costs money. \\n\\nI will soon send Congress a request. \\n\\nThe vast majority of Americans have used these tools and may want to again, so I expect Congress to pass it quickly. \\n\\nFourth, we will continue vaccinating the world. \\n\\nWe’ve sent 475 Million vaccine doses to 112 countries, more than any other nation. \\n\\nAnd we won’t stop. \\n\\nWe have lost so much to COVID-19. Time with one another. And worst of all, so much loss of life. \\n\\nLet’s use this moment to reset. Let’s stop looking at COVID-19 as a partisan dividing line and see it for what it is: A God-awful disease. \\n\\nLet’s stop seeing each other as enemies, and start seeing each other for who we really are: Fellow Americans.', metadata={'source': 'data/state_of_the_union.txt'}),\n", " Document(page_content='And let’s pass the PRO Act when a majority of workers want to form a union—they shouldn’t be stopped. \\n\\nWhen we invest in our workers, when we build the economy from the bottom up and the middle out together, we can do something we haven’t done in a long time: build a better America. \\n\\nFor more than two years, COVID-19 has impacted every decision in our lives and the life of the nation. \\n\\nAnd I know you’re tired, frustrated, and exhausted. \\n\\nBut I also know this. \\n\\nBecause of the progress we’ve made, because of your resilience and the tools we have, tonight I can say \\nwe are moving forward safely, back to more normal routines. \\n\\nWe’ve reached a new moment in the fight against COVID-19, with severe cases down to a level not seen since last July. \\n\\nJust a few days ago, the Centers for Disease Control and Prevention—the CDC—issued new mask guidelines. \\n\\nUnder these new guidelines, most Americans in most of the country can now be mask free.', metadata={'source': 'data/state_of_the_union.txt'}),\n", " Document(page_content='We’re also ready with anti-viral treatments. If you get COVID-19, the Pfizer pill reduces your chances of ending up in the hospital by 90%. \\n\\nWe’ve ordered more of these pills than anyone in the world. And Pfizer is working overtime to get us 1 Million pills this month and more than double that next month. \\n\\nAnd we’re launching the “Test to Treat” initiative so people can get tested at a pharmacy, and if they’re positive, receive antiviral pills on the spot at no cost. \\n\\nIf you’re immunocompromised or have some other vulnerability, we have treatments and free high-quality masks. \\n\\nWe’re leaving no one behind or ignoring anyone’s needs as we move forward. \\n\\nAnd on testing, we have made hundreds of millions of tests available for you to order for free. \\n\\nEven if you already ordered free tests tonight, I am announcing that you can order more from covidtests.gov starting next week.', metadata={'source': 'data/state_of_the_union.txt'})]" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "index.vectorstore.similarity_search(\"living with COVID-19\")\n" ] }, { "cell_type": "markdown", "id": "3984f677-bb81-4738-98aa-15f847ed6a19", "metadata": {}, "source": [ "# 4. FAISS 사용\n", "- 참조 : https://python.langchain.com/en/latest/modules/indexes/vectorstores/examples/faiss.html" ] }, { "cell_type": "code", "execution_count": 76, "id": "05955dc2-ff4f-43c5-abf6-dcffaa2a17df", "metadata": { "tags": [] }, "outputs": [], "source": [ "from langchain.embeddings.openai import OpenAIEmbeddings\n", "from langchain.text_splitter import CharacterTextSplitter\n", "from langchain.vectorstores import FAISS\n", "from langchain.document_loaders import TextLoader" ] }, { "cell_type": "code", "execution_count": 78, "id": "19fd1e81-251b-456d-928d-b942803a7b6c", "metadata": { "tags": [] }, "outputs": [], "source": [ "db_FAISS = FAISS.from_documents(texts, embeddings)" ] }, { "cell_type": "code", "execution_count": 79, "id": "af3c7aca-ffb9-41fc-9a0c-6f3bb4a78b1d", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "{0: '4187ca80-7460-423a-b370-84a4ab647983',\n", " 1: 'e67fd22c-7288-4b46-8657-3bdb3bc6b9f5',\n", " 2: '969b48d3-89eb-4b23-9b57-41466a47b868',\n", " 3: 'f9c12189-c88f-444f-a9ec-84ef13302117',\n", " 4: '420d8325-2891-467b-9257-d9994fe24ff3',\n", " 5: '82b5cc00-c784-4fdc-a778-ceee4c69ca01',\n", " 6: '0e6a2770-3e5f-4c06-add4-26dc445ca21d',\n", " 7: '03055cdd-0095-4e52-8ce0-59e45af41431',\n", " 8: 'ddcc07d4-0207-4cc7-b08b-5a35e458dc13',\n", " 9: '75c2c84b-7aaf-4442-b073-913ccba68a8e',\n", " 10: 'd9b6f326-1f3a-4266-a75c-3d6633eeceb7',\n", " 11: '7ebf917c-1689-4241-a21e-187b6920ffcc',\n", " 12: 'd990ab83-586d-4a77-880d-dcb3cfb954aa',\n", " 13: '0550832e-7bc7-482e-b6df-9f2bf8110aed',\n", " 14: '6d6e018d-b849-4507-babf-da2a604a3b66',\n", " 15: 'f0e52fa5-7a98-4453-9dda-7052686edac0',\n", " 16: 'c5a789e9-512d-4086-9016-5547cc53e69b',\n", " 17: 'f49b761e-4745-4bcd-9b4b-103ffde21a50',\n", " 18: '5a22d6cf-de54-4a9f-bb93-92811587e17b',\n", " 19: '4a244f2b-0e7c-453f-9c41-881af19f4a8a',\n", " 20: '0c6cdc7b-2146-4c6d-8526-5631de41227b',\n", " 21: '5f0895ae-eeb6-44f7-a9da-17e6b01edf71',\n", " 22: '0f6bd6dd-cdb1-4995-9007-27fc53f16796',\n", " 23: '1aeced3e-d8bc-438e-9e87-5030f1d479a2',\n", " 24: 'a805a738-54bf-4d41-a1bb-8f416ab23281',\n", " 25: '585baa91-a2fe-4a0d-b678-0eb0c4255bf2',\n", " 26: '322cb001-cc1d-4735-ae55-012cc2f75244',\n", " 27: 'be12be7f-cb16-4753-b66f-70651bec7de2',\n", " 28: 'f215084c-9476-44bd-8a39-4ed1b11ccfd6',\n", " 29: '3eb607a8-9fe7-4987-94aa-73ee7bf5f36e',\n", " 30: 'eb083616-0560-45ce-aeee-1c70d1c23d54',\n", " 31: '332acd31-c30b-4b40-b0cb-2890dd462e75',\n", " 32: 'dffca792-3a92-4c72-89aa-fd6ed9f48340',\n", " 33: '33eb74ef-8b35-490e-af44-12c687170867',\n", " 34: '1692dc5c-dff9-434d-95bd-227b557d4627',\n", " 35: '422e2e8e-0603-4c35-9088-1808d7ba7f3e',\n", " 36: '22b1341f-1566-4bc4-9b27-e712983530ab',\n", " 37: '15661a02-9d3a-4118-9308-b60c7cfaa284',\n", " 38: 'c3b6c0d8-eea3-43c8-a4f5-4207548e0f2b',\n", " 39: '3ec7f4ea-ca57-4adf-ae69-da71a05a2f10',\n", " 40: '4e668c74-7d97-459e-ab05-b74e3c6a4c65',\n", " 41: 'e8ec7ae2-7f47-4658-94a3-ff4631c37ff9'}" ] }, "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ "db_FAISS.index_to_docstore_id" ] }, { "cell_type": "code", "execution_count": 83, "id": "d9e54248-a09d-4cb3-8765-681b81394bad", "metadata": { "tags": [] }, "outputs": [], "source": [ "query = \"What did the president say about Ketanji Brown Jackson\"\n", "docs = db_FAISS.similarity_search_with_score(query)" ] }, { "cell_type": "code", "execution_count": 84, "id": "dde0252f-58ec-4c37-ad1c-7502ea8f6eed", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "[(Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', metadata={'source': 'data/state_of_the_union.txt'}),\n", " 0.36927557),\n", " (Document(page_content='A former top litigator in private practice. A former federal public defender. And from a family of public school educators and police officers. A consensus builder. Since she’s been nominated, she’s received a broad range of support—from the Fraternal Order of Police to former judges appointed by Democrats and Republicans. \\n\\nAnd if we are to advance liberty and justice, we need to secure the Border and fix the immigration system. \\n\\nWe can do both. At our border, we’ve installed new technology like cutting-edge scanners to better detect drug smuggling. \\n\\nWe’ve set up joint patrols with Mexico and Guatemala to catch more human traffickers. \\n\\nWe’re putting in place dedicated immigration judges so families fleeing persecution and violence can have their cases heard faster. \\n\\nWe’re securing commitments and supporting partners in South and Central America to host more refugees and secure their own borders.', metadata={'source': 'data/state_of_the_union.txt'}),\n", " 0.43436372),\n", " (Document(page_content='And for our LGBTQ+ Americans, let’s finally get the bipartisan Equality Act to my desk. The onslaught of state laws targeting transgender Americans and their families is wrong. \\n\\nAs I said last year, especially to our younger transgender Americans, I will always have your back as your President, so you can be yourself and reach your God-given potential. \\n\\nWhile it often appears that we never agree, that isn’t true. I signed 80 bipartisan bills into law last year. From preventing government shutdowns to protecting Asian-Americans from still-too-common hate crimes to reforming military justice. \\n\\nAnd soon, we’ll strengthen the Violence Against Women Act that I first wrote three decades ago. It is important for us to show the nation that we can come together and do big things. \\n\\nSo tonight I’m offering a Unity Agenda for the Nation. Four big things we can do together. \\n\\nFirst, beat the opioid epidemic.', metadata={'source': 'data/state_of_the_union.txt'}),\n", " 0.45247576),\n", " (Document(page_content='Tonight, I’m announcing a crackdown on these companies overcharging American businesses and consumers. \\n\\nAnd as Wall Street firms take over more nursing homes, quality in those homes has gone down and costs have gone up. \\n\\nThat ends on my watch. \\n\\nMedicare is going to set higher standards for nursing homes and make sure your loved ones get the care they deserve and expect. \\n\\nWe’ll also cut costs and keep the economy going strong by giving workers a fair shot, provide more training and apprenticeships, hire them based on their skills not degrees. \\n\\nLet’s pass the Paycheck Fairness Act and paid leave. \\n\\nRaise the minimum wage to $15 an hour and extend the Child Tax Credit, so no one has to raise a family in poverty. \\n\\nLet’s increase Pell Grants and increase our historic support of HBCUs, and invest in what Jill—our First Lady who teaches full-time—calls America’s best-kept secret: community colleges.', metadata={'source': 'data/state_of_the_union.txt'}),\n", " 0.45297456)]" ] }, "execution_count": 84, "metadata": {}, "output_type": "execute_result" } ], "source": [ "docs" ] }, { "cell_type": "code", "execution_count": 88, "id": "7cca5d62-2535-45d1-96c2-4fad66ddb78a", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "query: \n", " What did the president say about Ketanji Brown Jackson\n", "embedding_vector length: 1536\n", "A little bit of embedding_vector : [-0.052522048354148865, -0.00884410459548235, -0.008728805929422379, 0.007738592103123665, 0.0037912996485829353]\n" ] } ], "source": [ "embedding_vector = embeddings.embed_query(query)\n", "print(\"query: \\n\", query)\n", "print(\"embedding_vector length: \", len(embedding_vector))\n", "print(\"A little bit of embedding_vector : \", embedding_vector[0:5])\n" ] }, { "cell_type": "code", "execution_count": 89, "id": "0c83a37f-eaf6-4c69-9599-fd37cb9a79dd", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "[Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', metadata={'source': 'data/state_of_the_union.txt'}),\n", " Document(page_content='A former top litigator in private practice. A former federal public defender. And from a family of public school educators and police officers. A consensus builder. Since she’s been nominated, she’s received a broad range of support—from the Fraternal Order of Police to former judges appointed by Democrats and Republicans. \\n\\nAnd if we are to advance liberty and justice, we need to secure the Border and fix the immigration system. \\n\\nWe can do both. At our border, we’ve installed new technology like cutting-edge scanners to better detect drug smuggling. \\n\\nWe’ve set up joint patrols with Mexico and Guatemala to catch more human traffickers. \\n\\nWe’re putting in place dedicated immigration judges so families fleeing persecution and violence can have their cases heard faster. \\n\\nWe’re securing commitments and supporting partners in South and Central America to host more refugees and secure their own borders.', metadata={'source': 'data/state_of_the_union.txt'}),\n", " Document(page_content='And for our LGBTQ+ Americans, let’s finally get the bipartisan Equality Act to my desk. The onslaught of state laws targeting transgender Americans and their families is wrong. \\n\\nAs I said last year, especially to our younger transgender Americans, I will always have your back as your President, so you can be yourself and reach your God-given potential. \\n\\nWhile it often appears that we never agree, that isn’t true. I signed 80 bipartisan bills into law last year. From preventing government shutdowns to protecting Asian-Americans from still-too-common hate crimes to reforming military justice. \\n\\nAnd soon, we’ll strengthen the Violence Against Women Act that I first wrote three decades ago. It is important for us to show the nation that we can come together and do big things. \\n\\nSo tonight I’m offering a Unity Agenda for the Nation. Four big things we can do together. \\n\\nFirst, beat the opioid epidemic.', metadata={'source': 'data/state_of_the_union.txt'}),\n", " Document(page_content='Tonight, I’m announcing a crackdown on these companies overcharging American businesses and consumers. \\n\\nAnd as Wall Street firms take over more nursing homes, quality in those homes has gone down and costs have gone up. \\n\\nThat ends on my watch. \\n\\nMedicare is going to set higher standards for nursing homes and make sure your loved ones get the care they deserve and expect. \\n\\nWe’ll also cut costs and keep the economy going strong by giving workers a fair shot, provide more training and apprenticeships, hire them based on their skills not degrees. \\n\\nLet’s pass the Paycheck Fairness Act and paid leave. \\n\\nRaise the minimum wage to $15 an hour and extend the Child Tax Credit, so no one has to raise a family in poverty. \\n\\nLet’s increase Pell Grants and increase our historic support of HBCUs, and invest in what Jill—our First Lady who teaches full-time—calls America’s best-kept secret: community colleges.', metadata={'source': 'data/state_of_the_union.txt'})]" ] }, "execution_count": 89, "metadata": {}, "output_type": "execute_result" } ], "source": [ "docs_and_scores = db.similarity_search_by_vector(embedding_vector)\n", "docs_and_scores" ] }, { "cell_type": "code", "execution_count": null, "id": "065f7a0c-ee9a-4202-9a47-8a9d7884c216", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "availableInstances": [ { "_defaultOrder": 0, "_isFastLaunch": true, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 4, "name": "ml.t3.medium", "vcpuNum": 2 }, { "_defaultOrder": 1, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 8, "name": "ml.t3.large", "vcpuNum": 2 }, { "_defaultOrder": 2, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.t3.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 3, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.t3.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 4, "_isFastLaunch": true, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 8, "name": "ml.m5.large", "vcpuNum": 2 }, { "_defaultOrder": 5, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.m5.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 6, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.m5.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 7, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.m5.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 8, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.m5.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 9, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.m5.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 10, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.m5.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 11, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 384, "name": "ml.m5.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 12, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 8, "name": "ml.m5d.large", "vcpuNum": 2 }, { "_defaultOrder": 13, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.m5d.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 14, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.m5d.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 15, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.m5d.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 16, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.m5d.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 17, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.m5d.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 18, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.m5d.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 19, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 384, "name": "ml.m5d.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 20, "_isFastLaunch": false, "category": "General purpose", "gpuNum": 0, "hideHardwareSpecs": true, "memoryGiB": 0, "name": "ml.geospatial.interactive", "supportedImageNames": [ "sagemaker-geospatial-v1-0" ], "vcpuNum": 0 }, { "_defaultOrder": 21, "_isFastLaunch": true, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 4, "name": "ml.c5.large", "vcpuNum": 2 }, { "_defaultOrder": 22, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 8, "name": "ml.c5.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 23, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.c5.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 24, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.c5.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 25, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 72, "name": "ml.c5.9xlarge", "vcpuNum": 36 }, { "_defaultOrder": 26, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 96, "name": "ml.c5.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 27, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 144, "name": "ml.c5.18xlarge", "vcpuNum": 72 }, { "_defaultOrder": 28, "_isFastLaunch": false, "category": "Compute optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.c5.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 29, "_isFastLaunch": true, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.g4dn.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 30, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.g4dn.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 31, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.g4dn.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 32, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.g4dn.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 33, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 4, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.g4dn.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 34, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.g4dn.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 35, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 61, "name": "ml.p3.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 36, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 4, "hideHardwareSpecs": false, "memoryGiB": 244, "name": "ml.p3.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 37, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 8, "hideHardwareSpecs": false, "memoryGiB": 488, "name": "ml.p3.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 38, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 8, "hideHardwareSpecs": false, "memoryGiB": 768, "name": "ml.p3dn.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 39, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.r5.large", "vcpuNum": 2 }, { "_defaultOrder": 40, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.r5.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 41, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.r5.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 42, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.r5.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 43, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.r5.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 44, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 384, "name": "ml.r5.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 45, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 512, "name": "ml.r5.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 46, "_isFastLaunch": false, "category": "Memory Optimized", "gpuNum": 0, "hideHardwareSpecs": false, "memoryGiB": 768, "name": "ml.r5.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 47, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 16, "name": "ml.g5.xlarge", "vcpuNum": 4 }, { "_defaultOrder": 48, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 32, "name": "ml.g5.2xlarge", "vcpuNum": 8 }, { "_defaultOrder": 49, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 64, "name": "ml.g5.4xlarge", "vcpuNum": 16 }, { "_defaultOrder": 50, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 128, "name": "ml.g5.8xlarge", "vcpuNum": 32 }, { "_defaultOrder": 51, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 1, "hideHardwareSpecs": false, "memoryGiB": 256, "name": "ml.g5.16xlarge", "vcpuNum": 64 }, { "_defaultOrder": 52, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 4, "hideHardwareSpecs": false, "memoryGiB": 192, "name": "ml.g5.12xlarge", "vcpuNum": 48 }, { "_defaultOrder": 53, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 4, "hideHardwareSpecs": false, "memoryGiB": 384, "name": "ml.g5.24xlarge", "vcpuNum": 96 }, { "_defaultOrder": 54, "_isFastLaunch": false, "category": "Accelerated computing", "gpuNum": 8, "hideHardwareSpecs": false, "memoryGiB": 768, "name": "ml.g5.48xlarge", "vcpuNum": 192 } ], "instance_type": "ml.m5.large", "kernelspec": { "display_name": "Python 3 (PyTorch 1.13 Python 3.9 CPU Optimized)", "language": "python", "name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/pytorch-1.13-cpu-py39" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.16" } }, "nbformat": 4, "nbformat_minor": 5 }