|
190 | 190 | " print()"
|
191 | 191 | ]
|
192 | 192 | },
|
| 193 | + { |
| 194 | + "attachments": {}, |
| 195 | + "cell_type": "markdown", |
| 196 | + "id": "782ae8c8", |
| 197 | + "metadata": {}, |
| 198 | + "source": [ |
| 199 | + "## Customize Prompt\n", |
| 200 | + "\n", |
| 201 | + "You can also customize the prompt that is used. Here is an example prompting it using a score from 0 to 10.\n", |
| 202 | + "The custom prompt requires 3 input variables: \"query\", \"answer\" and \"result\". Where \"query\" is the question, \"answer\" is the ground truth answer, and \"result\" is the predicted answer." |
| 203 | + ] |
| 204 | + }, |
| 205 | + { |
| 206 | + "cell_type": "code", |
| 207 | + "execution_count": null, |
| 208 | + "id": "153425c4", |
| 209 | + "metadata": {}, |
| 210 | + "outputs": [], |
| 211 | + "source": [ |
| 212 | + "from langchain.prompts.prompt import PromptTemplate\n", |
| 213 | + "\n", |
| 214 | + "_PROMPT_TEMPLATE = \"\"\"You are an expert professor specialized in grading students' answers to questions.\n", |
| 215 | + "You are grading the following question:\n", |
| 216 | + "{query}\n", |
| 217 | + "Here is the real answer:\n", |
| 218 | + "{answer}\n", |
| 219 | + "You are grading the following predicted answer:\n", |
| 220 | + "{result}\n", |
| 221 | + "What grade do you give from 0 to 10, where 0 is the lowest (very low similarity) and 10 is the highest (very high similarity)?\n", |
| 222 | + "\"\"\"\n", |
| 223 | + "\n", |
| 224 | + "PROMPT = PromptTemplate(input_variables=[\"query\", \"answer\", \"result\"], template=_PROMPT_TEMPLATE)" |
| 225 | + ] |
| 226 | + }, |
| 227 | + { |
| 228 | + "cell_type": "code", |
| 229 | + "execution_count": null, |
| 230 | + "id": "0a3b0fb7", |
| 231 | + "metadata": {}, |
| 232 | + "outputs": [], |
| 233 | + "source": [ |
| 234 | + "evalchain = QAEvalChain.from_llm(llm=llm,prompt=PROMPT)\n", |
| 235 | + "evalchain.evaluate(examples, predictions, question_key=\"question\", answer_key=\"answer\", prediction_key=\"text\")" |
| 236 | + ] |
| 237 | + }, |
193 | 238 | {
|
194 | 239 | "cell_type": "markdown",
|
195 | 240 | "id": "aaa61f0c",
|
|
271 | 316 | ],
|
272 | 317 | "metadata": {
|
273 | 318 | "kernelspec": {
|
274 |
| - "display_name": "Python 3 (ipykernel)", |
| 319 | + "display_name": ".venv", |
275 | 320 | "language": "python",
|
276 | 321 | "name": "python3"
|
277 | 322 | },
|
|
285 | 330 | "name": "python",
|
286 | 331 | "nbconvert_exporter": "python",
|
287 | 332 | "pygments_lexer": "ipython3",
|
288 |
| - "version": "3.10.9" |
| 333 | + "version": "3.9.7 (default, Sep 16 2021, 08:50:36) \n[Clang 10.0.0 ]" |
| 334 | + }, |
| 335 | + "vscode": { |
| 336 | + "interpreter": { |
| 337 | + "hash": "53f3bc57609c7a84333bb558594977aa5b4026b1d6070b93987956689e367341" |
| 338 | + } |
289 | 339 | }
|
290 | 340 | },
|
291 | 341 | "nbformat": 4,
|
|
0 commit comments