DSPy: The framework for programming—not prompting—language models
Python
updating intro notebook
Sri Vardhamanan1e4bf2f715fb
diff --git a/intro.ipynb b/intro.ipynbindex 8cbf568ee..8fd0704d1 100644--- a/intro.ipynb+++ b/intro.ipynb@@ -1,7 +1,6 @@{"cells": [{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -13,7 +12,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -37,7 +35,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -79,7 +76,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -109,7 +105,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -140,7 +135,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -166,7 +160,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -188,7 +181,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -215,7 +207,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -277,7 +268,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -432,7 +422,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -466,7 +455,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -490,7 +478,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -572,7 +559,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -730,7 +716,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -765,7 +750,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -801,7 +785,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -891,7 +874,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -1042,7 +1024,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -1086,7 +1067,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -1111,7 +1091,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -1159,7 +1138,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -1303,7 +1281,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -1461,7 +1438,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -1475,7 +1451,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -1514,7 +1489,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -1934,7 +1908,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -2171,7 +2144,13 @@]},{- "attachments": {},+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": []+ },+ {"cell_type": "markdown","metadata": {},"source": [@@ -2196,7 +2175,6 @@]},{- "attachments": {},"cell_type": "markdown","metadata": {},"source": [@@ -2211,11 +2189,73 @@"source": ["# Program 4 with max_hops=4 and automatic stopping."]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "# Additional Capabilities"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## more LLMs for use\n",+ "Eventhough the most quality tested model is openai text-davinci, we also offer support for `openai chatgpt, cohere, and hf models`.\n",+ "\n",+ "`Note:` The quality and stability might be different based on the provider and the model. Please report any bugs that you come across."+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "# initializing chatgpt\n",+ "\n",+ "lm = dsp.GPT3(model='gpt-3.5-turbo', api_key=openai_key, model_type='chat')\n",+ "\n",+ "# initializing cohere\n",+ "\n",+ "lm = dsp.Cohere(model='command-xlarge-nightly')\n",+ "\n",+ "# initializing hf models\n",+ "\n",+ "lm = dsp.HFModel(model=\"google/flan-t5-base\")"+ ]+ },+ {+ "cell_type": "markdown",+ "metadata": {},+ "source": [+ "## Re-Ranker\n",+ "\n",+ "You could also construct powerful retrieval programs that uses both `retriever and re-ranker model`.\n",+ "\n",+ "Currently, we support `Sentence-Transformers cross-encoder` for reranking, and an example initialisation and usage is provided below"+ ]+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "metadata": {},+ "outputs": [],+ "source": [+ "sbert_reranker = dsp.SentenceTransformersCrossEncoder(\"cross-encoder/ms-marco-MiniLM-L-12-v2\")\n",+ "\n",+ "dsp.settings.configure(lm=lm, rm=rm, reranker=sbert_reranker)\n",+ "\n",+ "# dsp.retrieve, and retrieveEnsemble already takes care of retrieving and re-ranking based on initiated rm, and reranker.\n",+ "\n",+ "reranked_passages = dsp.retrieve(\"When was the creator of Hadoop given an award?\", k=3)"+ ]}],"metadata": {"kernelspec": {- "display_name": "base",+ "display_name": "Python 3 (ipykernel)","language": "python","name": "python3"},@@ -2229,15 +2269,21 @@"name": "python","nbconvert_exporter": "python","pygments_lexer": "ipython3",- "version": "3.8.5"+ "version": "3.9.4"},- "orig_nbformat": 4,"vscode": {"interpreter": {"hash": "de72ef8826336f005e74d4a3f2b2dfb9239c3f097fd15aff69f3f6a4fc3bd8b8"}+ },+ "widgets": {+ "application/vnd.jupyter.widget-state+json": {+ "state": {},+ "version_major": 2,+ "version_minor": 0+ }}},"nbformat": 4,- "nbformat_minor": 2+ "nbformat_minor": 4}