Last active
June 17, 2023 20:00
-
-
Save itsuncheng/3d9a46c883ed70d733f11a7faec56b7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Import Library" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from transformers import pipeline, Conversation" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Build Conversational Pipeline" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"conversational_pipeline = pipeline(\"conversational\")" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Add Starting Conversations" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"[Conversation id: a9bae572-cc11-48c8-b36f-d88bcd49b8c0 \n", | |
" user >> Let's watch a movie tonight - any recommendations? \n", | |
" bot >> The Big Lebowski ,\n", | |
" Conversation id: e6ee2d97-5ee7-404b-b2e5-4dd527f9e9dd \n", | |
" user >> What's your favorite book? \n", | |
" bot >> The Hunger Games ]" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"conv1_start = \"Let's watch a movie tonight - any recommendations?\"\n", | |
"conv2_start = \"What's your favorite book?\"\n", | |
"\n", | |
"conv1 = Conversation(conv1_start)\n", | |
"conv2 = Conversation(conv2_start)\n", | |
"\n", | |
"conversational_pipeline([conv1, conv2])" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Add Continuing Conversations" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"[Conversation id: a9bae572-cc11-48c8-b36f-d88bcd49b8c0 \n", | |
" user >> Let's watch a movie tonight - any recommendations? \n", | |
" bot >> The Big Lebowski \n", | |
" user >> What is it about? \n", | |
" bot >> It's a comedy about a guy who gets a job at a movie theater and gets a bunch of jobs. ,\n", | |
" Conversation id: e6ee2d97-5ee7-404b-b2e5-4dd527f9e9dd \n", | |
" user >> What's your favorite book? \n", | |
" bot >> The Hunger Games \n", | |
" user >> Cool, what is the genre of the book? \n", | |
" bot >> I'm not sure, but I think it's fantasy. ]" | |
] | |
}, | |
"execution_count": 14, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"conv1_next = \"What is it about?\"\n", | |
"conv2_next = \"Cool, what is the genre of the book?\"\n", | |
"\n", | |
"conv1.add_user_input(conv1_next)\n", | |
"conv2.add_user_input(conv2_next)\n", | |
"\n", | |
"conversational_pipeline([conv1, conv2])" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"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.6.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment