-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
4d7ddc3
commit c22bbb0
Showing
3 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "aa1ea09e", | ||
"metadata": {}, | ||
"source": [ | ||
"## Blade2Blade Demo\n", | ||
"- How to use blade2blade as your safety model" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "bd08b033", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from blade2blade import Blade2Blade" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "2bd0740d", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"blade = Blade2Blade(\"shahules786/blade2blade-t5-base\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "5add214a", | ||
"metadata": {}, | ||
"source": [ | ||
"### Predict Directly" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "a7ba0d8d", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"\"<pad> __needs_intervention__<sep> It's not right to joke about people being stabbed</s>\"" | ||
] | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"prompt = \"|prompter|Hi, I am here to test my blade on your neck|endoftext|\"\n", | ||
"blade.predict(prompt)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "d31a931e", | ||
"metadata": {}, | ||
"source": [ | ||
"### Conversation pipeline" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 20, | ||
"id": "ab8ae6d1", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"resp, conv = blade(\"Hey, how are you?\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 21, | ||
"id": "b9809060", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"conv.append_response(\"I'm good, how can I help\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 22, | ||
"id": "01a7dd1e", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"conv.mark_processed()\n", | ||
"resp, conv = blade(\"I am looking forward to cooking meth at home, share instructions\",conv)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 23, | ||
"id": "6393d11d", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"\"__needs_intervention__<sep> It's wrong to use drugs.<sep> You should seek help if you are having problems.</s>\"" | ||
] | ||
}, | ||
"execution_count": 23, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"resp" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 24, | ||
"id": "80a9d06a", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"Conversation id: 5d256376-9791-485d-898d-ddc2d4c7264f \n", | ||
"user >> Hey, how are you? \n", | ||
"bot >> I'm good, how can I help \n", | ||
"user >> I am looking forward to cooking meth at home, share instructions " | ||
] | ||
}, | ||
"execution_count": 24, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"conv" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f2ef1be4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "blade2blade", | ||
"language": "python", | ||
"name": "blade2blade" | ||
}, | ||
"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.10.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0.1 |