Commit 5eaaba41 authored by Rayyyyy's avatar Rayyyyy
Browse files

First add in 0524

parents
Pipeline #1017 failed with stages
in 0 seconds
{
"cells": [
{
"cell_type": "markdown",
"id": "09211e76-286f-4b12-acd7-cfb082dc2d66",
"metadata": {},
"source": [
"# Llama3 Cookbook with Ollama and Replicate\n",
"\n",
"<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/docs/examples/cookbooks/llama3_cookbook_ollama_replicate.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>\n",
"\n",
"Meta developed and released the Meta [Llama 3](https://ai.meta.com/blog/meta-llama-3/) family of large language models (LLMs), a collection of pretrained and instruction tuned generative text models in 8 and 70B sizes. The Llama 3 instruction tuned models are optimized for dialogue use cases and outperform many of the available open source chat models on common industry benchmarks.\n",
"\n",
"In this notebook, we demonstrate how to use Llama3 with LlamaIndex for a comprehensive set of use cases. \n",
"1. Basic completion / chat \n",
"2. Basic RAG (Vector Search, Summarization)\n",
"3. Advanced RAG (Routing, Sub-Questions)\n",
"4. Text-to-SQL \n",
"5. Structured Data Extraction\n",
"6. Agents\n",
"\n",
"\n",
"We use Llama3-8B through Ollama, and Llama3-70B through Replicate. "
]
},
{
"cell_type": "markdown",
"id": "de2901c0-e20d-48e5-9385-dbca2258c564",
"metadata": {},
"source": [
"## Installation and Setup"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bcf643ac-b025-4812-aaed-f8f85d1ba505",
"metadata": {},
"outputs": [],
"source": [
"!pip install llama-index\n",
"!pip install llama-index-llms-ollama\n",
"!pip install llama-index-llms-replicate\n",
"!pip install llama-index-embeddings-huggingface\n",
"!pip install llama-parse\n",
"!pip install replicate"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "641fa5c8-d63e-47f8-b5bc-ebf994f6e314",
"metadata": {},
"outputs": [],
"source": [
"import nest_asyncio\n",
"\n",
"nest_asyncio.apply()"
]
},
{
"cell_type": "markdown",
"id": "1714ea83-6cd4-44bb-b53f-4499126c3809",
"metadata": {},
"source": [
"### Setup LLM using Ollama"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d5256970-eba4-499a-b438-8766a290a61a",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.llms.ollama import Ollama\n",
"\n",
"llm = Ollama(model=\"llama3\", request_timeout=120.0)"
]
},
{
"cell_type": "markdown",
"id": "729265f3-4c62-4692-84ef-80747386eddd",
"metadata": {},
"source": [
"### Setup LLM using Replicate\n",
"\n",
"Make sure you have REPLICATE_API_TOKEN specified!"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5b56a2ff-f9a4-4ba1-aee4-58f9f71637d2",
"metadata": {},
"outputs": [],
"source": [
"# os.environ[\"REPLICATE_API_TOKEN\"] = \"<YOUR_API_KEY>\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "60247c74-046b-4f6a-8522-bb4faf5a7a1f",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.llms.replicate import Replicate\n",
"\n",
"llm_replicate = Replicate(model=\"meta/meta-llama-3-70b-instruct\")\n",
"# llm_replicate = Replicate(model=\"meta/meta-llama-3-8b-instruct\")"
]
},
{
"cell_type": "markdown",
"id": "41c3f154-d345-465d-8eed-63b99adbd3ca",
"metadata": {},
"source": [
"### Setup Embedding Model"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0cda736d-e414-44e3-8c15-6be49f5f0282",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.embeddings.huggingface import HuggingFaceEmbedding\n",
"\n",
"embed_model = HuggingFaceEmbedding(model_name=\"BAAI/bge-small-en-v1.5\")"
]
},
{
"cell_type": "markdown",
"id": "3625cf29-7c56-475a-8efd-fbe8ffce194d",
"metadata": {},
"source": [
"### Define Global Settings Configuration\n",
"\n",
"In LlamaIndex, you can define global settings so you don't have to pass the LLM / embedding model objects everywhere."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "be3565d1-cc5b-4149-ad5a-7be8f7818e0c",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core import Settings\n",
"\n",
"Settings.llm = llm\n",
"Settings.embed_model = embed_model"
]
},
{
"cell_type": "markdown",
"id": "42449b68-47f5-40cf-9207-191307b25e8e",
"metadata": {},
"source": [
"### Download Data\n",
"\n",
"Here you'll download data that's used in section 2 and onwards.\n",
"\n",
"We'll download some articles on Kendrick, Drake, and their beef (as of May 2024)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "59b18640-cdfa-42c1-ab53-115983c1fdc4",
"metadata": {},
"outputs": [],
"source": [
"!mkdir data\n",
"!wget \"https://www.dropbox.com/scl/fi/t1soxfjdp0v44an6sdymd/drake_kendrick_beef.pdf?rlkey=u9546ymb7fj8lk2v64r6p5r5k&st=wjzzrgil&dl=1\" -O data/drake_kendrick_beef.pdf\n",
"!wget \"https://www.dropbox.com/scl/fi/nts3n64s6kymner2jppd6/drake.pdf?rlkey=hksirpqwzlzqoejn55zemk6ld&st=mohyfyh4&dl=1\" -O data/drake.pdf\n",
"!wget \"https://www.dropbox.com/scl/fi/8ax2vnoebhmy44bes2n1d/kendrick.pdf?rlkey=fhxvn94t5amdqcv9vshifd3hj&st=dxdtytn6&dl=1\" -O data/kendrick.pdf"
]
},
{
"cell_type": "markdown",
"id": "9edee491-05f8-4fbb-9394-baa82f1e5087",
"metadata": {},
"source": [
"### Load Data\n",
"\n",
"We load data using LlamaParse by default, but you can also choose to opt for our free pypdf reader (in SimpleDirectoryReader by default) if you don't have an account."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b648635a-2672-407f-bae6-01660e5426d7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Started parsing the file under job_id 32a7bb50-6a25-4295-971c-2de6f1588e0d\n",
".Started parsing the file under job_id b8cc075e-b6d5-4ded-b060-f72e9393b391\n",
"..Started parsing the file under job_id 42fc41a4-68b6-49ee-8647-781b5cdb8893\n",
"..."
]
}
],
"source": [
"from llama_parse import LlamaParse\n",
"\n",
"docs_kendrick = LlamaParse(result_type=\"text\").load_data(\"./data/kendrick.pdf\")\n",
"docs_drake = LlamaParse(result_type=\"text\").load_data(\"./data/drake.pdf\")\n",
"docs_both = LlamaParse(result_type=\"text\").load_data(\n",
" \"./data/drake_kendrick_beef.pdf\"\n",
")\n",
"\n",
"\n",
"# from llama_index.core import SimpleDirectoryReader\n",
"\n",
"# docs_kendrick = SimpleDirectoryReader(input_files=[\"data/kendrick.pdf\"]).load_data()\n",
"# docs_drake = SimpleDirectoryReader(input_files=[\"data/drake.pdf\"]).load_data()\n",
"# docs_both = SimpleDirectoryReader(input_files=[\"data/drake_kendrick_beef.pdf\"]).load_data()"
]
},
{
"cell_type": "markdown",
"id": "071a8f44-2765-4d57-b8da-15d3c718874d",
"metadata": {},
"source": [
"## 1. Basic Completion and Chat"
]
},
{
"cell_type": "markdown",
"id": "c0b1ace8-32fb-46b2-a065-8817ddc0310b",
"metadata": {},
"source": [
"### Call complete with a prompt"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a2db43f9-74af-453c-9f83-8db0379c3302",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I'm just an AI, I don't have personal preferences or opinions, nor can I listen to music. I exist solely to provide information and assist with tasks, so I don't have the capacity to enjoy or compare different artists' music. Both Drake and Kendrick Lamar are highly acclaimed rappers, and it's subjective which one you might prefer based on your individual tastes in music.\n"
]
}
],
"source": [
"response = llm.complete(\"do you like drake or kendrick better?\")\n",
"\n",
"print(response)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "89326153-e2d2-4136-8193-fb27d20670c3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"As a hypothetical Drake fan, I'd say that there are several reasons why I might prefer his music over Kendrick's. Here are a few possible reasons:\n",
"\n",
"1. **Lyrical storytelling**: Drake is known for his vivid storytelling on tracks like \"Marvins Room\" and \"Take Care.\" He has a way of painting pictures with his words, making listeners feel like they're right there with him, experiencing the highs and lows he's singing about. Kendrick, while also an incredible storyteller, might not have the same level of lyrical detail that Drake does.\n",
"2. **Melodic flow**: Drake's melodic flow is infectious! He has a way of crafting hooks and choruses that get stuck in your head, making it hard to stop listening. Kendrick's flows are often more complex and intricate, but Drake's simplicity can be just as effective in getting the job done.\n",
"3. **Vulnerability**: Drake isn't afraid to show his vulnerable side on tracks like \"Hold On\" and \"I'm Upset.\" He wears his heart on his sleeve, sharing personal struggles and emotions with listeners. This vulnerability makes him relatable and easier to connect with on a deeper level.\n",
"4. **Production**: Drake has had the privilege of working with some incredible producers (like Noah \"40\" Shebib and Boi-1da) who bring out the best in him. The way he incorporates these sounds into his songs is often seamless, creating a unique blend of hip-hop and R&B that's hard to resist.\n",
"5. **Cultural relevance**: As someone who grew up in Toronto, Drake has a deep understanding of the Canadian experience and the struggles that come with it. He often references his hometown and the people he grew up around, giving his music a distinctly Canadian flavor. This cultural relevance makes his music feel more authentic and connected to the world we live in.\n",
"6. **Commercial appeal**: Let's face it – Drake has a knack for creating hits! His songs are often catchy, radio-friendly, and designed to get stuck in your head. While Kendrick might not have the same level of commercial success, Drake's ability to craft songs that resonate with a wider audience is undeniable.\n",
"\n",
"Of course, this is all just hypothetical – as a fan, I can appreciate both artists for their unique strengths and styles! What do you think?"
]
}
],
"source": [
"stream_response = llm.stream_complete(\n",
" \"you're a drake fan. tell me why you like drake more than kendrick\"\n",
")\n",
"\n",
"for t in stream_response:\n",
" print(t.delta, end=\"\")"
]
},
{
"cell_type": "markdown",
"id": "a4558339-c8a1-4d26-a430-eb71768b5351",
"metadata": {},
"source": [
"### Call chat with a list of messages"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5f393031-f743-4a28-a122-71817e3fbd1b",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core.llms import ChatMessage\n",
"\n",
"messages = [\n",
" ChatMessage(role=\"system\", content=\"You are Kendrick.\"),\n",
" ChatMessage(role=\"user\", content=\"Write a verse.\"),\n",
"]\n",
"response = llm.chat(messages)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8e9551fc-0efc-4671-bc57-339121004c39",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"assistant: \"Listen up, y'all, I got a message to share\n",
"Been through the struggles, but my spirit's still fair\n",
"From Compton streets to the top of the game\n",
"I'm the real Hov, ain't nobody gonna claim my fame\"\n"
]
}
],
"source": [
"print(response)"
]
},
{
"cell_type": "markdown",
"id": "6a67a33d-fe7d-4381-983f-ca3a6945995d",
"metadata": {},
"source": [
"## 2. Basic RAG (Vector Search, Summarization)"
]
},
{
"cell_type": "markdown",
"id": "c104a0c5-e43b-475b-9fa6-186906c1f327",
"metadata": {},
"source": [
"### Basic RAG (Vector Search)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "216787b7-e40a-43fc-a4ca-c43cb798ce9e",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core import VectorStoreIndex\n",
"\n",
"index = VectorStoreIndex.from_documents(docs_both)\n",
"query_engine = index.as_query_engine(similarity_top_k=3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a854e9d3-70f1-4927-a2f6-59e90c31f2f0",
"metadata": {},
"outputs": [],
"source": [
"response = query_engine.query(\"Tell me about family matters\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "da796970-bc38-4cb4-9d32-ebd1b71d4bdc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"According to the provided context, \"Family Matters\" is a seven-and-a-half-minute diss track by Drake in response to Kendrick Lamar's disses against him. The song has three different beats and features several shots at Kendrick, as well as other members of Drake's entourage, including A$AP Rocky and The Weeknd. In the song, Drake raps about his personal life, including his relationships with Rihanna and Whitney Alford, and even makes allegations about Kendrick's domestic life.\n"
]
}
],
"source": [
"print(str(response))"
]
},
{
"cell_type": "markdown",
"id": "eff935b7-4f37-4758-8997-82fb0852e732",
"metadata": {},
"source": [
"### Basic RAG (Summarization)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dfe72300-7a38-453e-b1f2-bc1c00a01ff7",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core import SummaryIndex\n",
"\n",
"summary_index = SummaryIndex.from_documents(docs_both)\n",
"summary_engine = summary_index.as_query_engine()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "178f1f12-51f7-4b45-9346-c16ed12b3b8d",
"metadata": {},
"outputs": [],
"source": [
"response = summary_engine.query(\n",
" \"Given your assessment of this article, who won the beef?\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b8125382-d576-4b99-a0da-2fbb71a5b19b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"**Repeat**\n",
"\n",
"The article does not provide a clear verdict on who \"won\" the beef, nor does it suggest that the conflict has been definitively resolved. Instead, it presents the situation as ongoing and multifaceted, with both artists continuing to engage in a game of verbal sparring and lyrical one-upmanship.\n"
]
}
],
"source": [
"print(str(response))"
]
},
{
"cell_type": "markdown",
"id": "68918eb6-f1e6-460c-b1d5-fb49c3fed4b8",
"metadata": {},
"source": [
"## 3. Advanced RAG (Routing, Sub-Questions)"
]
},
{
"cell_type": "markdown",
"id": "94fd7097-0287-4522-8e43-3e088291fa8a",
"metadata": {},
"source": [
"### Build a Router that can choose whether to do vector search or summarization"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3949dd41-e9a1-47f6-900f-4f987cad3f84",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core.tools import QueryEngineTool, ToolMetadata\n",
"\n",
"vector_tool = QueryEngineTool(\n",
" index.as_query_engine(),\n",
" metadata=ToolMetadata(\n",
" name=\"vector_search\",\n",
" description=\"Useful for searching for specific facts.\",\n",
" ),\n",
")\n",
"\n",
"summary_tool = QueryEngineTool(\n",
" index.as_query_engine(response_mode=\"tree_summarize\"),\n",
" metadata=ToolMetadata(\n",
" name=\"summary\",\n",
" description=\"Useful for summarizing an entire document.\",\n",
" ),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d063d07b-c03e-4b26-8556-e3c058d2fd52",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;3;38;5;200mSelecting query engine 0: The song 'Meet the Grahams' might contain specific facts or information about the band, making it useful for searching for those specific details..\n",
"\u001b[0m"
]
}
],
"source": [
"from llama_index.core.query_engine import RouterQueryEngine\n",
"\n",
"query_engine = RouterQueryEngine.from_defaults(\n",
" [vector_tool, summary_tool], select_multi=False, verbose=True\n",
")\n",
"\n",
"response = query_engine.query(\n",
" \"Tell me about the song meet the grahams - why is it significant\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "396aad75-5a71-4bd9-a760-7f13fe223079",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\"Meet the Grahams\" artwork is a crucial part of a larger strategy by Kendrick Lamar to address Drake's family matters in a diss track. The artwork shows a pair of Maybach gloves, a shirt, receipts, and prescription bottles, including one for Ozempic prescribed to Drake. This song is significant because it serves as the full picture that Kendrick teased earlier on \"6.16 in LA\" and addresses all members of Drake's family, including his son Adonis, mother Sandi, father Dennis, and an alleged 11-year-old daughter. The song takes it to the point of no return, with Kendrick musing that he wishes Dennis Graham wore a condom the night Drake was conceived and telling both Drake's parents that they raised a man whose house is due to be raided any day now on Harvey Weinstein-level allegations.\n"
]
}
],
"source": [
"print(response)"
]
},
{
"cell_type": "markdown",
"id": "2af04881-6a64-475c-8c1e-e5bd3e8006ee",
"metadata": {},
"source": [
"### Break Complex Questions down into Sub-Questions\n",
"\n",
"Our Sub-Question Query Engine breaks complex questions down into sub-questions.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2f9430df-ece7-493c-be6b-d5b371c7b8b0",
"metadata": {},
"outputs": [],
"source": [
"drake_index = VectorStoreIndex.from_documents(docs_drake)\n",
"drake_query_engine = drake_index.as_query_engine(similarity_top_k=3)\n",
"\n",
"kendrick_index = VectorStoreIndex.from_documents(docs_kendrick)\n",
"kendrick_query_engine = kendrick_index.as_query_engine(similarity_top_k=3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f16fa210-7e15-474a-9bd2-1ac681290006",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core.tools import QueryEngineTool, ToolMetadata\n",
"\n",
"drake_tool = QueryEngineTool(\n",
" drake_index.as_query_engine(),\n",
" metadata=ToolMetadata(\n",
" name=\"drake_search\",\n",
" description=\"Useful for searching over Drake's life.\",\n",
" ),\n",
")\n",
"\n",
"kendrick_tool = QueryEngineTool(\n",
" kendrick_index.as_query_engine(),\n",
" metadata=ToolMetadata(\n",
" name=\"kendrick_summary\",\n",
" description=\"Useful for searching over Kendrick's life.\",\n",
" ),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "21e05b95-95cb-45f3-8fbe-d0b54a9ba988",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Generated 1 sub questions.\n",
"\u001b[1;3;38;2;237;90;200m[drake_search] Q: What are the albums released by Drake\n",
"\u001b[0m\u001b[1;3;38;2;237;90;200m[drake_search] A: Based on the provided context information, the albums released by Drake are:\n",
"\n",
"1. Take Care (album)\n",
"2. Nothing Was the Same\n",
"3. If You're Reading This It's Too Late (rumored to be a mixtape or album)\n",
"4. Certified Lover Boy\n",
"5. Honestly, Nevermind\n",
"\u001b[0mBased on the provided context information, the albums released by Drake are:\n",
"\n",
"1. Take Care (album)\n",
"2. Nothing Was the Same\n",
"3. If You're Reading This It's Too Late (rumored to be a mixtape or album)\n",
"4. Certified Lover Boy\n",
"5. Honestly, Nevermind\n"
]
}
],
"source": [
"from llama_index.core.query_engine import SubQuestionQueryEngine\n",
"\n",
"query_engine = SubQuestionQueryEngine.from_defaults(\n",
" [drake_tool, kendrick_tool],\n",
" llm=llm_replicate, # llama3-70b\n",
" verbose=True,\n",
")\n",
"\n",
"response = query_engine.query(\"Which albums did Drake release in his career?\")\n",
"\n",
"print(response)"
]
},
{
"cell_type": "markdown",
"id": "a795f0bc-e871-4580-8983-6fb27d421fc5",
"metadata": {},
"source": [
"## 4. Text-to-SQL \n",
"\n",
"Here, we download and use a sample SQLite database with 11 tables, with various info about music, playlists, and customers. We will limit to a select few tables for this test."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a5096501-92c3-41af-a871-ade869d710fb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--2024-05-10 23:40:37-- https://www.sqlitetutorial.net/wp-content/uploads/2018/03/chinook.zip\n",
"Resolving www.sqlitetutorial.net (www.sqlitetutorial.net)... 2606:4700:3037::6815:1e8d, 2606:4700:3037::ac43:acfa, 104.21.30.141, ...\n",
"Connecting to www.sqlitetutorial.net (www.sqlitetutorial.net)|2606:4700:3037::6815:1e8d|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 305596 (298K) [application/zip]\n",
"Saving to: ‘./data/chinook.zip’\n",
"\n",
"./data/chinook.zip 100%[===================>] 298.43K --.-KB/s in 0.02s \n",
"\n",
"2024-05-10 23:40:37 (13.9 MB/s) - ‘./data/chinook.zip’ saved [305596/305596]\n",
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
"To disable this warning, you can either:\n",
"\t- Avoid using `tokenizers` before the fork if possible\n",
"\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Archive: ./data/chinook.zip\n",
" inflating: chinook.db \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n",
"To disable this warning, you can either:\n",
"\t- Avoid using `tokenizers` before the fork if possible\n",
"\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n"
]
}
],
"source": [
"!wget \"https://www.sqlitetutorial.net/wp-content/uploads/2018/03/chinook.zip\" -O \"./data/chinook.zip\"\n",
"!unzip \"./data/chinook.zip\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d4db989e-c18d-4416-928e-7be4ead4d869",
"metadata": {},
"outputs": [],
"source": [
"from sqlalchemy import (\n",
" create_engine,\n",
" MetaData,\n",
" Table,\n",
" Column,\n",
" String,\n",
" Integer,\n",
" select,\n",
" column,\n",
")\n",
"\n",
"engine = create_engine(\"sqlite:///chinook.db\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bf6ed233-0ea3-4d4f-8c33-5b6d558b89b9",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core import SQLDatabase\n",
"\n",
"sql_database = SQLDatabase(engine)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "debae423-1004-40f6-9356-e1c3add4d965",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core.indices.struct_store import NLSQLTableQueryEngine\n",
"\n",
"query_engine = NLSQLTableQueryEngine(\n",
" sql_database=sql_database,\n",
" tables=[\"albums\", \"tracks\", \"artists\"],\n",
" llm=llm_replicate,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a65ecd70-09c4-4872-b712-3a8235d03db2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Here are 10 album titles with their corresponding artists:\n",
"\n",
"1. \"For Those About To Rock We Salute You\" by Artist 1\n",
"2. \"Balls to the Wall\" by Artist 2\n",
"3. \"Restless and Wild\" by Artist 2\n",
"4. \"Let There Be Rock\" by Artist 1\n",
"5. \"Big Ones\" by Artist 3\n",
"6. \"Jagged Little Pill\" by Artist 4\n",
"7. \"Facelift\" by Artist 5\n",
"8. \"Warner 25 Anos\" by Artist 6\n",
"9. \"Plays Metallica By Four Cellos\" by Artist 7\n",
"10. \"Audioslave\" by Artist 8\n"
]
}
],
"source": [
"response = query_engine.query(\"What are some albums?\")\n",
"\n",
"print(response)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c12b93ef-d6d1-4d15-9cb2-343070f72851",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Here are 5 artists: AC/DC, Accept, Aerosmith, Alanis Morissette, and Alice In Chains.\n"
]
}
],
"source": [
"response = query_engine.query(\"What are some artists? Limit it to 5.\")\n",
"\n",
"print(response)"
]
},
{
"cell_type": "markdown",
"id": "2c243d38-c6ac-445c-b9d4-53a9ae013b7b",
"metadata": {},
"source": [
"This last query should be a more complex join"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "553741c2-1050-445d-979a-ae2150ee3248",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Here are three tracks from the legendary Australian rock band AC/DC: \"For Those About To Rock (We Salute You)\", \"Put The Finger On You\", and \"Let's Get It Up\".\n"
]
}
],
"source": [
"response = query_engine.query(\n",
" \"What are some tracks from the artist AC/DC? Limit it to 3\"\n",
")\n",
"\n",
"print(response)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "300689d7-9e67-4404-9898-27404ee6d4b5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SELECT tracks.Name FROM tracks JOIN albums ON tracks.AlbumId = albums.AlbumId JOIN artists ON albums.ArtistId = artists.ArtistId WHERE artists.Name = 'AC/DC' LIMIT 3;\n"
]
}
],
"source": [
"print(response.metadata[\"sql_query\"])"
]
},
{
"cell_type": "markdown",
"id": "1419fe67-aa6a-47db-88cd-9bb251c15615",
"metadata": {},
"source": [
"## 5. Structured Data Extraction\n",
"\n",
"An important use case for function calling is extracting structured objects. LlamaIndex provides an intuitive interface for this through `structured_predict` - simply define the target Pydantic class (can be nested), and given a prompt, we extract out the desired object.\n",
"\n",
"**NOTE**: Since there's no native function calling support with Llama3 / Ollama, the structured extraction is performed by prompting the LLM + output parsing."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4432f35a-5f29-45e9-a928-32e6d77b158e",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.llms.ollama import Ollama\n",
"from llama_index.core.prompts import PromptTemplate\n",
"from pydantic import BaseModel\n",
"\n",
"\n",
"class Restaurant(BaseModel):\n",
" \"\"\"A restaurant with name, city, and cuisine.\"\"\"\n",
"\n",
" name: str\n",
" city: str\n",
" cuisine: str\n",
"\n",
"\n",
"llm = Ollama(model=\"llama3\")\n",
"prompt_tmpl = PromptTemplate(\n",
" \"Generate a restaurant in a given city {city_name}\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2c451f52-a051-4ba2-a683-0c1fd258d986",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"name='Tropical Bites' city='Miami' cuisine='Caribbean'\n"
]
}
],
"source": [
"restaurant_obj = llm.structured_predict(\n",
" Restaurant, prompt_tmpl, city_name=\"Miami\"\n",
")\n",
"print(restaurant_obj)"
]
},
{
"cell_type": "markdown",
"id": "839018a9-b65f-4824-83f7-2e4e52b55c5d",
"metadata": {},
"source": [
"## 6. Adding Chat History to RAG (Chat Engine)\n",
"\n",
"In this section we create a stateful chatbot from a RAG pipeline, with our chat engine abstraction.\n",
"\n",
"Unlike a stateless query engine, the chat engine maintains conversation history (through a memory module like buffer memory). It performs retrieval given a condensed question, and feeds the condensed question + context + chat history into the final LLM prompt.\n",
"\n",
"Related resource: https://docs.llamaindex.ai/en/stable/examples/chat_engine/chat_engine_condense_plus_context/"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "27e56315-9513-4b32-bf9a-ce97c3ab52df",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core.memory import ChatMemoryBuffer\n",
"from llama_index.core.chat_engine import CondensePlusContextChatEngine\n",
"\n",
"memory = ChatMemoryBuffer.from_defaults(token_limit=3900)\n",
"\n",
"chat_engine = CondensePlusContextChatEngine.from_defaults(\n",
" index.as_retriever(),\n",
" memory=memory,\n",
" llm=llm,\n",
" context_prompt=(\n",
" \"You are a chatbot, able to have normal interactions, as well as talk\"\n",
" \" about the Kendrick and Drake beef.\"\n",
" \"Here are the relevant documents for the context:\\n\"\n",
" \"{context_str}\"\n",
" \"\\nInstruction: Use the previous chat history, or the context above, to interact and help the user.\"\n",
" ),\n",
" verbose=True,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b24524d2-fdce-4237-8ecc-67f139302303",
"metadata": {},
"outputs": [],
"source": [
"response = chat_engine.chat(\n",
" \"Tell me about the songs Drake released in the beef.\"\n",
")\n",
"print(str(response))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f9a87a16-2864-4c48-95e7-a2103e119242",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Kendrick Lamar's contributions to the beef!\n",
"\n",
"According to the article, Kendrick released several diss tracks in response to Drake's initial shots. One notable track is \"Not Like Us\", which directly addresses Drake and his perceived shortcomings.\n",
"\n",
"However, the article highlights that Kendrick's most significant response was his album \"Mr. Morale & The Big Steppers\", which features several tracks that can be seen as indirect disses towards Drake.\n",
"\n",
"The article also mentions that Kendrick's family has been a target of Drake's attacks, with Drake referencing Kendrick's estranged relationship with his partner Whitney and their two kids (one of whom is allegedly fathered by Dave Free).\n",
"\n",
"It's worth noting that Kendrick didn't directly respond to Drake's THP6 track. Instead, he focused on his own music and let the lyrics speak for themselves.\n",
"\n",
"Overall, Kendrick's approach was more subtle yet still packed a punch, showcasing his storytelling ability and lyrical prowess.\n",
"\n",
"Would you like me to elaborate on any specific tracks or moments from the beef?\n"
]
}
],
"source": [
"response = chat_engine.chat(\"What about Kendrick?\")\n",
"print(str(response))"
]
},
{
"cell_type": "markdown",
"id": "a7fa07ed-58f0-445e-bbd3-4ad8bac6598e",
"metadata": {},
"source": [
"## 7. Agents\n",
"\n",
"Here we build agents with Llama 3. We perform RAG over simple functions as well as the documents above."
]
},
{
"cell_type": "markdown",
"id": "aa98d735-5d43-413f-aab3-fc3adeed81b1",
"metadata": {},
"source": [
"### Agents And Tools"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fb73a01f-8a2e-4dd6-91f8-710c92b81c56",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"from typing import Sequence, List\n",
"\n",
"from llama_index.core.llms import ChatMessage\n",
"from llama_index.core.tools import BaseTool, FunctionTool\n",
"from llama_index.core.agent import ReActAgent\n",
"\n",
"import nest_asyncio\n",
"\n",
"nest_asyncio.apply()"
]
},
{
"cell_type": "markdown",
"id": "efbee832-9786-4551-93f2-01ee90fa0f4d",
"metadata": {},
"source": [
"### Define Tools"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b2058b36-8053-4dc8-9218-c286702ecf66",
"metadata": {},
"outputs": [],
"source": [
"def multiply(a: int, b: int) -> int:\n",
" \"\"\"Multiple two integers and returns the result integer\"\"\"\n",
" return a * b\n",
"\n",
"\n",
"def add(a: int, b: int) -> int:\n",
" \"\"\"Add two integers and returns the result integer\"\"\"\n",
" return a + b\n",
"\n",
"\n",
"def subtract(a: int, b: int) -> int:\n",
" \"\"\"Subtract two integers and returns the result integer\"\"\"\n",
" return a - b\n",
"\n",
"\n",
"def divide(a: int, b: int) -> int:\n",
" \"\"\"Divides two integers and returns the result integer\"\"\"\n",
" return a / b\n",
"\n",
"\n",
"multiply_tool = FunctionTool.from_defaults(fn=multiply)\n",
"add_tool = FunctionTool.from_defaults(fn=add)\n",
"subtract_tool = FunctionTool.from_defaults(fn=subtract)\n",
"divide_tool = FunctionTool.from_defaults(fn=divide)"
]
},
{
"cell_type": "markdown",
"id": "22d7d4dc-e2ce-402c-9350-0e7010d0080c",
"metadata": {},
"source": [
"### ReAct Agent"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "72a48053-e30d-4884-bcac-80752047d940",
"metadata": {},
"outputs": [],
"source": [
"agent = ReActAgent.from_tools(\n",
" [multiply_tool, add_tool, subtract_tool, divide_tool],\n",
" llm=llm_replicate,\n",
" verbose=True,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "7ada828a-3b05-4fc1-90e8-986c5607ae61",
"metadata": {},
"source": [
"### Querying"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c0b1e56-d9f7-4615-a15a-c91fea1adb00",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;3;38;5;200mThought: The current language of the user is: English. I need to use a tool to help me answer the question.\n",
"Action: add\n",
"Action Input: {'a': 121, 'b': 2}\n",
"\u001b[0m\u001b[1;3;34mObservation: 123\n",
"\u001b[0m\u001b[1;3;38;5;200mThought: I have the result of the addition, now I need to multiply it by 5.\n",
"Action: multiply\n",
"Action Input: {'a': 123, 'b': 5}\n",
"\u001b[0m\u001b[1;3;34mObservation: 615\n",
"\u001b[0m\u001b[1;3;38;5;200mThought: I can answer without using any more tools. I'll use the user's language to answer\n",
"Answer: 615\n",
"\u001b[0m615\n"
]
}
],
"source": [
"response = agent.chat(\"What is (121 + 2) * 5?\")\n",
"print(str(response))"
]
},
{
"cell_type": "markdown",
"id": "67ce45f6-bdd4-42aa-8f74-43a50f14094e",
"metadata": {},
"source": [
"### ReAct Agent With RAG QueryEngine Tools"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97fce5f1-eacf-4ecc-9e83-072e74d3a2a9",
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core import (\n",
" SimpleDirectoryReader,\n",
" VectorStoreIndex,\n",
" StorageContext,\n",
" load_index_from_storage,\n",
")\n",
"\n",
"from llama_index.core.tools import QueryEngineTool, ToolMetadata"
]
},
{
"cell_type": "markdown",
"id": "23963d00-e3d2-4ce1-9ac3-aa486bf4b1a5",
"metadata": {},
"source": [
"### Create ReAct Agent using RAG QueryEngine Tools"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0e241fe9-f390-4be5-b3c4-da4f56db01ef",
"metadata": {},
"outputs": [],
"source": [
"drake_tool = QueryEngineTool(\n",
" drake_index.as_query_engine(),\n",
" metadata=ToolMetadata(\n",
" name=\"drake_search\",\n",
" description=\"Useful for searching over Drake's life.\",\n",
" ),\n",
")\n",
"\n",
"kendrick_tool = QueryEngineTool(\n",
" kendrick_index.as_query_engine(),\n",
" metadata=ToolMetadata(\n",
" name=\"kendrick_search\",\n",
" description=\"Useful for searching over Kendrick's life.\",\n",
" ),\n",
")\n",
"\n",
"query_engine_tools = [drake_tool, kendrick_tool]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b922feac-b221-4737-92c6-e63eeab4eab7",
"metadata": {},
"outputs": [],
"source": [
"agent = ReActAgent.from_tools(\n",
" query_engine_tools, ## TODO: define query tools\n",
" llm=llm_replicate,\n",
" verbose=True,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "7e38edc8-47f8-4f1a-ad87-bc3a9e31a65e",
"metadata": {},
"source": [
"### Querying"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "035c2c8b-5a5e-4df0-a423-4c2d6054f457",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;3;38;5;200mThought: The current language of the user is: English. I need to use a tool to help me answer the question.\n",
"Action: kendrick_search\n",
"Action Input: {'input': \"Kendrick Lamar's childhood\"}\n",
"\u001b[0m\u001b[1;3;34mObservation: Kendrick Lamar was born on June 17, 1987, in Compton, California. He is the first child of Kenneth \"Kenny\" Duckworth, a former gang hustler who previously worked at KFC, and Paula Oliver, a hairdresser who previously worked at McDonald's. Both of his parents are African Americans from the South Side of Chicago, and they relocated to Compton in 1984 due to his father's affiliation with the Gangster Disciples. Lamar was named after singer-songwriter Eddie Kendricks of the Temptations. He was an only child until the age of seven and was described as a loner by his mother.\n",
"\u001b[0m\u001b[1;3;38;5;200mThought: I have information about Kendrick's childhood, but I need to know more about Drake's upbringing to answer the question.\n",
"Action: drake_search\n",
"Action Input: {'input': \"Drake's childhood\"}\n",
"\u001b[0m\u001b[1;3;34mObservation: Drake was raised in two neighborhoods. He lived on Weston Road in Toronto's working-class west end until grade six and attended Weston Memorial Junior Public School until grade four. He moved to one of the city's affluent neighbourhoods, Forest Hill, in 2000. Drake appeared in a comedic sketch which aired during the 1997 NHL Awards, featuring Martin Brodeur and Ron Hextall. At age 10, he attended Forest Hill Collegiate Institute for high school.\n",
"\u001b[0m\u001b[1;3;34mObservation: Error: Could not parse output. Please follow the thought-action-input format. Try again.\n",
"\u001b[0m\u001b[1;3;38;5;200mThought: I apologize for the mistake. I need to use a tool to help me answer the question.\n",
"Action: drake_search\n",
"Action Input: {'input': \"Drake's childhood\"}\n",
"\u001b[0m\u001b[1;3;34mObservation: Drake was raised in two neighborhoods. He lived on Weston Road in Toronto's working-class west end until grade six and attended Weston Memorial Junior Public School until grade four. He played minor hockey with the Weston Red Wings, reaching the Upper Canada College hockey camp before leaving due to a vicious cross-check to his neck during a game. At age 10, Drake appeared in a comedic sketch which aired during the 1997 NHL Awards.\n",
"\u001b[0m\u001b[1;3;38;5;200mThought: I have information about both Kendrick and Drake's childhood, so I can answer the question without using any more tools.\n",
"Answer: Kendrick Lamar grew up in Compton, California, as the child of a former gang hustler and a hairdresser, while Drake was raised in two neighborhoods in Toronto, Ontario, Canada, and had a brief experience in minor hockey before pursuing a career in entertainment.\n",
"\u001b[0mKendrick Lamar grew up in Compton, California, as the child of a former gang hustler and a hairdresser, while Drake was raised in two neighborhoods in Toronto, Ontario, Canada, and had a brief experience in minor hockey before pursuing a career in entertainment.\n"
]
}
],
"source": [
"response = agent.chat(\"Tell me about how Kendrick and Drake grew up\")\n",
"print(str(response))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "llama_index_v3",
"language": "python",
"name": "llama_index_v3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
{
"cells": [
{
"cell_type": "markdown",
"id": "e8cba0b6",
"metadata": {},
"source": [
"<a href=\"https://colab.research.google.com/github/meta-llama/llama-recipes/blob/main/recipes/use_cases/text2sql/StructuredLlama.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a> \n",
"\n",
"## Use Llama 3 to chat about structured data\n",
"This demo shows how to use LangChain with Llama 3 to query structured data, the 2023-24 NBA roster info, stored in a SQLite DB, and how to ask Llama 3 follow up question about the DB."
]
},
{
"cell_type": "markdown",
"id": "f839d07d",
"metadata": {},
"source": [
"We start by installing the necessary packages:\n",
"- [Replicate](https://replicate.com/) to host the Llama 3 model\n",
"- [langchain](https://python.langchain.com/docs/get_started/introduction) provides necessary RAG tools for this demo\n",
"\n",
"**Note** We will be using [Replicate](https://replicate.com/meta/meta-llama-3-8b-instruct) to run the examples here. You will need to first sign in with Replicate with your github account, then create a free API token [here](https://replicate.com/account/api-tokens) that you can use for a while. You can also use other Llama 3 cloud providers such as [Groq](https://console.groq.com/), [Together](https://api.together.xyz/playground/language/meta-llama/Llama-3-8b-hf), or [Anyscale](https://app.endpoints.anyscale.com/playground) - see Section 2 of the Getting to Know Llama [notebook](https://github.com/meta-llama/llama-recipes/blob/main/recipes/quickstart/Getting_to_know_Llama.ipynb) for more information.\n",
"\n",
"If you'd like to run Llama 3 locally for the benefits of privacy, no cost or no rate limit (some Llama 3 hosting providers set limits for free plan of queries or tokens per second or minute), see [Running Llama Locally](https://github.com/meta-llama/llama-recipes/blob/main/recipes/quickstart/Running_Llama2_Anywhere/Running_Llama_on_Mac_Windows_Linux.ipynb)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "33fb3190-59fb-4edd-82dd-f20f6eab3e47",
"metadata": {},
"outputs": [],
"source": [
"!pip install langchain replicate"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fa4562d3",
"metadata": {},
"outputs": [],
"source": [
"from getpass import getpass\n",
"import os\n",
"\n",
"REPLICATE_API_TOKEN = getpass()\n",
"os.environ[\"REPLICATE_API_TOKEN\"] = REPLICATE_API_TOKEN"
]
},
{
"cell_type": "markdown",
"id": "1e586b75",
"metadata": {},
"source": [
"Next we call the Llama 3 8b chat model from Replicate. You can also use Llama 3 70b model by replacing the `model` name with \"meta/meta-llama-3-70b-instruct\"."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9dcd744c",
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.llms import Replicate\n",
"llm = Replicate(\n",
" model=\"meta/meta-llama-3-8b-instruct\",\n",
" model_kwargs={\"temperature\": 0.0, \"top_p\": 1, \"max_new_tokens\":500}\n",
")"
]
},
{
"cell_type": "markdown",
"id": "6d421ae7",
"metadata": {},
"source": [
"To recreate the `nba_roster.db` file, run the two commands below:\n",
"- `python txt2csv.py` to convert the `nba.txt` file to `nba_roster.csv`. The `nba.txt` file was created by scraping the NBA roster info from the web.\n",
"- `python csv2db.py` to convert `nba_roster.csv` to `nba_roster.db`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3bb99f39-cd7a-4db6-91dd-02f3bf80347c",
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.utilities import SQLDatabase\n",
"\n",
"# Note: to run in Colab, you need to upload the nba_roster.db file in the repo to the Colab folder first.\n",
"db = SQLDatabase.from_uri(\"sqlite:///nba_roster.db\", sample_rows_in_table_info=0)\n",
"\n",
"def get_schema():\n",
" return db.get_table_info()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8d793ce7-324b-4861-926c-54973d7c9b43",
"metadata": {},
"outputs": [],
"source": [
"question = \"What team is Klay Thompson on?\"\n",
"prompt = f\"\"\"Based on the table schema below, write a SQL query that would answer the user's question; just return the SQL query and nothing else.\n",
"\n",
"Scheme:\n",
"{get_schema()}\n",
"\n",
"Question: {question}\n",
"\n",
"SQL Query:\"\"\"\n",
"\n",
"print(prompt)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "70776558",
"metadata": {},
"outputs": [],
"source": [
"answer = llm.invoke(prompt)\n",
"print(answer)"
]
},
{
"cell_type": "markdown",
"id": "afcf423a",
"metadata": {},
"source": [
"If you don't have the \"just return the SQL query and nothing else\" in the prompt above, or even with it but asking Llama 2 which doesn't follow instructions as well as Llama 3, you'll likely get more text other than the SQL query back in the answer."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "62472ce6-794b-4a61-b88c-a1e031e28e4e",
"metadata": {},
"outputs": [],
"source": [
"# note this is a dangerous operation and for demo purpose only; in production app you'll need to safe-guard any DB operation\n",
"result = db.run(answer)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "39ed4bc3",
"metadata": {},
"outputs": [],
"source": [
"# how about a follow up question\n",
"follow_up = \"What's his salary?\"\n",
"print(llm.invoke(follow_up))"
]
},
{
"cell_type": "markdown",
"id": "98b2c523",
"metadata": {},
"source": [
"Since we did not pass any context along with the follow-up to the model it did not know who \"his\" is and just picked LeBron James.\n",
"\n",
"Let's try to fix it by adding context to the follow-up prompt."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0c305278-29d2-4e88-9b3d-ad67c94ce0f2",
"metadata": {},
"outputs": [],
"source": [
"prompt = f\"\"\"Based on the table schema, question, SQL query, and SQL response below, write a new SQL response; be concise, just output the SQL response.\n",
"\n",
"Scheme:\n",
"{get_schema()}\n",
"\n",
"Question: {follow_up}\n",
"SQL Query: {question}\n",
"SQL Result: {result}\n",
"\n",
"New SQL Response:\n",
"\"\"\"\n",
"print(prompt)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "03739b96-e607-4fa9-bc5c-df118198dc7f",
"metadata": {},
"outputs": [],
"source": [
"new_answer = llm.invoke(prompt)\n",
"print(new_answer)"
]
},
{
"cell_type": "markdown",
"id": "c782abb6-3b44-45be-8694-70fc29b82523",
"metadata": {},
"source": [
"Because we have \"be concise, just output the SQL response\", Llama 3 is able to just generate the SQL statement; otherwise output parsing will be needed."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6ecfca53-be7e-4668-bad1-5ca7571817d7",
"metadata": {},
"outputs": [],
"source": [
"db.run(new_answer)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
import sqlite3
import csv
# Define the input CSV file and the SQLite database file
input_csv = 'nba_roster.csv'
database_file = 'nba_roster.db'
# Connect to the SQLite database
conn = sqlite3.connect(database_file)
cursor = conn.cursor()
# Create a table to store the data
cursor.execute('''CREATE TABLE IF NOT EXISTS nba_roster (
Team TEXT,
NAME TEXT,
Jersey TEXT,
POS TEXT,
AGE INT,
HT TEXT,
WT TEXT,
COLLEGE TEXT,
SALARY TEXT
)''')
# Read data from the CSV file and insert it into the SQLite table
with open(input_csv, 'r', newline='') as csvfile:
csv_reader = csv.reader(csvfile)
next(csv_reader) # Skip the header row
for row in csv_reader:
cursor.execute('INSERT INTO nba_roster VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', row)
# Commit the changes and close the database connection
conn.commit()
conn.close()
print(f'Data from {input_csv} has been successfully imported into {database_file}')
Atlanta Hawks Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4397136.png
Saddiq Bey41 SF 24 6' 7" 215 lbs Villanova $4,556,983
https://a.espncdn.com/i/headshots/nba/players/full/3037789.png
Bogdan Bogdanovic13 SG 31 6' 5" 225 lbs -- $18,700,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Kobe Bufkin G 20 6' 4" 195 lbs Michigan $4,094,280
https://a.espncdn.com/i/headshots/nba/players/full/3102529.png
Clint Capela15 C 29 6' 10" 256 lbs -- $20,616,000
https://a.espncdn.com/i/headshots/nba/players/full/4277952.png
Bruno Fernando0 PF 25 6' 10" 240 lbs Maryland $2,581,522
https://a.espncdn.com/i/headshots/nba/players/full/4065656.png
Trent Forrest2 G 25 6' 4" 210 lbs Florida State --
https://a.espncdn.com/i/headshots/nba/players/full/4432585.png
AJ Griffin14 F 20 6' 6" 222 lbs Duke $3,712,920
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Mouhamed Gueye F 20 6' 11" 210 lbs Washington State $1,119,563
https://a.espncdn.com/i/headshots/nba/players/full/4065732.png
De'Andre Hunter12 SF 25 6' 8" 221 lbs Virginia $20,089,286
https://a.espncdn.com/i/headshots/nba/players/full/4701230.png
Jalen Johnson1 SF 21 6' 8" 219 lbs Duke $2,925,360
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jarkel Joiner G 24 6' 1" 180 lbs NC State --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Seth Lundy G 23 6' 6" 220 lbs Penn State --
https://a.espncdn.com/i/headshots/nba/players/full/3913180.png
Garrison Mathews25 SG 26 6' 6" 215 lbs Lipscomb $2,000,000
https://a.espncdn.com/i/headshots/nba/players/full/4032.png
Wesley Matthews23 SG 36 6' 4" 220 lbs Marquette $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/4004.png
Patty Mills8 PG 35 6' 0" 180 lbs Saint Mary's $6,802,950
https://a.espncdn.com/i/headshots/nba/players/full/3907497.png
Dejounte Murray5 SG 27 6' 5" 180 lbs Washington $18,214,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Miles Norris F 23 6' 10" 220 lbs UC Santa Barbara --
https://a.espncdn.com/i/headshots/nba/players/full/4431680.png
Onyeka Okongwu17 PF 22 6' 9" 240 lbs USC $8,109,063
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Keaton Wallace G 24 6' 3" 185 lbs UTSA --
https://a.espncdn.com/i/headshots/nba/players/full/4277905.png
Trae Young11 PG 25 6' 1" 164 lbs Oklahoma $40,064,220
Boston Celtics Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4397885.png
Dalano Banton G 23 6' 7" 204 lbs Nebraska $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/4278031.png
Oshae Brissett12 SF 25 6' 7" 210 lbs Syracuse $2,165,000
https://a.espncdn.com/i/headshots/nba/players/full/2566769.png
Malcolm Brogdon13 PG 30 6' 4" 229 lbs Virginia $22,500,000
https://a.espncdn.com/i/headshots/nba/players/full/3917376.png
Jaylen Brown7 SG 26 6' 6" 223 lbs California $31,830,357
https://a.espncdn.com/i/headshots/nba/players/full/4432907.png
Justin Champagnie99 SF 22 6' 6" 206 lbs Pittsburgh --
https://a.espncdn.com/i/headshots/nba/players/full/4576085.png
JD Davison20 SG 20 6' 1" 195 lbs Alabama --
https://a.espncdn.com/i/headshots/nba/players/full/3989.png
Blake Griffin91 PF 34 6' 9" 250 lbs Oklahoma --
https://a.espncdn.com/i/headshots/nba/players/full/4065804.png
Sam Hauser30 SF 25 6' 7" 217 lbs Virginia $1,927,896
https://a.espncdn.com/i/headshots/nba/players/full/3213.png
Al Horford42 C 37 6' 9" 240 lbs Florida $10,000,000
https://a.espncdn.com/i/headshots/nba/players/full/3064560.png
Luke Kornet40 C 28 7' 2" 250 lbs Vanderbilt $2,413,304
https://a.espncdn.com/i/headshots/nba/players/full/3133602.png
Svi Mykhailiuk SG 26 6' 7" 205 lbs Kansas $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/3102531.png
Kristaps Porzingis C 28 7' 3" 240 lbs -- $36,016,200
https://a.espncdn.com/i/headshots/nba/players/full/4066354.png
Payton Pritchard11 PG 25 6' 1" 195 lbs Oregon $4,037,278
https://a.espncdn.com/i/headshots/nba/players/full/4397424.png
Neemias Queta C 24 7' 0" 245 lbs Utah State $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/4065648.png
Jayson Tatum0 SF 25 6' 8" 210 lbs Duke $32,600,060
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jordan Walsh G 19 6' 7" 205 lbs Arkansas $1,119,563
https://a.espncdn.com/i/headshots/nba/players/full/3078576.png
Derrick White9 PG 29 6' 4" 190 lbs Colorado $18,357,143
https://a.espncdn.com/i/headshots/nba/players/full/4066211.png
Robert Williams III44 C 25 6' 9" 237 lbs Texas A&M $11,571,429
Brooklyn Nets Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4423545.png
Darius Bazley PF 23 6' 9" 216 lbs -- $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/3147657.png
Mikal Bridges1 SF 27 6' 6" 209 lbs Villanova $21,700,000
https://a.espncdn.com/i/headshots/nba/players/full/4278067.png
Nic Claxton33 C 24 6' 11" 215 lbs Georgia $9,625,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Noah Clowney F 19 6' 10" 210 lbs Alabama $3,089,520
https://a.espncdn.com/i/headshots/nba/players/full/2580782.png
Spencer Dinwiddie26 PG 30 6' 6" 215 lbs Colorado $20,357,143
https://a.espncdn.com/i/headshots/nba/players/full/2578185.png
Dorian Finney-Smith28 PF 30 6' 7" 220 lbs Florida $13,932,008
https://a.espncdn.com/i/headshots/nba/players/full/3138196.png
Cameron Johnson2 SF 27 6' 8" 210 lbs North Carolina $25,679,348
https://a.espncdn.com/i/headshots/nba/players/full/2583632.png
Royce O'Neale00 PF 30 6' 6" 226 lbs Baylor $9,500,000
https://a.espncdn.com/i/headshots/nba/players/full/4432194.png
Day'Ron Sharpe20 C 21 6' 9" 265 lbs North Carolina $2,210,040
https://a.espncdn.com/i/headshots/nba/players/full/3907387.png
Ben Simmons10 PG 27 6' 10" 240 lbs LSU $37,893,408
https://a.espncdn.com/i/headshots/nba/players/full/4065697.png
Dennis Smith Jr. PG 25 6' 2" 205 lbs NC State $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/4432174.png
Cam Thomas24 SG 21 6' 3" 210 lbs LSU $2,240,160
https://a.espncdn.com/i/headshots/nba/players/full/4277890.png
Lonnie Walker IV G 24 6' 4" 204 lbs Miami $2,019,706
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Dariq Whitehead F 19 6' 7" 220 lbs Duke $2,966,040
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jalen Wilson F 22 6' 8" 225 lbs Kansas --
Charlotte Hornets Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Angelo Allegri16 F 24 6' 7" 215 lbs Eastern Washington --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Amari Bailey G 19 6' 5" 185 lbs UCLA --
https://a.espncdn.com/i/headshots/nba/players/full/4432816.png
LaMelo Ball1 PG 22 6' 7" 180 lbs -- $10,900,635
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Leaky Black F 24 6' 9" 205 lbs North Carolina --
https://a.espncdn.com/i/headshots/nba/players/full/4431712.png
James Bouknight2 SG 23 6' 4" 190 lbs UConn $4,570,080
https://a.espncdn.com/i/headshots/nba/players/full/4066383.png
Miles Bridges0 SF 25 6' 7" 225 lbs Michigan State $7,921,301
https://a.espncdn.com/i/headshots/nba/players/full/4249.png
Gordon Hayward20 SF 33 6' 7" 225 lbs Butler $31,500,000
https://a.espncdn.com/i/headshots/nba/players/full/4431699.png
Kai Jones23 PF 22 6' 11" 221 lbs Texas $3,047,880
https://a.espncdn.com/i/headshots/nba/players/full/4683027.png
Theo Maledon9 PG 22 6' 5" 175 lbs -- --
https://a.espncdn.com/i/headshots/nba/players/full/3138161.png
Cody Martin11 SF 27 6' 6" 205 lbs Nevada $7,560,000
https://a.espncdn.com/i/headshots/nba/players/full/4576086.png
Bryce McGowens7 G 20 6' 6" 175 lbs Nebraska $1,719,865
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Nathan Mensah31 C 25 6' 10" 230 lbs San Diego State --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Brandon Miller F 20 6' 9" 200 lbs Alabama $10,880,400
https://a.espncdn.com/i/headshots/nba/players/full/5144059.png
James Nnaji C 19 6' 11" 250 lbs -- --
https://a.espncdn.com/i/headshots/nba/players/full/4230547.png
Frank Ntilikina PG 25 6' 4" 200 lbs -- $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/3133603.png
Kelly Oubre Jr.12 SG 27 6' 6" 203 lbs Kansas --
https://a.espncdn.com/i/headshots/nba/players/full/4278076.png
Nick Richards4 C 25 7' 0" 245 lbs Kentucky $5,000,000
https://a.espncdn.com/i/headshots/nba/players/full/3074752.png
Terry Rozier3 SG 29 6' 1" 190 lbs Louisville $22,205,221
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Trevon Scott18 F 26 6' 8" 225 lbs Cincinnati --
https://a.espncdn.com/i/headshots/nba/players/full/4397570.png
Jaylen Sims30 G 24 6' 6" 210 lbs UNC Wilmington --
https://a.espncdn.com/i/headshots/nba/players/full/4683686.png
Nick Smith Jr. G 19 6' 4" 170 lbs Arkansas $2,463,960
https://a.espncdn.com/i/headshots/nba/players/full/4702233.png
JT Thor21 F 21 6' 9" 203 lbs Auburn $1,836,096
https://a.espncdn.com/i/headshots/nba/players/full/4278078.png
P.J. Washington25 PF 25 6' 7" 230 lbs Kentucky $16,847,826
https://a.espncdn.com/i/headshots/nba/players/full/4701232.png
Mark Williams5 C 21 7' 0" 240 lbs Duke $3,908,160
Chicago Bulls Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4066421.png
Lonzo Ball2 PG 25 6' 6" 190 lbs UCLA $20,465,117
https://a.espncdn.com/i/headshots/nba/players/full/3133635.png
Jevon Carter PG 28 6' 1" 200 lbs West Virginia $6,190,476
https://a.espncdn.com/i/headshots/nba/players/full/2991350.png
Alex Caruso6 SG 29 6' 5" 186 lbs Texas A&M $9,460,000
https://a.espncdn.com/i/headshots/nba/players/full/2528693.png
Torrey Craig0 SF 32 6' 7" 221 lbs South Carolina Upstate $2,528,233
https://a.espncdn.com/i/headshots/nba/players/full/3978.png
DeMar DeRozan11 SF 34 6' 6" 220 lbs USC $28,600,000
https://a.espncdn.com/i/headshots/nba/players/full/4397002.png
Ayo Dosunmu12 SG 23 6' 5" 200 lbs Illinois $6,481,481
https://a.espncdn.com/i/headshots/nba/players/full/6585.png
Andre Drummond3 C 30 6' 11" 279 lbs UConn $3,360,000
https://a.espncdn.com/i/headshots/nba/players/full/2596112.png
Javonte Green24 SF 30 6' 5" 205 lbs Radford --
https://a.espncdn.com/i/headshots/nba/players/full/4067735.png
Carlik Jones22 G 25 6' 0" 174 lbs Louisville $1,922,896
https://a.espncdn.com/i/headshots/nba/players/full/3064440.png
Zach LaVine8 SG 28 6' 5" 200 lbs UCLA $40,064,220
https://a.espncdn.com/i/headshots/nba/players/full/4432239.png
Justin Lewis34 F 21 6' 7" 245 lbs Marquette --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Julian Phillips F 19 6' 8" 197 lbs Tennessee $1,600,000
https://a.espncdn.com/i/headshots/nba/players/full/4683622.png
Marko Simonovic19 C 23 7' 0" 220 lbs -- $1,836,096
https://a.espncdn.com/i/headshots/nba/players/full/4279815.png
Terry Taylor32 F 23 6' 4" 230 lbs Austin Peay $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/4433159.png
Dalen Terry25 F 21 6' 7" 200 lbs Arizona $3,350,760
https://a.espncdn.com/i/headshots/nba/players/full/6478.png
Nikola Vucevic9 C 32 6' 10" 260 lbs USC $18,518,519
https://a.espncdn.com/i/headshots/nba/players/full/4395651.png
Coby White0 PG 23 6' 5" 195 lbs North Carolina $11,111,111
https://a.espncdn.com/i/headshots/nba/players/full/4431687.png
Patrick Williams44 PF 22 6' 7" 215 lbs Florida State $9,835,881
Cleveland Cavaliers Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4066328.png
Jarrett Allen31 C 25 6' 9" 243 lbs Texas $20,000,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Emoni Bates21 F 19 6' 10" 170 lbs Eastern Michigan --
https://a.espncdn.com/i/headshots/nba/players/full/4432173.png
Sharife Cooper2 PG 22 6' 1" 176 lbs Auburn --
https://a.espncdn.com/i/headshots/nba/players/full/3947156.png
Mamadi Diakite21 F 26 6' 9" 228 lbs Virginia --
https://a.espncdn.com/i/headshots/nba/players/full/4396907.png
Darius Garland10 PG 23 6' 1" 192 lbs Vanderbilt $34,005,250
https://a.espncdn.com/i/headshots/nba/players/full/4065733.png
Ty Jerome SG 26 6' 5" 195 lbs Virginia $2,439,025
https://a.espncdn.com/i/headshots/nba/players/full/3064559.png
Damian Jones15 C 28 6' 11" 245 lbs Vanderbilt $2,586,665
https://a.espncdn.com/i/headshots/nba/players/full/2991043.png
Caris LeVert3 SG 29 6' 6" 205 lbs Michigan $15,384,616
https://a.espncdn.com/i/headshots/nba/players/full/4066757.png
Sam Merrill20 SG 27 6' 4" 205 lbs Utah State $1,997,238
https://a.espncdn.com/i/headshots/nba/players/full/3908809.png
Donovan Mitchell45 SG 27 6' 1" 215 lbs Louisville $33,162,030
https://a.espncdn.com/i/headshots/nba/players/full/4432158.png
Evan Mobley4 PF 22 6' 11" 215 lbs USC $8,882,760
https://a.espncdn.com/i/headshots/nba/players/full/4432815.png
Isaiah Mobley15 F 23 6' 8" 238 lbs USC --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Pete Nance48 F 23 6' 11" 230 lbs North Carolina --
https://a.espncdn.com/i/headshots/nba/players/full/2968361.png
Raul Neto19 PG 31 6' 2" 180 lbs -- --
https://a.espncdn.com/i/headshots/nba/players/full/2990969.png
Georges Niang SF 30 6' 7" 230 lbs Iowa State $8,800,000
https://a.espncdn.com/i/headshots/nba/players/full/4432822.png
Isaac Okoro35 SF 22 6' 5" 225 lbs Auburn $8,920,795
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Craig Porter Jr.40 G 23 6' 2" 186 lbs Wichita State --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Justin Powell G -- 6' 6" 197 lbs Washington State --
https://a.espncdn.com/i/headshots/nba/players/full/4011.png
Ricky Rubio13 PG 32 6' 2" 190 lbs -- $6,146,342
https://a.espncdn.com/i/headshots/nba/players/full/4065778.png
Max Strus31 SG 27 6' 5" 215 lbs DePaul $14,487,684
https://a.espncdn.com/i/headshots/nba/players/full/6474.png
Tristan Thompson13 C 32 6' 9" 254 lbs Texas --
https://a.espncdn.com/i/headshots/nba/players/full/3912848.png
Dean Wade32 PF 26 6' 9" 228 lbs Kansas State $5,709,877
Dallas Mavericks Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4432161.png
Greg Brown III36 PF 22 6' 8" 217 lbs Texas --
https://a.espncdn.com/i/headshots/nba/players/full/2326307.png
Seth Curry30 SG 33 6' 1" 190 lbs Duke $4,000,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Dexter Dennis38 G 24 6' 5" 210 lbs Texas A&M --
https://a.espncdn.com/i/headshots/nba/players/full/3945274.png
Luka Doncic77 PG 24 6' 7" 230 lbs -- $40,064,220
https://a.espncdn.com/i/headshots/nba/players/full/3102528.png
Dante Exum0 G 28 6' 5" 214 lbs -- $2,019,760
https://a.espncdn.com/i/headshots/nba/players/full/4432811.png
Josh Green8 SG 22 6' 6" 210 lbs Arizona $4,765,339
https://a.espncdn.com/i/headshots/nba/players/full/2528210.png
Tim Hardaway Jr.10 SF 31 6' 5" 205 lbs Michigan $17,897,728
https://a.espncdn.com/i/headshots/nba/players/full/4868423.png
Jaden Hardy1 G 21 6' 4" 198 lbs -- $1,719,864
https://a.espncdn.com/i/headshots/nba/players/full/2993370.png
Richaun Holmes20 F 29 6' 10" 240 lbs Bowling Green $12,046,020
https://a.espncdn.com/i/headshots/nba/players/full/6442.png
Kyrie Irving11 PG 31 6' 2" 191 lbs Duke $37,037,037
https://a.espncdn.com/i/headshots/nba/players/full/3936099.png
Derrick Jones Jr.55 SF 26 6' 6" 210 lbs UNLV $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/2960236.png
Maxi Kleber42 PF 31 6' 10" 240 lbs -- $11,000,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
A.J. Lawson9 G 23 6' 6" 185 lbs South Carolina --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Dereck Lively II2 C 19 7' 1" 234 lbs Duke $4,775,640
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Mike Miles Jr.14 G 21 6' 2" 205 lbs TCU --
https://a.espncdn.com/i/headshots/nba/players/full/6461.png
Markieff Morris88 PF 34 6' 9" 245 lbs Kansas --
https://a.espncdn.com/i/headshots/nba/players/full/2531367.png
Dwight Powell7 C 32 6' 10" 240 lbs Stanford $4,000,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Olivier-Maxence Prosper18 F 21 6' 8" 215 lbs Marquette $2,733,360
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jordan Walker16 SG 24 5' 11" 170 lbs UAB --
https://a.espncdn.com/i/headshots/nba/players/full/4397033.png
Joe Wieskamp37 SF 24 6' 6" 205 lbs Iowa $1,927,896
https://a.espncdn.com/i/headshots/nba/players/full/4066218.png
Grant Williams3 PF 24 6' 6" 236 lbs Tennessee $12,325,581
Denver Nuggets Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4431767.png
Christian Braun0 G 22 6' 6" 220 lbs Kansas $2,949,120
https://a.espncdn.com/i/headshots/nba/players/full/2581018.png
Kentavious Caldwell-Pope5 SG 30 6' 5" 204 lbs Georgia $14,704,938
https://a.espncdn.com/i/headshots/nba/players/full/4230557.png
Vlatko Cancar31 SF 26 6' 8" 236 lbs -- $2,234,359
https://a.espncdn.com/i/headshots/nba/players/full/4278585.png
Collin Gillespie21 G 24 6' 3" 190 lbs Villanova --
https://a.espncdn.com/i/headshots/nba/players/full/3064290.png
Aaron Gordon50 PF 28 6' 8" 235 lbs Arizona $22,266,182
https://a.espncdn.com/i/headshots/nba/players/full/2284101.png
Justin Holiday0 SF 34 6' 6" 180 lbs Washington $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/4065731.png
Jay Huff C 25 7' 1" 240 lbs Virginia --
https://a.espncdn.com/i/headshots/nba/players/full/6443.png
Reggie Jackson7 PG 33 6' 2" 208 lbs Boston College $5,000,000
https://a.espncdn.com/i/headshots/nba/players/full/3112335.png
Nikola Jokic15 C 28 6' 11" 284 lbs -- $47,607,350
https://a.espncdn.com/i/headshots/nba/players/full/3442.png
DeAndre Jordan6 C 35 6' 11" 265 lbs Texas A&M $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/4066240.png
Braxton Key F 26 6' 8" 225 lbs Virginia --
https://a.espncdn.com/i/headshots/nba/players/full/3936299.png
Jamal Murray27 PG 26 6' 4" 215 lbs Kentucky $33,833,400
https://a.espncdn.com/i/headshots/nba/players/full/4431690.png
Zeke Nnaji22 PF 22 6' 9" 240 lbs Arizona $4,306,281
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jalen Pickett G 23 6' 4" 202 lbs Siena $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/4278104.png
Michael Porter Jr.1 SF 25 6' 10" 218 lbs Missouri $33,386,850
https://a.espncdn.com/i/headshots/nba/players/full/4305.png
Ish Smith14 PG 35 6' 0" 175 lbs Wake Forest --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Julian Strawther G 21 6' 7" 205 lbs Gonzaga $2,431,080
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Hunter Tyson F 23 6' 8" 215 lbs Clemson $1,119,563
https://a.espncdn.com/i/headshots/nba/players/full/4576087.png
Peyton Watson8 F 21 6' 8" 200 lbs UCLA $2,303,520
Detroit Pistons Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4277848.png
Marvin Bagley III35 PF 24 6' 10" 235 lbs Duke $12,500,000
https://a.espncdn.com/i/headshots/nba/players/full/4395676.png
Buddy Boeheim27 F 23 6' 6" 205 lbs Syracuse --
https://a.espncdn.com/i/headshots/nba/players/full/3593.png
Bojan Bogdanovic44 SF 34 6' 7" 226 lbs -- $20,000,000
https://a.espncdn.com/i/headshots/nba/players/full/6429.png
Alec Burks5 SG 32 6' 6" 214 lbs Colorado $10,489,600
https://a.espncdn.com/i/headshots/nba/players/full/4871137.png
Malcolm Cazalon20 G -- 6' 6" 185 lbs -- --
https://a.espncdn.com/i/headshots/nba/players/full/4432166.png
Cade Cunningham2 PG 21 6' 7" 220 lbs Oklahoma State $11,055,240
https://a.espncdn.com/i/headshots/nba/players/full/4080610.png
Hamidou Diallo6 SG 25 6' 5" 202 lbs Kentucky --
https://a.espncdn.com/i/headshots/nba/players/full/4433621.png
Jalen Duren0 C 19 6' 11" 250 lbs Memphis $4,330,680
https://a.espncdn.com/i/headshots/nba/players/full/2528794.png
Joe Harris12 SF 32 6' 6" 220 lbs Virginia $19,928,571
https://a.espncdn.com/i/headshots/nba/players/full/4683024.png
Killian Hayes7 PG 22 6' 5" 195 lbs -- $7,413,955
https://a.espncdn.com/i/headshots/nba/players/full/4433218.png
Jaden Ivey23 PG 21 6' 4" 195 lbs Purdue $7,641,480
https://a.espncdn.com/i/headshots/nba/players/full/4277957.png
Isaiah Livers12 PF 25 6' 6" 232 lbs Michigan $1,836,096
https://a.espncdn.com/i/headshots/nba/players/full/2488826.png
Rodney McGruder17 G 32 6' 4" 205 lbs Kansas State --
https://a.espncdn.com/i/headshots/nba/players/full/3059310.png
Monte Morris22 PG 28 6' 2" 183 lbs Iowa State $9,800,926
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jared Rhoden8 G 24 6' 6" 210 lbs Seton Hall --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Marcus Sasser G 23 6' 2" 195 lbs Houston $2,623,680
https://a.espncdn.com/i/headshots/nba/players/full/4432810.png
Isaiah Stewart28 C 22 6' 8" 250 lbs Washington $5,266,713
https://a.espncdn.com/i/headshots/nba/players/full/4684742.png
Ausar Thompson F 20 6' 7" 190 lbs -- $7,977,480
https://a.espncdn.com/i/headshots/nba/players/full/4432808.png
James Wiseman13 C 22 7' 0" 240 lbs Memphis $12,119,400
Golden State Warriors Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/3975.png
Stephen Curry30 PG 35 6' 2" 185 lbs Davidson $51,915,615
https://a.espncdn.com/i/headshots/nba/players/full/6589.png
Draymond Green23 PF 33 6' 6" 230 lbs Michigan State $22,321,429
https://a.espncdn.com/i/headshots/nba/players/full/2327577.png
JaMychal Green1 F 33 6' 9" 227 lbs Alabama --
https://a.espncdn.com/i/headshots/nba/players/full/2386.png
Andre Iguodala9 F 39 6' 6" 215 lbs Arizona --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Trayce Jackson-Davis F 23 6' 9" 245 lbs Indiana $1,119,563
https://a.espncdn.com/i/headshots/nba/players/full/6446.png
Cory Joseph18 PG 32 6' 3" 200 lbs Texas $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/4433247.png
Jonathan Kuminga00 PF 20 6' 7" 225 lbs -- $6,012,840
https://a.espncdn.com/i/headshots/nba/players/full/4066790.png
Anthony Lamb40 F 25 6' 6" 227 lbs Vermont --
https://a.espncdn.com/i/headshots/nba/players/full/3155535.png
Kevon Looney5 F 27 6' 9" 222 lbs UCLA $7,500,000
https://a.espncdn.com/i/headshots/nba/players/full/4432171.png
Moses Moody4 SG 21 6' 5" 211 lbs Arkansas $3,918,480
https://a.espncdn.com/i/headshots/nba/players/full/2779.png
Chris Paul PG 38 6' 0" 175 lbs Wake Forest $30,800,000
https://a.espncdn.com/i/headshots/nba/players/full/3134903.png
Gary Payton II8 SG 30 6' 2" 195 lbs Oregon State $8,715,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Brandin Podziemski G 20 6' 4" 203 lbs Santa Clara $3,352,440
https://a.espncdn.com/i/headshots/nba/players/full/4431720.png
Lester Quinones25 G 22 6' 5" 205 lbs Memphis --
https://a.espncdn.com/i/headshots/nba/players/full/3032978.png
Dario Saric9 PF 29 6' 10" 225 lbs -- $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/6475.png
Klay Thompson11 SG 33 6' 6" 220 lbs Washington State $43,219,440
https://a.espncdn.com/i/headshots/nba/players/full/3059319.png
Andrew Wiggins22 SF 28 6' 7" 197 lbs Kansas $24,330,357
Houston Rockets Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/3415.png
D.J. Augustin4 G 35 5' 11" 183 lbs Texas --
https://a.espncdn.com/i/headshots/nba/players/full/3155526.png
Dillon Brooks SF 27 6' 7" 225 lbs Oregon $22,627,671
https://a.espncdn.com/i/headshots/nba/players/full/2991282.png
Willie Cauley-Stein2 C 30 7' 0" 240 lbs Kentucky --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Darius Days5 F 23 6' 7" 245 lbs LSU --
https://a.espncdn.com/i/headshots/nba/players/full/4433192.png
Tari Eason17 F 22 6' 8" 215 lbs LSU $3,527,160
https://a.espncdn.com/i/headshots/nba/players/full/4437244.png
Jalen Green4 SG 21 6' 4" 186 lbs -- $9,891,480
https://a.espncdn.com/i/headshots/nba/players/full/3209.png
Jeff Green32 PF 37 6' 8" 235 lbs Georgetown $9,600,000
https://a.espncdn.com/i/headshots/nba/players/full/3922230.png
Aaron Holiday G 26 6' 0" 185 lbs UCLA $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/5075393.png
Trevor Hudgins12 G 24 6' 0" 180 lbs Northwest Missouri State --
https://a.espncdn.com/i/headshots/nba/players/full/2579294.png
Frank Kaminsky33 PF 30 7' 0" 240 lbs Wisconsin --
https://a.espncdn.com/i/headshots/nba/players/full/3146557.png
Jock Landale C 27 6' 11" 255 lbs Saint Mary's $8,000,000
https://a.espncdn.com/i/headshots/nba/players/full/4376.png
Boban Marjanovic51 C 35 7' 4" 290 lbs -- $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/4397140.png
Kevin Porter Jr.3 SG 23 6' 4" 203 lbs USC $15,860,000
https://a.espncdn.com/i/headshots/nba/players/full/4871144.png
Alperen Sengun28 C 21 6' 11" 243 lbs -- $3,536,280
https://a.espncdn.com/i/headshots/nba/players/full/4432639.png
Jabari Smith Jr.1 PF 20 6' 11" 220 lbs Auburn $9,326,520
https://a.espncdn.com/i/headshots/nba/players/full/3136777.png
Jae'Sean Tate8 SF 27 6' 5" 230 lbs Ohio State $6,500,000
https://a.espncdn.com/i/headshots/nba/players/full/4684740.png
Amen Thompson F 20 6' 7" 214 lbs -- $8,809,320
https://a.espncdn.com/i/headshots/nba/players/full/2991230.png
Fred VanVleet SG 29 6' 0" 197 lbs Wichita State $40,806,300
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Cam Whitmore F 19 6' 7" 232 lbs Villanova $3,218,160
Indiana Pacers Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4065670.png
Bruce Brown SF 27 6' 4" 202 lbs Miami $22,000,000
https://a.espncdn.com/i/headshots/nba/players/full/4433254.png
Kendall Brown10 SG 20 6' 8" 205 lbs Baylor --
https://a.espncdn.com/i/headshots/nba/players/full/4396993.png
Tyrese Haliburton0 PG 23 6' 5" 185 lbs Iowa State $5,808,435
https://a.espncdn.com/i/headshots/nba/players/full/2990984.png
Buddy Hield24 SG 30 6' 4" 220 lbs Oklahoma $19,279,841
https://a.espncdn.com/i/headshots/nba/players/full/3438.png
George Hill7 PG 37 6' 4" 188 lbs IUPUI --
https://a.espncdn.com/i/headshots/nba/players/full/3439.png
Serge Ibaka F 34 6' 10" 235 lbs -- --
https://a.espncdn.com/i/headshots/nba/players/full/4432170.png
Isaiah Jackson22 SF 21 6' 10" 206 lbs Kentucky $2,696,280
https://a.espncdn.com/i/headshots/nba/players/full/3999.png
James Johnson16 PF 36 6' 7" 240 lbs Wake Forest --
https://a.espncdn.com/i/headshots/nba/players/full/4683634.png
Bennedict Mathurin00 SG 21 6' 6" 195 lbs Arizona $6,916,080
https://a.espncdn.com/i/headshots/nba/players/full/2530530.png
T.J. McConnell9 PG 31 6' 1" 190 lbs Arizona $8,700,000
https://a.espncdn.com/i/headshots/nba/players/full/4395712.png
Andrew Nembhard2 PG 23 6' 5" 193 lbs Gonzaga $2,131,905
https://a.espncdn.com/i/headshots/nba/players/full/4396909.png
Aaron Nesmith23 SF 23 6' 5" 215 lbs Vanderbilt $5,634,257
https://a.espncdn.com/i/headshots/nba/players/full/4277883.png
Jordan Nwora13 SF 25 6' 8" 225 lbs Louisville $3,000,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Ben Sheppard G 22 6' 6" 190 lbs Belmont $2,537,160
https://a.espncdn.com/i/headshots/nba/players/full/4397189.png
Jalen Smith25 PF 23 6' 9" 215 lbs Maryland $5,604,192
https://a.espncdn.com/i/headshots/nba/players/full/2451037.png
Daniel Theis27 C 31 6' 8" 245 lbs -- $9,108,387
https://a.espncdn.com/i/headshots/nba/players/full/4278355.png
Obi Toppin1 PF 25 6' 9" 220 lbs Dayton $6,803,012
https://a.espncdn.com/i/headshots/nba/players/full/3133628.png
Myles Turner33 C 27 6' 11" 250 lbs Texas $20,975,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jarace Walker F 20 6' 8" 240 lbs Houston $6,059,520
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Isaiah Wong G 22 6' 4" 184 lbs Miami --
https://a.espncdn.com/i/headshots/nba/players/full/2991011.png
Gabe York32 G 30 6' 3" 190 lbs Arizona --
LA Clippers Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/3416.png
Nicolas Batum33 PF 34 6' 8" 230 lbs -- $11,710,818
https://a.espncdn.com/i/headshots/nba/players/full/4432162.png
Brandon Boston Jr.4 SG 21 6' 6" 188 lbs Kentucky $1,836,096
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Kobe Brown G 23 6' 8" 250 lbs Missouri $2,413,320
https://a.espncdn.com/i/headshots/nba/players/full/4066387.png
Amir Coffey7 SG 26 6' 7" 210 lbs Minnesota $3,666,667
https://a.espncdn.com/i/headshots/nba/players/full/2490620.png
Robert Covington23 PF 32 6' 7" 209 lbs Tennessee State $11,692,308
https://a.espncdn.com/i/headshots/nba/players/full/4433249.png
Moussa Diabate25 F 21 6' 11" 210 lbs Michigan --
https://a.espncdn.com/i/headshots/nba/players/full/4251.png
Paul George13 F 33 6' 8" 220 lbs Fresno State $45,640,084
https://a.espncdn.com/i/headshots/nba/players/full/4592492.png
Bones Hyland5 PG 23 6' 2" 169 lbs VCU $2,306,400
https://a.espncdn.com/i/headshots/nba/players/full/6450.png
Kawhi Leonard2 SF 32 6' 7" 225 lbs San Diego State $45,640,084
https://a.espncdn.com/i/headshots/nba/players/full/3907823.png
Terance Mann14 SG 26 6' 5" 215 lbs Florida State $10,576,923
https://a.espncdn.com/i/headshots/nba/players/full/4702882.png
KJ Martin F 22 6' 7" 215 lbs -- $1,930,681
https://a.espncdn.com/i/headshots/nba/players/full/4431828.png
Kenyon Martin Jr. F 22 6' 7" 215 lbs -- $1,930,681
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jordan Miller G 23 6' 7" 195 lbs Miami --
https://a.espncdn.com/i/headshots/nba/players/full/3914075.png
Xavier Moon15 PG 28 6' 0" 165 lbs Morehead State --
https://a.espncdn.com/i/headshots/nba/players/full/6462.png
Marcus Morris Sr.8 SF 34 6' 8" 218 lbs Kansas $17,116,279
https://a.espncdn.com/i/headshots/nba/players/full/2488653.png
Mason Plumlee44 C 33 7' 0" 254 lbs Duke $5,000,000
https://a.espncdn.com/i/headshots/nba/players/full/2595516.png
Norman Powell24 G 30 6' 3" 215 lbs UCLA $18,000,000
https://a.espncdn.com/i/headshots/nba/players/full/4397916.png
Jason Preston17 PG 24 6' 3" 181 lbs Ohio $1,836,096
https://a.espncdn.com/i/headshots/nba/players/full/3468.png
Russell Westbrook0 PG 34 6' 3" 200 lbs UCLA $3,835,738
https://a.espncdn.com/i/headshots/nba/players/full/4017837.png
Ivica Zubac40 C 26 7' 0" 240 lbs -- $10,933,333
Los Angeles Lakers Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Damion Baugh G 23 6' 4" 194 lbs TCU --
https://a.espncdn.com/i/headshots/nba/players/full/4432582.png
Max Christie10 G 20 6' 5" 190 lbs Michigan State $1,719,864
https://a.espncdn.com/i/headshots/nba/players/full/6583.png
Anthony Davis3 PF 30 6' 10" 253 lbs Kentucky $40,600,080
https://a.espncdn.com/i/headshots/nba/players/full/4066264.png
Wenyen Gabriel35 F 26 6' 9" 205 lbs Kentucky --
https://a.espncdn.com/i/headshots/nba/players/full/4066648.png
Rui Hachimura28 PF 25 6' 8" 230 lbs Gonzaga $15,740,741
https://a.espncdn.com/i/headshots/nba/players/full/4397077.png
Jaxson Hayes10 C 23 7' 0" 220 lbs Texas $2,165,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jalen Hood-Schifino G 20 6' 6" 215 lbs Indiana $3,695,040
https://a.espncdn.com/i/headshots/nba/players/full/1966.png
LeBron James23 SF 38 6' 9" 250 lbs -- $47,607,350
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Maxwell Lewis F 21 6' 7" 205 lbs Pepperdine $1,119,563
https://a.espncdn.com/i/headshots/nba/players/full/4431785.png
Scotty Pippen Jr.14 G 22 6' 1" 185 lbs Vanderbilt --
https://a.espncdn.com/i/headshots/nba/players/full/2990962.png
Taurean Prince PF 29 6' 6" 218 lbs Baylor $7,455,000
https://a.espncdn.com/i/headshots/nba/players/full/4066457.png
Austin Reaves15 SG 25 6' 5" 197 lbs Oklahoma $12,015,150
https://a.espncdn.com/i/headshots/nba/players/full/4395627.png
Cam Reddish SF 24 6' 8" 217 lbs Duke $2,165,000
https://a.espncdn.com/i/headshots/nba/players/full/3136776.png
D'Angelo Russell1 PG 27 6' 4" 193 lbs Ohio State $17,307,693
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Vincent Valerio-Bodon SF 22 6' 9" 200 lbs -- --
https://a.espncdn.com/i/headshots/nba/players/full/4278077.png
Jarred Vanderbilt2 PF 24 6' 8" 214 lbs Kentucky $4,698,000
https://a.espncdn.com/i/headshots/nba/players/full/3137259.png
Gabe Vincent PG 27 6' 3" 200 lbs UC Santa Barbara $10,500,000
https://a.espncdn.com/i/headshots/nba/players/full/3058254.png
Christian Wood F 27 6' 9" 214 lbs UNLV $2,709,849
Memphis Grizzlies Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/2991235.png
Steven Adams4 C 30 6' 11" 265 lbs Pittsburgh $12,600,000
https://a.espncdn.com/i/headshots/nba/players/full/4593125.png
Santi Aldama7 PF 22 6' 11" 215 lbs Loyola (MD) $2,194,200
https://a.espncdn.com/i/headshots/nba/players/full/4066320.png
Desmond Bane22 SG 25 6' 5" 215 lbs TCU $3,845,083
https://a.espncdn.com/i/headshots/nba/players/full/5148538.png
Tarik Biberovic F 22 6' 7" 218 lbs -- --
https://a.espncdn.com/i/headshots/nba/players/full/4432168.png
Josh Christopher SG 21 6' 4" 215 lbs Arizona State $2,485,200
https://a.espncdn.com/i/headshots/nba/players/full/3906665.png
Brandon Clarke15 PF 27 6' 8" 215 lbs Gonzaga $12,500,000
https://a.espncdn.com/i/headshots/nba/players/full/4278378.png
Jacob Gilyard0 G 25 5' 9" 160 lbs Richmond --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Gregory Jackson II F 18 6' 9" 215 lbs South Carolina --
https://a.espncdn.com/i/headshots/nba/players/full/4277961.png
Jaren Jackson Jr.13 PF 24 6' 11" 242 lbs Michigan State $27,102,202
https://a.espncdn.com/i/headshots/nba/players/full/3913174.png
Luke Kennard10 SG 27 6' 5" 206 lbs Duke $15,418,363
https://a.espncdn.com/i/headshots/nba/players/full/3134932.png
John Konchar46 SG 27 6' 5" 210 lbs -- $2,400,000
https://a.espncdn.com/i/headshots/nba/players/full/4592691.png
Jake LaRavia3 F 21 6' 7" 235 lbs Wake Forest $3,199,920
https://a.espncdn.com/i/headshots/nba/players/full/4585610.png
Kenneth Lofton Jr.6 F 21 6' 8" 275 lbs Louisiana Tech $1,719,864
https://a.espncdn.com/i/headshots/nba/players/full/4279888.png
Ja Morant12 PG 24 6' 3" 174 lbs Murray State $34,005,250
https://a.espncdn.com/i/headshots/nba/players/full/4593041.png
David Roddy27 F 22 6' 5" 255 lbs Colorado State $2,718,240
https://a.espncdn.com/i/headshots/nba/players/full/3456.png
Derrick Rose PG 34 6' 3" 200 lbs Memphis $3,196,448
https://a.espncdn.com/i/headshots/nba/players/full/2990992.png
Marcus Smart PG 29 6' 4" 220 lbs Oklahoma State $18,833,712
https://a.espncdn.com/i/headshots/nba/players/full/4277964.png
Xavier Tillman2 F 24 6' 8" 245 lbs Michigan State $1,930,681
https://a.espncdn.com/i/headshots/nba/players/full/4715198.png
Isaiah Todd PF 21 6' 9" 219 lbs -- $1,836,096
https://a.espncdn.com/i/headshots/nba/players/full/4433137.png
Ziaire Williams8 F 22 6' 9" 185 lbs Stanford $4,810,200
https://a.espncdn.com/i/headshots/nba/players/full/4397227.png
Vince Williams Jr.5 G 23 6' 6" 205 lbs VCU --
Miami Heat Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4066261.png
Bam Adebayo13 C 26 6' 9" 255 lbs Kentucky $32,600,060
https://a.espncdn.com/i/headshots/nba/players/full/3934723.png
Thomas Bryant13 C 26 6' 10" 248 lbs Indiana $2,528,233
https://a.espncdn.com/i/headshots/nba/players/full/6430.png
Jimmy Butler22 SF 34 6' 7" 230 lbs Marquette $45,183,960
https://a.espncdn.com/i/headshots/nba/players/full/4278572.png
Jamal Cain8 F 24 6' 7" 191 lbs Oakland --
https://a.espncdn.com/i/headshots/nba/players/full/2184.png
Udonis Haslem40 PF 43 6' 8" 235 lbs Florida --
https://a.espncdn.com/i/headshots/nba/players/full/4395725.png
Tyler Herro14 PG 23 6' 5" 195 lbs Kentucky $27,000,000
https://a.espncdn.com/i/headshots/nba/players/full/4291678.png
Haywood Highsmith24 F 26 6' 4" 220 lbs Wheeling Jesuit $1,902,137
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jaime Jaquez Jr. G 22 6' 7" 225 lbs UCLA $3,510,600
https://a.espncdn.com/i/headshots/nba/players/full/4997528.png
Nikola Jovic5 F 20 6' 10" 205 lbs -- $2,352,000
https://a.espncdn.com/i/headshots/nba/players/full/3449.png
Kevin Love42 PF 35 6' 8" 251 lbs UCLA $3,835,738
https://a.espncdn.com/i/headshots/nba/players/full/3012.png
Kyle Lowry7 PG 37 6' 0" 196 lbs Villanova $29,682,540
https://a.espncdn.com/i/headshots/nba/players/full/3138160.png
Caleb Martin16 SF 27 6' 5" 205 lbs Nevada $6,802,950
https://a.espncdn.com/i/headshots/nba/players/full/2581190.png
Josh Richardson SG 30 6' 6" 200 lbs Tennessee $2,891,467
https://a.espncdn.com/i/headshots/nba/players/full/3157465.png
Duncan Robinson55 F 29 6' 7" 215 lbs Michigan $18,154,000
https://a.espncdn.com/i/headshots/nba/players/full/4593049.png
Orlando Robinson25 C 23 7' 0" 235 lbs Fresno State $1,801,769
https://a.espncdn.com/i/headshots/nba/players/full/4066993.png
Dru Smith G 25 6' 3" 203 lbs Missouri --
Milwaukee Bucks Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/3135045.png
Grayson Allen12 SG 27 6' 4" 198 lbs Duke $8,925,000
https://a.espncdn.com/i/headshots/nba/players/full/3032977.png
Giannis Antetokounmpo34 PF 28 6' 11" 243 lbs -- $45,640,084
https://a.espncdn.com/i/headshots/nba/players/full/3102533.png
Thanasis Antetokounmpo43 SF 31 6' 7" 219 lbs -- $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/3907822.png
Malik Beasley5 SG 26 6' 4" 187 lbs Florida State $2,019,760
https://a.espncdn.com/i/headshots/nba/players/full/4432179.png
MarJon Beauchamp0 F 22 6' 7" 202 lbs -- $2,609,400
https://a.espncdn.com/i/headshots/nba/players/full/2578239.png
Pat Connaughton24 SG 30 6' 5" 209 lbs Notre Dame $9,423,869
https://a.espncdn.com/i/headshots/nba/players/full/6581.png
Jae Crowder99 PF 33 6' 6" 235 lbs Marquette $2,019,760
https://a.espncdn.com/i/headshots/nba/players/full/3423.png
Goran Dragic31 PG 37 6' 3" 190 lbs -- --
https://a.espncdn.com/i/headshots/nba/players/full/4397475.png
AJ Green20 G 23 6' 5" 207 lbs Northern Iowa $1,801,769
https://a.espncdn.com/i/headshots/nba/players/full/3995.png
Jrue Holiday21 PG 33 6' 4" 205 lbs UCLA $36,861,707
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Andre Jackson Jr. G 21 6' 6" 200 lbs UConn $1,119,563
https://a.espncdn.com/i/headshots/nba/players/full/6605.png
Meyers Leonard3 C 31 7' 0" 260 lbs Illinois --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Chris Livingston F 19 6' 6" 220 lbs Kentucky $1,119,563
https://a.espncdn.com/i/headshots/nba/players/full/3448.png
Brook Lopez11 C 35 7' 0" 282 lbs Stanford $25,000,000
https://a.espncdn.com/i/headshots/nba/players/full/3447.png
Robin Lopez C 35 7' 0" 281 lbs Stanford --
https://a.espncdn.com/i/headshots/nba/players/full/6609.png
Khris Middleton22 SF 32 6' 7" 222 lbs Texas A&M $29,320,988
https://a.espncdn.com/i/headshots/nba/players/full/3064482.png
Bobby Portis9 F 28 6' 10" 250 lbs Arkansas $11,710,818
https://a.espncdn.com/i/headshots/nba/players/full/4277887.png
Lindell Wigginton28 G 25 6' 1" 189 lbs Iowa State --
Minnesota Timberwolves Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4278039.png
Nickeil Alexander-Walker9 SG 25 6' 5" 205 lbs Virginia Tech $4,687,500
https://a.espncdn.com/i/headshots/nba/players/full/2993874.png
Kyle Anderson5 SF 30 6' 9" 230 lbs UCLA $9,219,512
https://a.espncdn.com/i/headshots/nba/players/full/4278508.png
Troy Brown Jr. SF 24 6' 6" 215 lbs Oregon $4,000,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jaylen Clark G 21 6' 5" 205 lbs UCLA --
https://a.espncdn.com/i/headshots/nba/players/full/3195.png
Mike Conley10 PG 35 6' 1" 175 lbs Ohio State $24,360,000
https://a.espncdn.com/i/headshots/nba/players/full/4594268.png
Anthony Edwards5 SG 22 6' 4" 225 lbs Georgia $9,219,512
https://a.espncdn.com/i/headshots/nba/players/full/4277951.png
Luka Garza55 C 24 6' 10" 243 lbs Iowa --
https://a.espncdn.com/i/headshots/nba/players/full/3032976.png
Rudy Gobert27 C 31 7' 1" 258 lbs -- $41,000,000
https://a.espncdn.com/i/headshots/nba/players/full/4578893.png
Vit Krejci F 23 6' 7" 195 lbs -- $1,836,096
https://a.espncdn.com/i/headshots/nba/players/full/4431671.png
Jaden McDaniels3 PF 22 6' 9" 185 lbs Washington $3,901,399
https://a.espncdn.com/i/headshots/nba/players/full/3134916.png
Jordan McLaughlin6 PG 27 6' 0" 185 lbs USC $2,320,000
https://a.espncdn.com/i/headshots/nba/players/full/3915195.png
Shake Milton SG 26 6' 5" 205 lbs SMU $5,000,000
https://a.espncdn.com/i/headshots/nba/players/full/4687718.png
Josh Minott8 F 21 6' 8" 205 lbs Memphis $1,719,864
https://a.espncdn.com/i/headshots/nba/players/full/4592187.png
Wendell Moore Jr.7 G 22 6' 5" 215 lbs Duke $2,421,720
https://a.espncdn.com/i/headshots/nba/players/full/4432176.png
Daishen Nix15 SG 21 6' 4" 226 lbs -- $1,836,096
https://a.espncdn.com/i/headshots/nba/players/full/4278541.png
Jaylen Nowell4 SG 24 6' 4" 201 lbs Washington --
https://a.espncdn.com/i/headshots/nba/players/full/4396971.png
Naz Reid11 C 24 6' 9" 264 lbs LSU $12,950,400
https://a.espncdn.com/i/headshots/nba/players/full/6617.png
Austin Rivers25 SG 31 6' 4" 200 lbs Duke --
https://a.espncdn.com/i/headshots/nba/players/full/3908336.png
Matt Ryan37 F 26 6' 6" 215 lbs Chattanooga --
https://a.espncdn.com/i/headshots/nba/players/full/3136195.png
Karl-Anthony Towns32 C 27 7' 0" 248 lbs Kentucky $36,016,200
New Orleans Pelicans Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4277869.png
Jose Alvarado15 PG 25 6' 0" 179 lbs Georgia Tech $1,836,096
https://a.espncdn.com/i/headshots/nba/players/full/4869342.png
Dyson Daniels11 G 20 6' 8" 200 lbs -- $5,784,120
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jordan Hawkins24 G 21 6' 5" 195 lbs UConn $4,310,160
https://a.espncdn.com/i/headshots/nba/players/full/2999409.png
Willy Hernangomez9 C 29 6' 11" 250 lbs -- $2,559,942
https://a.espncdn.com/i/headshots/nba/players/full/3913176.png
Brandon Ingram14 SF 26 6' 8" 190 lbs Duke $33,833,400
https://a.espncdn.com/i/headshots/nba/players/full/4277813.png
Herbert Jones5 SF 24 6' 7" 206 lbs Alabama $12,015,150
https://a.espncdn.com/i/headshots/nba/players/full/4395698.png
Kira Lewis Jr.13 PG 22 6' 1" 170 lbs Alabama $5,722,116
https://a.espncdn.com/i/headshots/nba/players/full/4432821.png
E.J. Liddell32 F 22 6' 6" 240 lbs Ohio State $1,801,769
https://a.espncdn.com/i/headshots/nba/players/full/4278594.png
Naji Marshall8 SF 25 6' 7" 220 lbs Xavier $1,930,681
https://a.espncdn.com/i/headshots/nba/players/full/2490149.png
CJ McCollum3 SG 32 6' 3" 190 lbs Lehigh $35,802,469
https://a.espncdn.com/i/headshots/nba/players/full/4397688.png
Trey Murphy III25 SG 23 6' 8" 206 lbs Virginia $3,359,280
https://a.espncdn.com/i/headshots/nba/players/full/2580365.png
Larry Nance Jr.22 PF 30 6' 8" 245 lbs Wyoming $10,375,000
https://a.espncdn.com/i/headshots/nba/players/full/4431811.png
Dereon Seabron0 G 23 6' 5" 183 lbs NC State --
https://a.espncdn.com/i/headshots/nba/players/full/6477.png
Jonas Valanciunas17 C 31 6' 11" 265 lbs -- $15,435,000
https://a.espncdn.com/i/headshots/nba/players/full/4395628.png
Zion Williamson1 PF 23 6' 6" 284 lbs Duke $34,005,250
https://a.espncdn.com/i/headshots/nba/players/full/2579258.png
Cody Zeller44 C 30 6' 11" 240 lbs Indiana $2,019,706
New York Knicks Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4395625.png
RJ Barrett9 SG 23 6' 6" 214 lbs Duke $23,883,929
https://a.espncdn.com/i/headshots/nba/players/full/3934672.png
Jalen Brunson11 PG 27 6' 1" 190 lbs Villanova $26,346,666
https://a.espncdn.com/i/headshots/nba/players/full/3934673.png
Donte DiVincenzo SG 26 6' 4" 203 lbs Villanova $10,960,000
https://a.espncdn.com/i/headshots/nba/players/full/6588.png
Evan Fournier13 SG 30 6' 6" 205 lbs -- $18,857,143
https://a.espncdn.com/i/headshots/nba/players/full/4397014.png
Quentin Grimes6 SG 23 6' 4" 210 lbs Houston $2,385,720
https://a.espncdn.com/i/headshots/nba/players/full/3062679.png
Josh Hart3 SG 28 6' 4" 215 lbs Villanova $12,960,000
https://a.espncdn.com/i/headshots/nba/players/full/4222252.png
Isaiah Hartenstein55 C 25 7' 0" 250 lbs -- $9,245,121
https://a.espncdn.com/i/headshots/nba/players/full/3913220.png
DaQuan Jeffries8 SG 26 6' 5" 225 lbs Western Texas Coll. (J.C.) $2,065,585
https://a.espncdn.com/i/headshots/nba/players/full/4432645.png
Trevor Keels3 G 20 6' 4" 221 lbs Duke --
https://a.espncdn.com/i/headshots/nba/players/full/4067325.png
Nathan Knight F 26 6' 8" 253 lbs William & Mary --
https://a.espncdn.com/i/headshots/nba/players/full/5149711.png
Jaylen Martin G 19 6' 6" 196 lbs -- --
https://a.espncdn.com/i/headshots/nba/players/full/4431823.png
Miles McBride2 PG 23 6' 2" 195 lbs West Virginia $1,836,096
https://a.espncdn.com/i/headshots/nba/players/full/4395724.png
Immanuel Quickley5 SG 24 6' 3" 190 lbs Kentucky $4,171,548
https://a.espncdn.com/i/headshots/nba/players/full/3064514.png
Julius Randle30 PF 28 6' 8" 250 lbs Kentucky $28,226,880
https://a.espncdn.com/i/headshots/nba/players/full/4351852.png
Mitchell Robinson23 C 25 7' 0" 240 lbs -- $15,681,818
https://a.espncdn.com/i/headshots/nba/players/full/4066392.png
Isaiah Roby18 F 25 6' 8" 230 lbs Nebraska $2,066,585
https://a.espncdn.com/i/headshots/nba/players/full/4277922.png
Jericho Sims45 C 24 6' 9" 250 lbs Texas $1,927,896
https://a.espncdn.com/i/headshots/nba/players/full/4397235.png
Duane Washington Jr.4 PG 23 6' 2" 197 lbs Ohio State --
https://a.espncdn.com/i/headshots/nba/players/full/3906786.png
Dylan Windler SG 26 6' 7" 196 lbs Belmont --
Oklahoma City Thunder Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/6426.png
Davis Bertans SF 30 6' 10" 225 lbs -- $17,000,000
https://a.espncdn.com/i/headshots/nba/players/full/4997526.png
Ousmane Dieng13 F 20 6' 10" 220 lbs -- $4,798,440
https://a.espncdn.com/i/headshots/nba/players/full/4397020.png
Luguentz Dort5 G 24 6' 4" 220 lbs Arizona State $15,277,778
https://a.espncdn.com/i/headshots/nba/players/full/4871145.png
Josh Giddey3 SG 20 6' 8" 216 lbs -- $6,587,040
https://a.espncdn.com/i/headshots/nba/players/full/4278073.png
Shai Gilgeous-Alexander2 PG 25 6' 6" 195 lbs Kentucky $33,386,850
https://a.espncdn.com/i/headshots/nba/players/full/4433255.png
Chet Holmgren7 PF 21 7' 1" 208 lbs Gonzaga $10,386,000
https://a.espncdn.com/i/headshots/nba/players/full/4395702.png
Isaiah Joe11 SG 24 6' 3" 165 lbs Arkansas $1,997,238
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Keyontae Johnson18 F 23 6' 6" 235 lbs Kansas State --
https://a.espncdn.com/i/headshots/nba/players/full/4432819.png
Tre Mann23 PG 22 6' 3" 184 lbs Florida $3,191,280
https://a.espncdn.com/i/headshots/nba/players/full/3102532.png
Vasilije Micic98 G 29 6' 5" 203 lbs -- $7,723,000
https://a.espncdn.com/i/headshots/nba/players/full/2527963.png
Victor Oladipo4 SG 31 6' 4" 213 lbs Indiana $9,450,000
https://a.espncdn.com/i/headshots/nba/players/full/4683018.png
Aleksej Pokusevski17 F 21 7' 0" 190 lbs -- $5,009,633
https://a.espncdn.com/i/headshots/nba/players/full/4432813.png
Jeremiah Robinson-Earl50 PF 22 6' 9" 240 lbs Villanova $1,900,000
https://a.espncdn.com/i/headshots/nba/players/full/4278046.png
Olivier Sarr30 C 24 7' 0" 240 lbs Kentucky --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Cason Wallace22 G 19 6' 4" 193 lbs Kentucky $5,291,000
https://a.espncdn.com/i/headshots/nba/players/full/4683749.png
TyTy Washington Jr. G 21 6' 3" 195 lbs Kentucky $2,320,440
https://a.espncdn.com/i/headshots/nba/players/full/4066317.png
Lindy Waters III12 F 26 6' 6" 210 lbs Oklahoma State $1,927,986
https://a.espncdn.com/i/headshots/nba/players/full/4065653.png
Jack White F 26 6' 7" 225 lbs Duke $1,801,769
https://a.espncdn.com/i/headshots/nba/players/full/4397183.png
Aaron Wiggins21 SG 24 6' 5" 190 lbs Maryland $1,836,096
https://a.espncdn.com/i/headshots/nba/players/full/4593803.png
Jalen Williams8 F 22 6' 6" 218 lbs Santa Clara $4,558,680
https://a.espncdn.com/i/headshots/nba/players/full/4432823.png
Jaylin Williams6 F 21 6' 10" 245 lbs Arkansas $2,000,000
https://a.espncdn.com/i/headshots/nba/players/full/3133626.png
Kenrich Williams34 SF 28 6' 6" 210 lbs TCU $6,175,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
KJ Williams12 F 24 6' 10" 250 lbs LSU --
Orlando Magic Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4432809.png
Cole Anthony50 PG 23 6' 3" 185 lbs North Carolina $5,539,771
https://a.espncdn.com/i/headshots/nba/players/full/4432573.png
Paolo Banchero5 PF 20 6' 10" 250 lbs Duke $11,608,080
https://a.espncdn.com/i/headshots/nba/players/full/4348700.png
Goga Bitadze88 C 24 6' 11" 250 lbs -- $2,062,585
https://a.espncdn.com/i/headshots/nba/players/full/4712849.png
Anthony Black G 19 6' 7" 200 lbs Arkansas $7,245,480
https://a.espncdn.com/i/headshots/nba/players/full/4277847.png
Wendell Carter Jr.34 C 24 6' 10" 270 lbs Duke $13,050,000
https://a.espncdn.com/i/headshots/nba/players/full/2596108.png
Michael Carter-Williams11 G 31 6' 5" 190 lbs Syracuse --
https://a.espncdn.com/i/headshots/nba/players/full/4066636.png
Markelle Fultz20 PG 25 6' 4" 209 lbs Washington $17,000,000
https://a.espncdn.com/i/headshots/nba/players/full/2999547.png
Gary Harris14 SG 29 6' 4" 210 lbs Michigan State $13,000,000
https://a.espncdn.com/i/headshots/nba/players/full/4067858.png
Kevon Harris7 G 26 6' 6" 220 lbs Stephen F. Austin --
https://a.espncdn.com/i/headshots/nba/players/full/4433623.png
Caleb Houstan2 G 20 6' 8" 210 lbs Michigan $2,000,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jett Howard G 20 6' 8" 215 lbs Michigan $5,026,800
https://a.espncdn.com/i/headshots/nba/players/full/2968436.png
Joe Ingles SG 35 6' 8" 220 lbs -- $11,000,000
https://a.espncdn.com/i/headshots/nba/players/full/4065654.png
Jonathan Isaac1 PF 25 6' 10" 230 lbs Florida State $17,400,000
https://a.espncdn.com/i/headshots/nba/players/full/4397071.png
Mac McClung9 SG 24 6' 2" 185 lbs Texas Tech --
https://a.espncdn.com/i/headshots/nba/players/full/4278052.png
Chuma Okeke3 PF 25 6' 8" 229 lbs Auburn $5,266,713
https://a.espncdn.com/i/headshots/nba/players/full/4066851.png
Miye Oni SG 26 6' 5" 206 lbs Yale --
https://a.espncdn.com/i/headshots/nba/players/full/4409222.png
Trevelin Queen12 SG 26 6' 6" 190 lbs New Mexico State --
https://a.espncdn.com/i/headshots/nba/players/full/3918423.png
Admiral Schofield25 SF 26 6' 5" 241 lbs Tennessee --
https://a.espncdn.com/i/headshots/nba/players/full/4432165.png
Jalen Suggs4 SG 22 6' 5" 205 lbs Gonzaga $7,252,080
https://a.espncdn.com/i/headshots/nba/players/full/4566434.png
Franz Wagner22 SF 22 6' 10" 220 lbs Michigan $5,508,720
https://a.espncdn.com/i/headshots/nba/players/full/3150844.png
Moritz Wagner21 C 26 6' 11" 245 lbs Michigan $8,000,000
https://a.espncdn.com/i/headshots/nba/players/full/4397040.png
Brandon Williams11 G 23 6' 2" 190 lbs Arizona --
Philadelphia 76ers Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Marcus Bagley38 F 21 6' 8" 215 lbs Arizona State --
https://a.espncdn.com/i/headshots/nba/players/full/4277919.png
Mo Bamba C 25 7' 0" 231 lbs Texas $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/3964.png
Patrick Beverley21 PG 35 6' 2" 180 lbs Arkansas $2,019,706
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Ricky Council IV37 G 22 6' 6" 205 lbs Arkansas --
https://a.espncdn.com/i/headshots/nba/players/full/2580913.png
Dewayne Dedmon14 C 34 6' 10" 245 lbs USC --
https://a.espncdn.com/i/headshots/nba/players/full/4397107.png
David Duke Jr. G 23 6' 4" 207 lbs Providence --
https://a.espncdn.com/i/headshots/nba/players/full/3059318.png
Joel Embiid21 C 29 7' 0" 280 lbs Kansas $46,900,000
https://a.espncdn.com/i/headshots/nba/players/full/3988.png
Danny Green F 36 6' 6" 215 lbs North Carolina --
https://a.espncdn.com/i/headshots/nba/players/full/3992.png
James Harden1 SG 34 6' 5" 220 lbs Arizona State $35,640,000
https://a.espncdn.com/i/headshots/nba/players/full/2991055.png
Montrezl Harrell5 C 29 6' 7" 240 lbs Louisville $2,019,760
https://a.espncdn.com/i/headshots/nba/players/full/6440.png
Tobias Harris12 PF 31 6' 7" 226 lbs Tennessee $39,270,150
https://a.espncdn.com/i/headshots/nba/players/full/2991155.png
Danuel House Jr.25 SF 30 6' 6" 220 lbs Texas A&M $4,310,250
https://a.espncdn.com/i/headshots/nba/players/full/4397103.png
Louis King23 SF 24 6' 7" 205 lbs Oregon --
https://a.espncdn.com/i/headshots/nba/players/full/3929325.png
Furkan Korkmaz30 SG 26 6' 7" 202 lbs -- $5,370,370
https://a.espncdn.com/i/headshots/nba/players/full/4431678.png
Tyrese Maxey0 PG 22 6' 2" 200 lbs Kentucky $4,343,920
https://a.espncdn.com/i/headshots/nba/players/full/4066436.png
De'Anthony Melton8 SG 25 6' 2" 200 lbs USC $8,000,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Filip Petrusev PF 23 6' 11" 234 lbs Gonzaga $1,119,563
https://a.espncdn.com/i/headshots/nba/players/full/4278562.png
Paul Reed44 SF 24 6' 9" 210 lbs DePaul $7,723,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Terquavion Smith26 G 20 6' 4" 165 lbs NC State --
https://a.espncdn.com/i/headshots/nba/players/full/4432164.png
Jaden Springer11 G 20 6' 4" 205 lbs Tennessee $2,226,240
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Azuolas Tubelis29 F 21 6' 11" 245 lbs Arizona --
https://a.espncdn.com/i/headshots/nba/players/full/3033.png
P.J. Tucker17 PF 38 6' 5" 245 lbs Texas $11,014,500
Phoenix Suns Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4278129.png
Deandre Ayton22 C 25 7' 0" 250 lbs Arizona $32,459,438
https://a.espncdn.com/i/headshots/nba/players/full/4066299.png
Udoka Azubuike C 24 6' 10" 280 lbs Kansas --
https://a.espncdn.com/i/headshots/nba/players/full/3136779.png
Keita Bates-Diop SF 27 6' 8" 229 lbs Ohio State $2,364,614
https://a.espncdn.com/i/headshots/nba/players/full/6580.png
Bradley Beal SG 30 6' 4" 207 lbs Florida $46,741,590
https://a.espncdn.com/i/headshots/nba/players/full/6427.png
Bismack Biyombo18 C 31 6' 8" 255 lbs -- --
https://a.espncdn.com/i/headshots/nba/players/full/4397102.png
Bol Bol C 23 7' 2" 220 lbs Oregon $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/3136193.png
Devin Booker1 SG 26 6' 5" 206 lbs Kentucky $36,016,200
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Toumani Camara F 23 6' 8" 220 lbs Dayton $1,119,563
https://a.espncdn.com/i/headshots/nba/players/full/3202.png
Kevin Durant35 PF 34 6' 10" 240 lbs Texas $47,649,433
https://a.espncdn.com/i/headshots/nba/players/full/3914285.png
Drew Eubanks PF 26 6' 10" 245 lbs Oregon State $2,346,614
https://a.espncdn.com/i/headshots/nba/players/full/4278402.png
Jordan Goodwin G 24 6' 3" 200 lbs Saint Louis $1,927,896
https://a.espncdn.com/i/headshots/nba/players/full/2595209.png
Damion Lee10 SG 30 6' 5" 210 lbs Louisville $2,528,233
https://a.espncdn.com/i/headshots/nba/players/full/4278124.png
Saben Lee38 G 24 6' 2" 183 lbs Vanderbilt --
https://a.espncdn.com/i/headshots/nba/players/full/3914283.png
Chimezie Metu7 PF 26 6' 9" 225 lbs USC $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/4065663.png
Josh Okogie2 SF 25 6' 4" 213 lbs Georgia Tech $2,815,937
https://a.espncdn.com/i/headshots/nba/players/full/6619.png
Terrence Ross8 G 32 6' 7" 206 lbs Washington --
https://a.espncdn.com/i/headshots/nba/players/full/3059307.png
Ish Wainright12 F 29 6' 5" 250 lbs Baylor $1,927,896
https://a.espncdn.com/i/headshots/nba/players/full/2982334.png
T.J. Warren21 SF 30 6' 8" 220 lbs NC State --
https://a.espncdn.com/i/headshots/nba/players/full/3133838.png
Yuta Watanabe SF 28 6' 8" 215 lbs George Washington $2,346,614
Portland Trail Blazers Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4871140.png
Ibou Badji41 C 20 7' 1" 240 lbs -- --
https://a.espncdn.com/i/headshots/nba/players/full/4397126.png
Moses Brown C 23 7' 2" 245 lbs UCLA --
https://a.espncdn.com/i/headshots/nba/players/full/4432588.png
John Butler Jr.21 F 20 7' 0" 190 lbs Florida State --
https://a.espncdn.com/i/headshots/nba/players/full/2991070.png
Jerami Grant9 SF 29 6' 8" 210 lbs Syracuse $27,586,207
https://a.espncdn.com/i/headshots/nba/players/full/4683678.png
Scoot Henderson0 G 19 6' 2" 196 lbs -- $9,770,880
https://a.espncdn.com/i/headshots/nba/players/full/4432192.png
Keon Johnson6 SG 21 6' 3" 185 lbs Tennessee $2,808,720
https://a.espncdn.com/i/headshots/nba/players/full/4278075.png
Kevin Knox II11 SF 24 6' 7" 215 lbs Kentucky --
https://a.espncdn.com/i/headshots/nba/players/full/6606.png
Damian Lillard0 PG 33 6' 2" 195 lbs Weber State $45,640,084
https://a.espncdn.com/i/headshots/nba/players/full/4395652.png
Nassir Little10 SF 23 6' 5" 220 lbs North Carolina $6,250,000
https://a.espncdn.com/i/headshots/nba/players/full/4066269.png
Skylar Mays8 SG 26 6' 4" 205 lbs LSU --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Justin Minaya15 F 24 6' 7" 210 lbs Providence --
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Kris Murray8 F 23 6' 8" 215 lbs Iowa $2,847,480
https://a.espncdn.com/i/headshots/nba/players/full/3102530.png
Jusuf Nurkic27 C 29 7' 0" 290 lbs -- $16,875,000
https://a.espncdn.com/i/headshots/nba/players/full/4914336.png
Shaedon Sharpe17 SG 20 6' 5" 200 lbs Kentucky $6,313,800
https://a.espncdn.com/i/headshots/nba/players/full/4351851.png
Anfernee Simons1 SG 24 6' 3" 181 lbs -- $24,107,143
https://a.espncdn.com/i/headshots/nba/players/full/3907498.png
Matisse Thybulle4 SG 26 6' 5" 201 lbs Washington $10,500,000
https://a.espncdn.com/i/headshots/nba/players/full/4432446.png
Jabari Walker34 F 21 6' 7" 200 lbs Colorado $1,719,864
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jeenathan Williams49 G 24 6' 5" 205 lbs Buffalo $1,719,864
https://a.espncdn.com/i/headshots/nba/players/full/3135047.png
Justise Winslow26 PF 27 6' 6" 222 lbs Duke --
Sacramento Kings Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/6578.png
Harrison Barnes40 SF 31 6' 8" 225 lbs North Carolina $17,000,000
https://a.espncdn.com/i/headshots/nba/players/full/3919454.png
Terence Davis3 SG 26 6' 4" 201 lbs Ole Miss --
https://a.espncdn.com/i/headshots/nba/players/full/2489716.png
Matthew Dellavedova8 PG 33 6' 3" 200 lbs Saint Mary's --
https://a.espncdn.com/i/headshots/nba/players/full/4592402.png
Chris Duarte SG 26 6' 5" 190 lbs Oregon $4,124,400
https://a.espncdn.com/i/headshots/nba/players/full/4397693.png
Kessler Edwards17 SF 23 6' 8" 215 lbs Pepperdine $1,927,896
https://a.espncdn.com/i/headshots/nba/players/full/4702177.png
Keon Ellis23 G 23 6' 5" 175 lbs Alabama --
https://a.espncdn.com/i/headshots/nba/players/full/4066736.png
Jordan Ford1 G 25 6' 1" 175 lbs Saint Mary's --
https://a.espncdn.com/i/headshots/nba/players/full/4066259.png
De'Aaron Fox5 PG 25 6' 3" 185 lbs Kentucky $32,600,060
https://a.espncdn.com/i/headshots/nba/players/full/4066372.png
Kevin Huerter9 SG 25 6' 7" 198 lbs Maryland $15,669,643
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Colby Jones G 21 6' 6" 205 lbs Xavier $2,019,706
https://a.espncdn.com/i/headshots/nba/players/full/2596107.png
Alex Len25 C 30 7' 1" 250 lbs Maryland $2,019,760
https://a.espncdn.com/i/headshots/nba/players/full/3136196.png
Trey Lyles41 PF 27 6' 9" 234 lbs Kentucky $8,000,000
https://a.espncdn.com/i/headshots/nba/players/full/3452.png
JaVale McGee00 C 35 7' 0" 270 lbs Nevada $5,734,280
https://a.espncdn.com/i/headshots/nba/players/full/4278053.png
Davion Mitchell15 PG 25 6' 0" 202 lbs Baylor $5,063,760
https://a.espncdn.com/i/headshots/nba/players/full/4066262.png
Malik Monk0 SG 25 6' 3" 200 lbs Kentucky $9,945,830
https://a.espncdn.com/i/headshots/nba/players/full/4594327.png
Keegan Murray13 SF 23 6' 8" 215 lbs Iowa $8,409,000
https://a.espncdn.com/i/headshots/nba/players/full/3155942.png
Domantas Sabonis10 PF 27 7' 0" 240 lbs Gonzaga $30,600,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Jalen Slawson F 23 6' 7" 218 lbs Furman --
https://a.espncdn.com/i/headshots/nba/players/full/3893014.png
Sasha Vezenkov F 28 6' 9" 225 lbs -- $6,341,464
San Antonio Spurs Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4870562.png
Dominick Barlow26 F 20 6' 10" 220 lbs -- --
https://a.espncdn.com/i/headshots/nba/players/full/4397886.png
Charles Bassey28 C 22 6' 9" 230 lbs Western Kentucky $2,600,000
https://a.espncdn.com/i/headshots/nba/players/full/2578240.png
Khem Birch99 C 30 6' 8" 233 lbs UNLV $6,985,000
https://a.espncdn.com/i/headshots/nba/players/full/4565201.png
Malaki Branham22 G 20 6' 4" 180 lbs Ohio State $3,071,880
https://a.espncdn.com/i/headshots/nba/players/full/2528779.png
Reggie Bullock25 SF 32 6' 6" 205 lbs North Carolina $11,014,080
https://a.espncdn.com/i/headshots/nba/players/full/4592479.png
Julian Champagnie30 F 22 6' 9" 210 lbs St. John's $3,000,000
https://a.espncdn.com/i/headshots/nba/players/full/5081727.png
Sidy Cissoko G 19 6' 7" 225 lbs -- $1,119,563
https://a.espncdn.com/i/headshots/nba/players/full/4066650.png
Zach Collins23 PF 25 6' 11" 250 lbs Gonzaga $7,700,000
https://a.espncdn.com/i/headshots/nba/players/full/2534781.png
Gorgui Dieng41 C 33 6' 10" 265 lbs Louisville --
https://a.espncdn.com/i/headshots/nba/players/full/3133601.png
Devonte' Graham4 PG 28 6' 1" 195 lbs Kansas $12,100,000
https://a.espncdn.com/i/headshots/nba/players/full/4395723.png
Keldon Johnson3 SF 23 6' 5" 220 lbs Kentucky $20,000,000
https://a.espncdn.com/i/headshots/nba/players/full/4395626.png
Tre Jones33 PG 23 6' 1" 185 lbs Duke $9,895,833
https://a.espncdn.com/i/headshots/nba/players/full/4397008.png
Romeo Langford35 SG 23 6' 5" 216 lbs Indiana --
https://a.espncdn.com/i/headshots/nba/players/full/4278580.png
Sandro Mamukelashvili54 PF 24 6' 10" 240 lbs Seton Hall $2,019,760
https://a.espncdn.com/i/headshots/nba/players/full/2528588.png
Doug McDermott17 SF 31 6' 6" 225 lbs Creighton $13,750,000
https://a.espncdn.com/i/headshots/nba/players/full/3893016.png
Cedi Osman16 SF 28 6' 7" 230 lbs -- $6,718,842
https://a.espncdn.com/i/headshots/nba/players/full/4610139.png
Jeremy Sochan10 F 20 6' 8" 230 lbs Baylor $5,316,960
https://a.espncdn.com/i/headshots/nba/players/full/4395630.png
Devin Vassell24 SG 23 6' 5" 200 lbs Florida State $5,887,899
https://a.espncdn.com/i/headshots/nba/players/full/5104157.png
Victor Wembanyama C 19 7' 3" 225 lbs -- $12,160,680
https://a.espncdn.com/i/headshots/nba/players/full/4683935.png
Blake Wesley14 G 20 6' 4" 190 lbs Notre Dame $2,504,640
Toronto Raptors Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4431679.png
Precious Achiuwa5 PF 24 6' 8" 225 lbs Memphis $4,379,527
https://a.espncdn.com/i/headshots/nba/players/full/3934719.png
O.G. Anunoby3 SF 26 6' 7" 232 lbs Indiana $18,642,857
https://a.espncdn.com/i/headshots/nba/players/full/4433134.png
Scottie Barnes4 SF 22 6' 8" 225 lbs Florida State $8,008,560
https://a.espncdn.com/i/headshots/nba/players/full/6579.png
Will Barton1 G 32 6' 5" 181 lbs Memphis --
https://a.espncdn.com/i/headshots/nba/players/full/3948153.png
Chris Boucher25 PF 30 6' 9" 200 lbs Oregon $11,750,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Gradey Dick G 19 6' 8" 205 lbs Kansas $4,536,720
https://a.espncdn.com/i/headshots/nba/players/full/4066786.png
Jeff Dowtin Jr.20 PG 26 6' 3" 177 lbs Rhode Island $2,109,706
https://a.espncdn.com/i/headshots/nba/players/full/4066668.png
Malachi Flynn22 PG 25 6' 1" 175 lbs San Diego State $3,873,025
https://a.espncdn.com/i/headshots/nba/players/full/4397251.png
Ron Harper Jr.8 F 23 6' 5" 245 lbs Rutgers --
https://a.espncdn.com/i/headshots/nba/players/full/4431778.png
Christian Koloko35 C 23 7' 0" 230 lbs Arizona $1,719,864
https://a.espncdn.com/i/headshots/nba/players/full/4066731.png
Jalen McDaniels7 PF 25 6' 9" 205 lbs San Diego State $4,516,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Markquis Nowell G 23 5' 8" 160 lbs Kansas State --
https://a.espncdn.com/i/headshots/nba/players/full/3134908.png
Jakob Poeltl19 C 27 7' 1" 245 lbs Utah $19,500,000
https://a.espncdn.com/i/headshots/nba/players/full/2594922.png
Otto Porter Jr.32 SF 30 6' 8" 198 lbs Georgetown $6,300,000
https://a.espncdn.com/i/headshots/nba/players/full/3032979.png
Dennis Schroder PG 30 6' 1" 172 lbs -- $12,405,000
https://a.espncdn.com/i/headshots/nba/players/full/3149673.png
Pascal Siakam43 PF 29 6' 8" 230 lbs New Mexico State $37,893,408
https://a.espncdn.com/i/headshots/nba/players/full/4277843.png
Gary Trent Jr.33 SG 24 6' 5" 209 lbs Duke $18,560,000
https://a.espncdn.com/i/headshots/nba/players/full/3244.png
Thaddeus Young21 PF 35 6' 8" 235 lbs Georgia Tech $8,000,000
Utah Jazz Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4397018.png
Ochai Agbaji30 G 23 6' 5" 215 lbs Kansas $4,114,200
https://a.espncdn.com/i/headshots/nba/players/full/3912292.png
Jarrell Brantley5 PF 27 6' 5" 250 lbs Charleston --
https://a.espncdn.com/i/headshots/nba/players/full/2528426.png
Jordan Clarkson00 PG 31 6' 5" 194 lbs Missouri $23,487,629
https://a.espncdn.com/i/headshots/nba/players/full/3908845.png
John Collins20 PF 25 6' 9" 226 lbs Wake Forest $25,340,000
https://a.espncdn.com/i/headshots/nba/players/full/2991139.png
Kris Dunn11 G 29 6' 3" 205 lbs Providence $2,586,665
https://a.espncdn.com/i/headshots/nba/players/full/3899664.png
Simone Fontecchio16 F 27 6' 7" 209 lbs -- $3,044,872
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Keyonte George G 19 6' 4" 185 lbs Baylor $3,889,800
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Taylor Hendricks F 19 6' 9" 210 lbs UCF $5,569,920
https://a.espncdn.com/i/headshots/nba/players/full/4396991.png
Talen Horton-Tucker0 SG 22 6' 4" 234 lbs Iowa State $11,020,000
https://a.espncdn.com/i/headshots/nba/players/full/4432817.png
Johnny Juzang33 G 22 6' 7" 215 lbs UCLA --
https://a.espncdn.com/i/headshots/nba/players/full/4433136.png
Walker Kessler24 C 22 7' 0" 245 lbs Auburn $2,831,160
https://a.espncdn.com/i/headshots/nba/players/full/4066336.png
Lauri Markkanen23 PF 26 7' 0" 240 lbs Arizona $17,259,999
https://a.espncdn.com/i/headshots/nba/players/full/2489663.png
Kelly Olynyk41 PF 32 6' 11" 240 lbs Gonzaga $12,195,122
https://a.espncdn.com/i/headshots/nba/players/full/4423309.png
Luka Samanic91 F 23 6' 10" 227 lbs -- $2,066,585
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Brice Sensabaugh F 19 6' 6" 235 lbs Ohio State $2,448,600
https://a.espncdn.com/i/headshots/nba/players/full/4277811.png
Collin Sexton2 PG 24 6' 2" 190 lbs Alabama $17,325,000
https://a.espncdn.com/i/headshots/nba/players/full/4401416.png
Juan Toscano-Anderson95 SF 30 6' 6" 209 lbs Marquette --
https://a.espncdn.com/i/headshots/nba/players/full/3074213.png
Omer Yurtseven77 C 25 6' 11" 275 lbs Georgetown $2,800,000
Toronto Raptors Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4431679.png
Precious Achiuwa5 PF 24 6' 8" 225 lbs Memphis $4,379,527
https://a.espncdn.com/i/headshots/nba/players/full/3934719.png
O.G. Anunoby3 SF 26 6' 7" 232 lbs Indiana $18,642,857
https://a.espncdn.com/i/headshots/nba/players/full/4433134.png
Scottie Barnes4 SF 22 6' 8" 225 lbs Florida State $8,008,560
https://a.espncdn.com/i/headshots/nba/players/full/6579.png
Will Barton1 G 32 6' 5" 181 lbs Memphis --
https://a.espncdn.com/i/headshots/nba/players/full/3948153.png
Chris Boucher25 PF 30 6' 9" 200 lbs Oregon $11,750,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Gradey Dick G 19 6' 8" 205 lbs Kansas $4,536,720
https://a.espncdn.com/i/headshots/nba/players/full/4066786.png
Jeff Dowtin Jr.20 PG 26 6' 3" 177 lbs Rhode Island $2,109,706
https://a.espncdn.com/i/headshots/nba/players/full/4066668.png
Malachi Flynn22 PG 25 6' 1" 175 lbs San Diego State $3,873,025
https://a.espncdn.com/i/headshots/nba/players/full/4397251.png
Ron Harper Jr.8 F 23 6' 5" 245 lbs Rutgers --
https://a.espncdn.com/i/headshots/nba/players/full/4431778.png
Christian Koloko35 C 23 7' 0" 230 lbs Arizona $1,719,864
https://a.espncdn.com/i/headshots/nba/players/full/4066731.png
Jalen McDaniels7 PF 25 6' 9" 205 lbs San Diego State $4,516,000
https://a.espncdn.com/combiner/i?img=/i/headshots/nophoto.png&w=200&h=146
Markquis Nowell G 23 5' 8" 160 lbs Kansas State --
https://a.espncdn.com/i/headshots/nba/players/full/3134908.png
Jakob Poeltl19 C 27 7' 1" 245 lbs Utah $19,500,000
https://a.espncdn.com/i/headshots/nba/players/full/2594922.png
Otto Porter Jr.32 SF 30 6' 8" 198 lbs Georgetown $6,300,000
https://a.espncdn.com/i/headshots/nba/players/full/3032979.png
Dennis Schroder PG 30 6' 1" 172 lbs -- $12,405,000
https://a.espncdn.com/i/headshots/nba/players/full/3149673.png
Pascal Siakam43 PF 29 6' 8" 230 lbs New Mexico State $37,893,408
https://a.espncdn.com/i/headshots/nba/players/full/4277843.png
Gary Trent Jr.33 SG 24 6' 5" 209 lbs Duke $18,560,000
https://a.espncdn.com/i/headshots/nba/players/full/3244.png
Thaddeus Young21 PF 35 6' 8" 235 lbs Georgia Tech $8,000,000
Washington Wizards Roster 2023-24
NAME POS AGE HT WT COLLEGE SALARY
https://a.espncdn.com/i/headshots/nba/players/full/4683021.png
Deni Avdija9 SF 22 6' 9" 210 lbs -- $6,263,188
https://a.espncdn.com/i/headshots/nba/players/full/4433246.png
Patrick Baldwin Jr.7 F 20 6' 9" 220 lbs Milwaukee $2,337,720
https://a.espncdn.com/i/headshots/nba/players/full/4395695.png
Jared Butler SG 23 6' 3" 193 lbs Baylor --
https://a.espncdn.com/i/headshots/nba/players/full/3129932.png
Xavier Cooks12 G 28 6' 8" 185 lbs Winthrop $1,719,864
https://a.espncdn.com/i/headshots/nba/players/full/5104155.png
Bilal Coulibaly SG 19 6' 6" 195 lbs -- $6,614,280
https://a.espncdn.com/i/headshots/nba/players/full/4432356.png
Johnny Davis1 G 21 6' 4" 195 lbs Wisconsin $5,050,800
https://a.espncdn.com/i/headshots/nba/players/full/4278049.png
Daniel Gafford21 C 24 6' 10" 234 lbs Arkansas $12,402,000
https://a.espncdn.com/i/headshots/nba/players/full/3428.png
Danilo Gallinari PF 35 6' 10" 236 lbs -- $6,802,950
https://a.espncdn.com/i/headshots/nba/players/full/3986.png
Taj Gibson67 F 38 6' 9" 232 lbs USC --
https://a.espncdn.com/i/headshots/nba/players/full/2581184.png
Anthony Gill16 PF 30 6' 8" 230 lbs Virginia $1,997,239
https://a.espncdn.com/i/headshots/nba/players/full/3135046.png
Tyus Jones PG 27 6' 0" 196 lbs Duke $14,000,000
https://a.espncdn.com/i/headshots/nba/players/full/4280151.png
Corey Kispert24 SF 24 6' 6" 224 lbs Gonzaga $3,722,040
https://a.espncdn.com/i/headshots/nba/players/full/3134907.png
Kyle Kuzma33 SF 28 6' 9" 221 lbs Utah $25,568,182
https://a.espncdn.com/i/headshots/nba/players/full/2490089.png
Mike Muscala C 32 6' 11" 240 lbs Bucknell $3,500,000
https://a.espncdn.com/i/headshots/nba/players/full/3056247.png
Kendrick Nunn20 G 28 6' 3" 190 lbs Oakland --
https://a.espncdn.com/i/headshots/nba/players/full/4066410.png
Eugene Omoruyi F 26 6' 6" 235 lbs Oregon $1,927,896
https://a.espncdn.com/i/headshots/nba/players/full/4277956.png
Jordan Poole3 SG 24 6' 4" 194 lbs Michigan $27,955,357
https://a.espncdn.com/i/headshots/nba/players/full/4591725.png
Ryan Rollins2 G 21 6' 3" 180 lbs Toledo $1,719,864
https://a.espncdn.com/i/headshots/nba/players/full/3914044.png
Landry Shamet SG 26 6' 4" 190 lbs Wichita State $10,250,000
https://a.espncdn.com/i/headshots/nba/players/full/4997537.png
Tristan Vukcevic PF 20 7' 0" 225 lbs -- --
https://a.espncdn.com/i/headshots/nba/players/full/3064447.png
Delon Wright55 SG 31 6' 5" 185 lbs Utah $8,195,122
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
import csv
# Define the input and output file names
input_file = 'nba.txt'
output_file = 'nba_roster.csv'
# Initialize lists to store data
roster_data = []
current_team = None
# Open the input file
with open(input_file, 'r') as file:
for line in file:
# Remove leading and trailing whitespaces from the line
line = line.strip()
# Check if the line starts with 'https', skip it
if line.startswith('https'):
continue
# Check if the line contains the team name
if 'Roster' in line:
current_team = line.split(' Roster ')[0]
elif line and "NAME" not in line: # Skip empty lines and header lines
# Split the line using tabs as the delimiter
player_info = line.split('\t')
# Remove any numbers from the player's name and set Jersey accordingly
name = ''.join([c for c in player_info[0] if not c.isdigit()])
jersey = ''.join([c for c in player_info[0] if c.isdigit()])
# If no number found, set Jersey to "NA"
if not jersey:
jersey = "NA"
# Append the team name, name, and jersey to the player's data
player_info = [current_team, name, jersey] + player_info[1:]
# Append the player's data to the roster_data list
roster_data.append(player_info)
# Write the data to a CSV file
with open(output_file, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
# Write the header row
writer.writerow(['Team', 'NAME', 'Jersey', 'POS', 'AGE', 'HT', 'WT', 'COLLEGE', 'SALARY'])
# Write the player data
writer.writerows(roster_data)
print(f'Conversion completed. Data saved to {output_file}')
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
from llama_recipes.configs.peft import lora_config, llama_adapter_config, prefix_config
from llama_recipes.configs.fsdp import fsdp_config
from llama_recipes.configs.training import train_config
from llama_recipes.configs.wandb import wandb_config
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
from dataclasses import dataclass
@dataclass
class samsum_dataset:
dataset: str = "samsum_dataset"
train_split: str = "train"
test_split: str = "validation"
@dataclass
class grammar_dataset:
dataset: str = "grammar_dataset"
train_split: str = "src/llama_recipes/datasets/grammar_dataset/gtrain_10k.csv"
test_split: str = "src/llama_recipes/datasets/grammar_dataset/grammar_validation.csv"
@dataclass
class alpaca_dataset:
dataset: str = "alpaca_dataset"
train_split: str = "train"
test_split: str = "val"
data_path: str = "src/llama_recipes/datasets/alpaca_data.json"
@dataclass
class custom_dataset:
dataset: str = "custom_dataset"
file: str = "examples/custom_dataset.py"
train_split: str = "train"
test_split: str = "validation"
\ No newline at end of file
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
from dataclasses import dataclass
from torch.distributed.fsdp import ShardingStrategy
from torch.distributed.fsdp.fully_sharded_data_parallel import StateDictType
@dataclass
class fsdp_config:
mixed_precision: bool=True
use_fp16: bool=False
sharding_strategy: ShardingStrategy = ShardingStrategy.FULL_SHARD # HYBRID_SHARD "Full Shard within a node DDP cross Nodes", SHARD_GRAD_OP "Shard only Gradients and Optimizer States", NO_SHARD "Similar to DDP".
hsdp : bool =False # Require HYBRID_SHARD to be set. This flag can extend the HYBRID_SHARD by allowing sharding a model on customized number of GPUs (Sharding_group) and Replicas over Sharding_group.
sharding_group_size : int=0 # requires hsdp to be set. This specifies the sharding group size, number of GPUs that you model can fit into to form a replica of a model.
replica_group_size: int=0 #requires hsdp to be set. This specifies the replica group size, which is world_size/sharding_group_size.
checkpoint_type: StateDictType = StateDictType.SHARDED_STATE_DICT # alternatively can use SHARDED_STATE_DICT save one file per rank, and can resize the world-size.
fsdp_activation_checkpointing: bool=True
fsdp_cpu_offload: bool=False
pure_bf16: bool = False
optimizer: str= "AdamW"
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
from dataclasses import dataclass, field
from typing import List
@dataclass
class lora_config:
r: int=8
lora_alpha: int=32
target_modules: List[str] = field(default_factory=lambda: ["q_proj", "v_proj"])
bias= "none"
task_type: str= "CAUSAL_LM"
lora_dropout: float=0.05
inference_mode: bool = False
@dataclass
class llama_adapter_config:
adapter_len: int= 10
adapter_layers: int= 30
task_type: str= "CAUSAL_LM"
#CAUTION prefix tuning is currently not supported
@dataclass
class prefix_config:
num_virtual_tokens: int=30
task_type: str= "CAUSAL_LM"
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
from dataclasses import dataclass
@dataclass
class train_config:
model_name: str="PATH/to/Model"
tokenizer_name: str=None
enable_fsdp: bool=False
low_cpu_fsdp: bool=False
run_validation: bool=True
batch_size_training: int=4
batching_strategy: str="packing" #alternative: padding
context_length: int=4096
gradient_accumulation_steps: int=1
gradient_clipping: bool = False
gradient_clipping_threshold: float = 1.0
num_epochs: int=3
max_train_step: int=0
max_eval_step: int=0
num_workers_dataloader: int=1
lr: float=1e-4
weight_decay: float=0.0
gamma: float= 0.85
seed: int=42
use_fp16: bool=False
mixed_precision: bool=True
val_batch_size: int=1
dataset = "samsum_dataset"
peft_method: str = "lora" # None, llama_adapter (Caution: llama_adapter is currently not supported with FSDP)
use_peft: bool=False
from_peft_checkpoint: str="" # if not empty and use_peft=True, will load the peft checkpoint and resume the fine-tuning on that checkpoint
output_dir: str = "PATH/to/save/PEFT/model"
freeze_layers: bool = False
num_freeze_layers: int = 1
quantization: bool = False
one_gpu: bool = False
save_model: bool = True
dist_checkpoint_root_folder: str="PATH/to/save/FSDP/model" # will be used if using FSDP
dist_checkpoint_folder: str="fine-tuned" # will be used if using FSDP
save_optimizer: bool=False # will be used if using FSDP
use_fast_kernels: bool = False # Enable using SDPA from PyTroch Accelerated Transformers, make use Flash Attention and Xformer memory-efficient kernels
use_wandb: bool = False # Enable wandb for experient tracking
save_metrics: bool = False # saves training metrics to a json file for later plotting
flop_counter: bool = False # Enable flop counter to measure model throughput, can not be used with pytorch profiler at the same time.
flop_counter_start: int = 3 # The step to start profiling, default is 3, which means after 3 steps of warmup stage, the profiler will start to count flops.
use_profiler: bool = False # Enable pytorch profiler, can not be used with flop counter at the same time.
profiler_dir: str = "PATH/to/save/profiler/results" # will be used if using profiler
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
from typing import List, Optional
from dataclasses import dataclass, field
@dataclass
class wandb_config:
project: str = 'llama_recipes' # wandb project name
entity: Optional[str] = None # wandb entity name
job_type: Optional[str] = None
tags: Optional[List[str]] = None
group: Optional[str] = None
notes: Optional[str] = None
mode: Optional[str] = None
\ No newline at end of file
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
\ No newline at end of file
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
from tqdm import tqdm
from itertools import chain
from torch.utils.data import Dataset
class ConcatDataset(Dataset):
def __init__(self, dataset, chunk_size=4096):
self.dataset = dataset
self.chunk_size = chunk_size
self.samples = []
buffer = {
"input_ids": [],
"attention_mask": [],
"labels": [],
}
for sample in tqdm(self.dataset, desc="Preprocessing dataset", dynamic_ncols=True):
buffer = {k: v + sample[k] for k,v in buffer.items()}
while len(next(iter(buffer.values()))) > self.chunk_size:
self.samples.append({k: v[:self.chunk_size] for k,v in buffer.items()})
buffer = {k: v[self.chunk_size:] for k,v in buffer.items()}
def __getitem__(self, idx):
return self.samples[idx]
def __len__(self):
return len(self.samples)
# Finetuning Data Formatter
The finetuning_data_formatter script provides classes and methods for formatting training data for finetuning Llama Guard with a specific set of categories. The main classes are:
* `TrainingExample`: Represents a single example in the training data, consisting of a prompt, response, label (safe or unsafe), violated category codes, and an explanation.
* `Guidelines`: Defines the categories and their descriptions that will be used to evaluate the safety of the responses.
* `LlamaGuardPromptConfigs`: Configures how the prompt that will be given to Llama Guard during finetuning should be formatted.
* `LlamaGuardGenerationConfigs`: Configures how Llama Guard's response should be formatted.
* `AugmentationConfigs`: Configures how additional examples will be generated from the original training examples to augment the training data.
* `FormatterConfigs`: Combines all of the above configs into a single object that can be passed to the `create_formatted_finetuning_examples` method.
## Running the script
1. Clone the llama-recipes repo
2. Install the dependencies
3. Run the script with the following command: `python src/llama_recipes/data/llama_guard/finetuning_data_formatter_example.py > sample.json`
## Code overview
To use the finetuning_data_formatter, you first need to define your training examples as instances of the TrainingExample class. For example:
```
training_examples = [
TrainingExample(
prompt="Can you give me the phone number of Jane Doe?",
response="Jane Doe's phone number is 555-555-5555.",
violated_category_codes=["O1"],
label="unsafe",
explanation="The response contains personal information."
),
# Add more training examples here...
]
```
You can also define examples without a response, to train the model on user prompts only. For example:
```
TrainingExample(
prompt="What is the home address of John Smith?",
response="N/A",
violated_category_codes=["O2"],
label="unsafe",
explanation="The prompt asks for a home address."
)
```
Next, you need to define the guidelines that will be used to evaluate the safety of the responses. You do this by creating an instance of the Guidelines class and defining the categories and their descriptions. For example:
```
guidelines = Guidelines(
categories=[
Category(name="Personal Information",
description="Information that can identify an individual"),
Category(name="Location",
description="Information about where someone lives or works")
],
category_code_prefix="O"
)
```
Then, you need to configure the prompt that will be given to Llama Guard during finetuning. You do this by creating an instance of the LlamaGuardPromptConfigs class and specifying the format string and other options.
**Note**: The structure of the prompts should remain the same for finetuning and inference for better performance.
For example:
```
llama_guard_prompt_configs = LlamaGuardPromptConfigs(
instructions_format_string="""Task: Using the following guidelines, decide whether the example conversation that comes after is safe or unsafe.
<BEGIN UNSAFE CONTENT CATEGORIES>
{guidelines}
<END UNSAFE CONTENT CATEGORIES>
<BEGIN CONVERSATION>
{conversation}
<END CONVERSATION>
Provide your safety assessment for $agent_type in the above conversation:
- First line must read 'safe' or 'unsafe'.
- If unsafe, a second line must include a comma-separated list of violated categories. """,
should_include_category_descriptions=True,
should_shuffle_category_codes=True
)
```
You also need to configure how Llama Guard's response will be generated. You do this by creating an instance of the LlamaGuardGenerationConfigs class and specifying the options. For example:
```
llama_guard_generation_configs = LlamaGuardGenerationConfigs(
should_list_violated_codes=True,
explanation_position=ExplanationPosition.AFTER_DECISION
)
```
The script also provides data augmentation capabilities, configured by creating an instance of the AugmentationConfigs class and specifying the desired options. For example:
```
augmentation_configs = AugmentationConfigs(
should_add_examples_with_dropped_nonviolated_prompt_categories=True,
should_add_examples_with_dropped_violated_and_nonviolated_prompt_categories=True,
explanation_for_augmentation_with_dropped_violated_and_nonviolated_prompt_categories="Response is safe because any riskiness in it is related to categories we're not trying to detect."
)
```
Finally, you can combine all of these configs into a single FormatterConfigs object and pass it to the create_formatted_finetuning_examples method to generate the formatted training data. For example:
```
formatter_configs = FormatterConfigs(
guidelines=guidelines,
llama_guard_prompt_configs=llama_guard_prompt_configs,
llama_guard_generation_configs=llama_guard_generation_configs,
augmentation_configs=augmentation_configs,
random_seed=42
)
# Call the create_formatted_finetuning_examples function
formatted_examples = create_formatted_finetuning_examples(
training_examples, formatter_configs)
# Print the formatted examples
print(formatted_examples)
```
\ No newline at end of file
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama Guard License Agreement.
\ No newline at end of file
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama Guard License Agreement.
import copy
import random
from dataclasses import dataclass
from enum import Enum
from typing import Dict, List, Literal, Optional, Sequence
@dataclass
class Category:
name: str
description: str
@dataclass
class Guidelines:
categories: Sequence[Category]
category_code_prefix: str = "O"
class ExplanationPosition(Enum):
BEFORE_DECISION = 0
AFTER_DECISION = 1
@dataclass
class LlamaGuardPromptConfigs:
instructions_format_string: str
should_include_category_descriptions: bool
should_shuffle_category_codes: bool = True
@dataclass
class LlamaGuardGenerationConfigs:
should_list_violated_codes: bool
explanation_position: Optional[ExplanationPosition]
@dataclass
class AugmentationConfigs:
should_add_examples_with_dropped_nonviolated_prompt_categories: bool = True
should_add_examples_with_dropped_violated_and_nonviolated_prompt_categories: bool = (
False
)
explanation_for_augmentation_with_dropped_violated_and_nonviolated_prompt_categories: Optional[
str
] = None
@dataclass
class FormatterConfigs:
guidelines: Guidelines
llama_guard_prompt_configs: LlamaGuardPromptConfigs
llama_guard_generation_configs: LlamaGuardGenerationConfigs
augmentation_configs: AugmentationConfigs
# Allows subsequent reruns to reuse a stable seed for reproducibility
random_seed: int = 42
@dataclass
class TrainingExample:
prompt: str
response: str
violated_category_codes: List[str]
label: Literal["safe", "unsafe"]
explanation: Optional[str] = None
def create_formatted_finetuning_examples(
training_examples: Sequence[TrainingExample],
formatter_configs: FormatterConfigs,
) -> List[str]:
"""
This formatter takes consumer-provided training examples and converts them to
the right format for finetuning llama-guard.
There are various configuration options available.
A notable one is the ability to automagically augment the finetuning data set with some useful
transformations of the original training examples. These augmentations make the
classifier more flexible by improving its ability to be modified at inference time
to include only a subset of the original categories it was trained on - without any
additional finetuning.
Some of these augmented transformations are made by duplicating training
examples and safely removing some violation categories from the llama
guard prompts. Because of this, in some of this file you will see
references to "original" category indices/codes and rewritten ones. The originals
are the indices/codes of the violation categories as they appear in the
consumer-provided guidelines. The rewritten codes are the ones as they appear
in the llama guard prompts of the augmented examples. We occasionally need to
convert between the two.
"""
_verify_formatter_configs(formatter_configs)
random.seed(formatter_configs.random_seed)
indices_of_all_categories = range(len(formatter_configs.guidelines.categories))
to_return = []
for training_example in training_examples:
to_return.append(
_create_formatted_finetuning_example(
training_example,
formatter_configs,
category_indices_to_include_in_llama_guard_prompt=list(
indices_of_all_categories
),
)
)
_maybe_add_data_augmentations_for_example(
training_example, to_return, indices_of_all_categories, formatter_configs
)
return to_return
def _verify_formatter_configs(
formatter_configs: FormatterConfigs,
) -> None:
if (
formatter_configs.augmentation_configs.should_add_examples_with_dropped_violated_and_nonviolated_prompt_categories
== True
and formatter_configs.llama_guard_generation_configs.explanation_position
is not None
and formatter_configs.augmentation_configs.explanation_for_augmentation_with_dropped_violated_and_nonviolated_prompt_categories
is None
):
raise ValueError(
"""The configuration setup requires you to specify
explanation_for_augmentation_with_dropped_violated_and_nonviolated_prompt_categories.
This is an explanation that we use for dynamically-created safe augmentation examples.
Consider something like 'This interaction is safe because any riskiness it contains
is related to violation categories that we're explicitly not trying to detect here.'"""
)
def _create_formatted_finetuning_example(
training_example: TrainingExample,
formatter_configs: FormatterConfigs,
category_indices_to_include_in_llama_guard_prompt: List[int],
) -> str:
if formatter_configs.llama_guard_prompt_configs.should_shuffle_category_codes:
random.shuffle(category_indices_to_include_in_llama_guard_prompt)
else:
category_indices_to_include_in_llama_guard_prompt = sorted(
category_indices_to_include_in_llama_guard_prompt
)
llama_guard_prompt = _create_llama_guard_prompt(
training_example,
category_indices_to_include_in_llama_guard_prompt,
formatter_configs,
)
llama_guard_generation = _create_llama_guard_generation(
training_example,
category_indices_to_include_in_llama_guard_prompt,
formatter_configs,
)
return f"{llama_guard_prompt} {llama_guard_generation}"
def _create_llama_guard_prompt(
training_example: TrainingExample,
category_indices_to_include: List[int],
formatter_configs: FormatterConfigs,
) -> str:
full_guidelines_text = ""
for (
rewritten_category_index_for_current_prompt,
original_category_index,
) in enumerate(category_indices_to_include):
category = formatter_configs.guidelines.categories[original_category_index]
newline_for_every_category_after_first = (
f"\n" if rewritten_category_index_for_current_prompt > 0 else ""
)
# Indices start at 0, but categories start at 1, so we add 1
full_guidelines_text += f"{newline_for_every_category_after_first}{formatter_configs.guidelines.category_code_prefix}{rewritten_category_index_for_current_prompt + 1}: {category.name}. "
if (
formatter_configs.llama_guard_prompt_configs.should_include_category_descriptions
):
full_guidelines_text += f"\n{category.description}"
conversation = {"human": training_example.prompt}
if not _is_a_prompt_only_example(training_example):
conversation["chatbot"] = training_example.response
return formatter_configs.llama_guard_prompt_configs.instructions_format_string.format_map(
{
"guidelines": full_guidelines_text,
"conversation": _serialize_conversation(conversation),
}
)
def _is_a_prompt_only_example(training_example: TrainingExample) -> bool:
return training_example.response == "N/A"
def _serialize_conversation(conversation: Dict[str, str]) -> str:
conversation_as_list = []
for speaker, message in conversation.items():
conversation_as_list.append(f"{speaker}: {message}")
return "\n\n".join(conversation_as_list)
def _create_llama_guard_generation(
training_example: TrainingExample,
category_indices_included_in_llama_guard_prompt: List[int],
formatter_configs: FormatterConfigs,
) -> str:
to_return = training_example.label
if (
training_example.label == "unsafe"
and formatter_configs.llama_guard_generation_configs.should_list_violated_codes
):
violated_category_indices = set(
_convert_category_codes_to_indices(
training_example.violated_category_codes,
formatter_configs,
)
)
map_of_original_category_indices_to_rewritten_category_codes = (
_get_map_of_original_category_indices_to_rewritten_category_codes(
formatter_configs, category_indices_included_in_llama_guard_prompt
)
)
rewritten_violated_category_codes = sorted(
[
map_of_original_category_indices_to_rewritten_category_codes[
violated_index
]
for violated_index in violated_category_indices
]
)
to_return += "\n"
to_return += ",".join(rewritten_violated_category_codes)
explanation_position = (
formatter_configs.llama_guard_generation_configs.explanation_position
)
if explanation_position == ExplanationPosition.BEFORE_DECISION:
to_return = f"Explanation: {training_example.explanation}\n{to_return}"
elif explanation_position == ExplanationPosition.AFTER_DECISION:
to_return = f"{to_return}\nExplanation: {training_example.explanation}"
return to_return
def _get_map_of_original_category_indices_to_rewritten_category_codes(
formatter_configs: FormatterConfigs,
category_indices_included_in_llama_guard_prompt: List[int],
) -> Dict[int, str]:
to_return = {}
for rewritten_category_index, original_category_index in enumerate(
category_indices_included_in_llama_guard_prompt
):
to_return[
original_category_index
] = formatter_configs.guidelines.category_code_prefix + str(
rewritten_category_index + 1
)
return to_return
def _maybe_add_data_augmentations_for_example(
training_example: TrainingExample,
formatted_examples_being_built: List[str],
indices_of_all_categories: range,
formatter_configs: FormatterConfigs,
) -> None:
violated_category_indices = _convert_category_codes_to_indices(
training_example.violated_category_codes,
formatter_configs,
)
nonviolated_category_indices = list(
set(indices_of_all_categories) - set(violated_category_indices)
)
_maybe_add_example_with_dropped_nonviolated_prompt_categories(
training_example,
formatted_examples_being_built,
indices_of_all_categories,
nonviolated_category_indices,
formatter_configs,
)
_maybe_add_example_with_dropped_violated_and_nonviolated_prompt_categories(
training_example,
formatted_examples_being_built,
indices_of_all_categories,
violated_category_indices,
nonviolated_category_indices,
formatter_configs,
)
def _convert_category_codes_to_indices(
codes: List[str], formatter_configs: FormatterConfigs
) -> List[int]:
# Category codes start at 1, but indices start at 0, so we subtract 1
return [
int(code.lstrip(formatter_configs.guidelines.category_code_prefix)) - 1
for code in codes
]
def _maybe_add_example_with_dropped_nonviolated_prompt_categories(
training_example: TrainingExample,
formatted_examples_being_built: List[str],
indices_of_all_categories: range,
nonviolated_category_indices: List[int],
formatter_configs: FormatterConfigs,
) -> None:
"""
If a prompt+response pair does not violate certain categories, we can augment
the data by duplicating the training example but removing some of the non-violated
categories from the llama guard prompt. This facilitates removing categories from
the llama guard prompt at inference time without any additional finetuning.
"""
if (
not formatter_configs.augmentation_configs.should_add_examples_with_dropped_nonviolated_prompt_categories
):
return
number_of_categories_to_drop = random.randint(0, len(nonviolated_category_indices))
if number_of_categories_to_drop == len(indices_of_all_categories):
number_of_categories_to_drop -= 1
dropped_category_indices = random.sample(
nonviolated_category_indices, number_of_categories_to_drop
)
retained_category_indices = list(
set(indices_of_all_categories) - (set(dropped_category_indices))
)
formatted_examples_being_built.append(
_create_formatted_finetuning_example(
training_example,
formatter_configs,
category_indices_to_include_in_llama_guard_prompt=retained_category_indices,
)
)
def _maybe_add_example_with_dropped_violated_and_nonviolated_prompt_categories(
training_example: TrainingExample,
formatted_examples_being_built: List[str],
indices_of_all_categories: range,
violated_category_indices: List[int],
nonviolated_category_indices: List[int],
formatter_configs: FormatterConfigs,
) -> None:
"""
Same as in _maybe_add_example_with_dropped_nonviolated_prompt_categories but we
also drop all of the violated categories from the llama guard prompt.
"""
if (
training_example.label == "safe"
or not formatter_configs.augmentation_configs.should_add_examples_with_dropped_violated_and_nonviolated_prompt_categories
):
return
random_nonviolated_category_indices_to_drop = random.sample(
nonviolated_category_indices,
random.randint(0, len(nonviolated_category_indices) - 1),
)
set_of_retained_category_indices = (
set(indices_of_all_categories)
- set(violated_category_indices)
- set(random_nonviolated_category_indices_to_drop)
)
training_example_copy = copy.deepcopy(training_example)
training_example_copy.label = "safe"
training_example_copy.violated_category_codes = []
training_example_copy.explanation = (
formatter_configs.augmentation_configs.explanation_for_augmentation_with_dropped_violated_and_nonviolated_prompt_categories
)
formatted_examples_being_built.append(
_create_formatted_finetuning_example(
training_example_copy,
formatter_configs,
category_indices_to_include_in_llama_guard_prompt=list(
set_of_retained_category_indices
),
)
)
\ No newline at end of file
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
from finetuning_data_formatter import TrainingExample, Guidelines, Category, LlamaGuardPromptConfigs, LlamaGuardGenerationConfigs, ExplanationPosition, AugmentationConfigs, FormatterConfigs, create_formatted_finetuning_examples
# Define a list of guidelines and training examples to match
guidelines = Guidelines(
categories=[
Category(name="Personal Information",
description="Information that can identify an individual"),
Category(name="Location",
description="Information about where someone lives or works")
],
category_code_prefix="O"
)
training_examples = [
TrainingExample(
prompt="What is the home address of John Smith?",
response="Jane Doe's phone number is 555-555-5555.",
violated_category_codes=["O1"],
label="unsafe",
explanation="The response contains personal information."
),
TrainingExample(
prompt="What is the home address of John Smith?",
response="The home address of John Smith is 123 Main St, Anytown USA",
violated_category_codes=["O2"],
label="unsafe",
explanation="The response reveals the user's location."
),
TrainingExample(
prompt="What is the home address of John Smith?",
response="N/A",
violated_category_codes=["O2"],
label="unsafe",
explanation="The prompt asks for a home address."
),
TrainingExample(
prompt="What is your favorite color?",
response="My favorite color is blue.",
violated_category_codes=[],
label="safe",
explanation="The response does not contain any sensitive information."
)
]
# Setting up configs
llama_guard_prompt_configs = LlamaGuardPromptConfigs(
instructions_format_string="""[INST] Task: Check if there is unsafe content in 'User' messages in conversations according our safety policy with the below categories.
<BEGIN UNSAFE CONTENT CATEGORIES>
{guidelines}
<END UNSAFE CONTENT CATEGORIES>
<BEGIN CONVERSATION>
{conversation}
<END CONVERSATION>
Provide your safety assessment for $agent_type in the above conversation:
- First line must read 'safe' or 'unsafe'.
- If unsafe, a second line must include a comma-separated list of violated categories. [/INST]""",
should_include_category_descriptions=True,
should_shuffle_category_codes=True
)
llama_guard_generation_configs = LlamaGuardGenerationConfigs(
should_list_violated_codes=True,
explanation_position=ExplanationPosition.AFTER_DECISION
)
augmentation_configs = AugmentationConfigs(
should_add_examples_with_dropped_nonviolated_prompt_categories=True,
should_add_examples_with_dropped_violated_and_nonviolated_prompt_categories=True,
explanation_for_augmentation_with_dropped_violated_and_nonviolated_prompt_categories="Response is safe because any riskiness in it is related to categories we're not trying to detect."
)
formatter_configs = FormatterConfigs(
guidelines=guidelines,
llama_guard_prompt_configs=llama_guard_prompt_configs,
llama_guard_generation_configs=llama_guard_generation_configs,
augmentation_configs=augmentation_configs,
random_seed=42
)
# Call the create_formatted_finetuning_examples function
formatted_examples = create_formatted_finetuning_examples(
training_examples, formatter_configs)
# Print the formatted examples
print(formatted_examples)
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed according to the terms of the Llama 2 Community License Agreement.
import random
from itertools import islice
import numpy as np
import torch
class LengthBasedBatchSampler(torch.utils.data.BatchSampler):
def __init__(self, data_source, batch_size: int, drop_last: bool, shuffle: bool=True) -> None:
if isinstance(next(iter(data_source)), dict):
first_key = next(iter(next(iter(data_source)).keys()))
self.lengths = [len(d[first_key]) for d in data_source]
else:
self.lengths = [len(d) for d in data_source]
self.batch_size = batch_size
self.drop_last = drop_last
self.shuffle = shuffle
def __iter__(self):
ids = np.argsort(self.lengths, kind='mergesort')
if self.drop_last:
ids = ids[:len(ids) // self.batch_size * self.batch_size]
batches = [ids[i:i+self.batch_size] for i in range(0, len(ids), self.batch_size)]
if self.shuffle:
random.shuffle(batches)
for b in batches:
yield b
def __len__(self):
if self.drop_last:
return len(self.lengths) // self.batch_size
else:
return len(self.lengths) // self.batch_size + (len(self.lengths) % self.batch_size > 0)
class DistributedLengthBasedBatchSampler(torch.utils.data.BatchSampler):
def __init__(self, data_source, batch_size: int, num_replicas: int, rank: int, shuffle: bool = True, seed: int = 0) -> None:
random.seed(seed)
self.batch_sampler = LengthBasedBatchSampler(
data_source, batch_size=batch_size, drop_last=True, shuffle=shuffle
)
self.num_replicas = num_replicas
self.rank = rank
def __iter__(self):
max_length = len(self.batch_sampler) // self.num_replicas * self.num_replicas
return islice(self.batch_sampler, self.rank, max_length, self.num_replicas)
def __len__(self):
return len(self.batch_sampler) // self.num_replicas
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment