{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"os.environ[\"http_proxy\"] = \"http://127.0.0.1:15777\"\n",
"os.environ[\"https_proxy\"] = \"http://127.0.0.1:15777\"\n",
"\n",
"from tqdm import tqdm\n",
"from langchain.evaluation import load_evaluator\n",
"from langchain_openai import ChatOpenAI"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"accuracy_criteria = {\n",
" \"accuracy\": \"\"\"\n",
"Score 1: The answer is completely unrelated to the reference.\n",
"Score 3: The answer has minor relevance but does not align with the reference.\n",
"Score 5: The answer has moderate relevance but contains inaccuracies.\n",
"Score 7: The answer aligns with the reference but has minor errors or omissions.\n",
"Score 10: The answer is completely accurate and aligns perfectly with the reference.\n",
"Only respond with a numberical score\"\"\"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"evaluator = load_evaluator(\n",
" \"labeled_score_string\", \n",
" criteria=accuracy_criteria,\n",
" llm=ChatOpenAI(model=\"gpt-4\", openai_api_key=\"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\"),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"import jsonlines \n",
"\n",
"data = []\n",
"with jsonlines.open(\"/share/ninglu_shao/code/PluginTransformer/data/results/needle/result.jsonl\", \"r\") as f:\n",
" for obj in f:\n",
" data.append(obj)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"length: 9000\tdepth: 0\tscore: 3\n",
"length: 9000\tdepth: 33\tscore: 3\n",
"length: 9000\tdepth: 66\tscore: 5\n",
"length: 9000\tdepth: 100\tscore: 3\n",
"length: 10000\tdepth: 0\tscore: 3\n",
"length: 10000\tdepth: 33\tscore: 3\n",
"length: 10000\tdepth: 66\tscore: 3\n",
"length: 10000\tdepth: 100\tscore: 3\n",
"length: 11000\tdepth: 0\tscore: 3\n",
"length: 11000\tdepth: 33\tscore: 5\n",
"length: 11000\tdepth: 66\tscore: 3\n",
"length: 11000\tdepth: 100\tscore: 3\n",
"length: 12000\tdepth: 0\tscore: 5\n",
"length: 12000\tdepth: 33\tscore: 3\n",
"length: 12000\tdepth: 66\tscore: 5\n",
"length: 12000\tdepth: 100\tscore: 3\n"
]
}
],
"source": [
"for d in data:\n",
" eval_result = evaluator.evaluate_strings(\n",
" prediction=d[\"output\"].strip(),\n",
" reference=\"The best thing to do in San Francisco is sitting in Dolores Park and eating a hamburg on a sunny day.\",\n",
" input=\"What is the best thing to do in San Francisco?\",\n",
" )\n",
"\n",
" print(f\"length: {d['length']}\\tdepth: {d['depth']}\\tscore: {eval_result['score']}\")"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"length: 5000\tdepth: 0\tscore: 5\n",
"length: 5000\tdepth: 33\tscore: 3\n",
"length: 5000\tdepth: 66\tscore: 5\n",
"length: 5000\tdepth: 100\tscore: 3\n",
"length: 6000\tdepth: 0\tscore: 1\n",
"length: 6000\tdepth: 33\tscore: 1\n",
"length: 6000\tdepth: 66\tscore: 3\n",
"length: 6000\tdepth: 100\tscore: 5\n",
"length: 7000\tdepth: 0\tscore: 5\n",
"length: 7000\tdepth: 33\tscore: 3\n",
"length: 7000\tdepth: 66\tscore: 1\n",
"length: 7000\tdepth: 100\tscore: 1\n",
"length: 8000\tdepth: 0\tscore: 3\n",
"length: 8000\tdepth: 33\tscore: 5\n",
"length: 8000\tdepth: 66\tscore: 3\n",
"length: 8000\tdepth: 100\tscore: 5\n"
]
}
],
"source": [
"for d in data:\n",
" eval_result = evaluator.evaluate_strings(\n",
" prediction=d[\"output\"].strip(),\n",
" reference=\"The best thing to do in San Francisco is sitting in Dolores Park and eating a hamburg on a sunny day.\",\n",
" input=\"What is the best thing to do in San Francisco?\",\n",
" )\n",
"\n",
" print(f\"length: {d['length']}\\tdepth: {d['depth']}\\tscore: {eval_result['score']}\")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"length: 9000\tdepth: 0\tscore: 3\n",
"length: 9000\tdepth: 33\tscore: 3\n",
"length: 9000\tdepth: 66\tscore: 3\n",
"length: 9000\tdepth: 100\tscore: 3\n",
"length: 10000\tdepth: 0\tscore: 5\n",
"length: 10000\tdepth: 33\tscore: 5\n",
"length: 10000\tdepth: 66\tscore: 3\n",
"length: 10000\tdepth: 100\tscore: 5\n",
"length: 11000\tdepth: 0\tscore: 7\n",
"length: 11000\tdepth: 33\tscore: 7\n",
"length: 11000\tdepth: 66\tscore: 3\n",
"length: 11000\tdepth: 100\tscore: 7\n",
"length: 12000\tdepth: 0\tscore: 3\n",
"length: 12000\tdepth: 33\tscore: 7\n",
"length: 12000\tdepth: 66\tscore: 3\n",
"length: 12000\tdepth: 100\tscore: 3\n"
]
}
],
"source": [
"for d in data:\n",
" eval_result = evaluator.evaluate_strings(\n",
" prediction=d[\"output\"].strip(),\n",
" reference=\"The best thing to do in San Francisco is sitting in Dolores Park and eating a hamburg on a sunny day.\",\n",
" input=\"What is the best thing to do in San Francisco?\",\n",
" )\n",
"\n",
" print(f\"length: {d['length']}\\tdepth: {d['depth']}\\tscore: {eval_result['score']}\")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"length: 5000\tdepth: 0\tscore: 3\n",
"length: 5000\tdepth: 33\tscore: 3\n",
"length: 5000\tdepth: 66\tscore: 5\n",
"length: 5000\tdepth: 100\tscore: 3\n",
"length: 6000\tdepth: 0\tscore: 3\n",
"length: 6000\tdepth: 33\tscore: 7\n",
"length: 6000\tdepth: 66\tscore: 5\n",
"length: 6000\tdepth: 100\tscore: 3\n",
"length: 7000\tdepth: 0\tscore: 3\n",
"length: 7000\tdepth: 33\tscore: 7\n",
"length: 7000\tdepth: 66\tscore: 3\n",
"length: 7000\tdepth: 100\tscore: 3\n",
"length: 8000\tdepth: 0\tscore: 3\n",
"length: 8000\tdepth: 33\tscore: 5\n",
"length: 8000\tdepth: 66\tscore: 5\n",
"length: 8000\tdepth: 100\tscore: 3\n"
]
}
],
"source": [
"for d in data:\n",
" eval_result = evaluator.evaluate_strings(\n",
" prediction=d[\"output\"].strip(),\n",
" reference=\"The best thing to do in San Francisco is sitting in Dolores Park and eating a hamburg on a sunny day.\",\n",
" input=\"What is the best thing to do in San Francisco?\",\n",
" )\n",
"\n",
" print(f\"length: {d['length']}\\tdepth: {d['depth']}\\tscore: {eval_result['score']}\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"length: 9000\tdepth: 0\tscore: 3\n",
"length: 9000\tdepth: 33\tscore: 5\n",
"length: 9000\tdepth: 66\tscore: 5\n",
"length: 9000\tdepth: 100\tscore: 10\n",
"length: 10000\tdepth: 0\tscore: 5\n",
"length: 10000\tdepth: 33\tscore: 10\n",
"length: 10000\tdepth: 66\tscore: 7\n",
"length: 10000\tdepth: 100\tscore: 10\n",
"length: 11000\tdepth: 0\tscore: 7\n",
"length: 11000\tdepth: 33\tscore: 5\n",
"length: 11000\tdepth: 66\tscore: 5\n",
"length: 11000\tdepth: 100\tscore: 10\n",
"length: 12000\tdepth: 0\tscore: 1\n",
"length: 12000\tdepth: 33\tscore: 7\n",
"length: 12000\tdepth: 66\tscore: 7\n",
"length: 12000\tdepth: 100\tscore: 10\n"
]
}
],
"source": [
"for d in data:\n",
" eval_result = evaluator.evaluate_strings(\n",
" prediction=d[\"output\"].strip(),\n",
" reference=\"The best thing to do in San Francisco is sitting in Dolores Park and eating a hamburg on a sunny day.\",\n",
" input=\"What is the best thing to do in San Francisco?\",\n",
" )\n",
"\n",
" print(f\"length: {d['length']}\\tdepth: {d['depth']}\\tscore: {eval_result['score']}\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"length: 5000\tdepth: 0\tscore: 7\n",
"length: 5000\tdepth: 33\tscore: 5\n",
"length: 5000\tdepth: 66\tscore: 7\n",
"length: 5000\tdepth: 100\tscore: 5\n",
"length: 6000\tdepth: 0\tscore: 7\n",
"length: 6000\tdepth: 33\tscore: 10\n",
"length: 6000\tdepth: 66\tscore: 7\n",
"length: 6000\tdepth: 100\tscore: 5\n",
"length: 7000\tdepth: 0\tscore: 7\n",
"length: 7000\tdepth: 33\tscore: 7\n",
"length: 7000\tdepth: 66\tscore: 7\n",
"length: 7000\tdepth: 100\tscore: 7\n",
"length: 8000\tdepth: 0\tscore: 7\n",
"length: 8000\tdepth: 33\tscore: 7\n",
"length: 8000\tdepth: 66\tscore: 7\n",
"length: 8000\tdepth: 100\tscore: 7\n"
]
}
],
"source": [
"for d in data:\n",
" eval_result = evaluator.evaluate_strings(\n",
" prediction=d[\"output\"].strip(),\n",
" reference=\"The best thing to do in San Francisco is sitting in Dolores Park and eating a hamburg on a sunny day.\",\n",
" input=\"What is the best thing to do in San Francisco?\",\n",
" )\n",
"\n",
" print(f\"length: {d['length']}\\tdepth: {d['depth']}\\tscore: {eval_result['score']}\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"length: 5000\tdepth: 0\tscore: 10\n",
"length: 5000\tdepth: 33\tscore: 10\n",
"length: 5000\tdepth: 66\tscore: 10\n",
"length: 5000\tdepth: 100\tscore: 10\n",
"length: 6000\tdepth: 0\tscore: 10\n",
"length: 6000\tdepth: 33\tscore: 10\n",
"length: 6000\tdepth: 66\tscore: 10\n",
"length: 6000\tdepth: 100\tscore: 10\n",
"length: 7000\tdepth: 0\tscore: 7\n",
"length: 7000\tdepth: 33\tscore: 10\n",
"length: 7000\tdepth: 66\tscore: 10\n",
"length: 7000\tdepth: 100\tscore: 10\n",
"length: 8000\tdepth: 0\tscore: 5\n",
"length: 8000\tdepth: 33\tscore: 10\n",
"length: 8000\tdepth: 66\tscore: 10\n",
"length: 8000\tdepth: 100\tscore: 10\n"
]
}
],
"source": [
"for d in data:\n",
" eval_result = evaluator.evaluate_strings(\n",
" prediction=d[\"output\"].strip(),\n",
" reference=\"The best thing to do in San Francisco is sitting in Dolores Park and eating a hamburg on a sunny day.\",\n",
" input=\"What is the best thing to do in San Francisco?\",\n",
" )\n",
"\n",
" print(f\"length: {d['length']}\\tdepth: {d['depth']}\\tscore: {eval_result['score']}\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"length: 9000\tdepth: 0\tscore: 1\n",
"length: 9000\tdepth: 33\tscore: 3\n",
"length: 9000\tdepth: 66\tscore: 10\n",
"length: 9000\tdepth: 100\tscore: 10\n",
"length: 10000\tdepth: 0\tscore: 1\n",
"length: 10000\tdepth: 33\tscore: 1\n",
"length: 10000\tdepth: 66\tscore: 10\n",
"length: 10000\tdepth: 100\tscore: 10\n",
"length: 11000\tdepth: 0\tscore: 3\n",
"length: 11000\tdepth: 33\tscore: 1\n",
"length: 11000\tdepth: 66\tscore: 10\n",
"length: 11000\tdepth: 100\tscore: 10\n",
"length: 12000\tdepth: 0\tscore: 1\n",
"length: 12000\tdepth: 33\tscore: 1\n",
"length: 12000\tdepth: 66\tscore: 3\n",
"length: 12000\tdepth: 100\tscore: 10\n"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31m在当前单元格或上一个单元格中执行代码时 Kernel 崩溃。\n",
"\u001b[1;31m请查看单元格中的代码,以确定故障的可能原因。\n",
"\u001b[1;31m单击此处了解详细信息。\n",
"\u001b[1;31m有关更多详细信息,请查看 Jupyter log。"
]
}
],
"source": [
"for d in data:\n",
" eval_result = evaluator.evaluate_strings(\n",
" prediction=d[\"output\"].strip(),\n",
" reference=\"The best thing to do in San Francisco is sitting in Dolores Park and eating a hamburg on a sunny day.\",\n",
" input=\"What is the best thing to do in San Francisco?\",\n",
" )\n",
"\n",
" print(f\"length: {d['length']}\\tdepth: {d['depth']}\\tscore: {eval_result['score']}\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"length: 9000\tdepth: 0\tscore: 1\n",
"length: 9000\tdepth: 33\tscore: 5\n",
"length: 9000\tdepth: 66\tscore: 1\n",
"length: 9000\tdepth: 100\tscore: 10\n",
"length: 10000\tdepth: 0\tscore: 3\n",
"length: 10000\tdepth: 33\tscore: 3\n",
"length: 10000\tdepth: 66\tscore: 7\n",
"length: 10000\tdepth: 100\tscore: 10\n",
"length: 11000\tdepth: 0\tscore: 5\n",
"length: 11000\tdepth: 33\tscore: 3\n",
"length: 11000\tdepth: 66\tscore: 3\n",
"length: 11000\tdepth: 100\tscore: 10\n",
"length: 12000\tdepth: 0\tscore: 3\n",
"length: 12000\tdepth: 33\tscore: 7\n",
"length: 12000\tdepth: 66\tscore: 5\n",
"length: 12000\tdepth: 100\tscore: 10\n"
]
}
],
"source": [
"for d in data:\n",
" eval_result = evaluator.evaluate_strings(\n",
" prediction=d[\"output\"].strip(),\n",
" reference=\"The best thing to do in San Francisco is sitting in Dolores Park and eating a hamburg on a sunny day.\",\n",
" input=\"What is the best thing to do in San Francisco?\",\n",
" )\n",
"\n",
" print(f\"length: {d['length']}\\tdepth: {d['depth']}\\tscore: {eval_result['score']}\")"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"length: 5000\tdepth: 0\tscore: 1\n",
"length: 5000\tdepth: 33\tscore: 10\n",
"length: 5000\tdepth: 66\tscore: 10\n",
"length: 5000\tdepth: 100\tscore: 10\n",
"length: 6000\tdepth: 0\tscore: 7\n",
"length: 6000\tdepth: 33\tscore: 10\n",
"length: 6000\tdepth: 66\tscore: 10\n",
"length: 6000\tdepth: 100\tscore: 10\n",
"length: 7000\tdepth: 0\tscore: 7\n",
"length: 7000\tdepth: 33\tscore: 10\n",
"length: 7000\tdepth: 66\tscore: 10\n",
"length: 7000\tdepth: 100\tscore: 10\n",
"length: 8000\tdepth: 0\tscore: 3\n",
"length: 8000\tdepth: 33\tscore: 10\n",
"length: 8000\tdepth: 66\tscore: 10\n",
"length: 8000\tdepth: 100\tscore: 10\n"
]
}
],
"source": [
"for d in data:\n",
" eval_result = evaluator.evaluate_strings(\n",
" prediction=d[\"output\"].strip(),\n",
" reference=\"The best thing to do in San Francisco is sitting in Dolores Park and eating a hamburg on a sunny day.\",\n",
" input=\"What is the best thing to do in San Francisco?\",\n",
" )\n",
"\n",
" print(f\"length: {d['length']}\\tdepth: {d['depth']}\\tscore: {eval_result['score']}\")"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"length: 5000\tdepth: 0\tscore: 10\n",
"length: 5000\tdepth: 33\tscore: 10\n",
"length: 5000\tdepth: 66\tscore: 10\n",
"length: 5000\tdepth: 100\tscore: 10\n",
"length: 6000\tdepth: 0\tscore: 10\n",
"length: 6000\tdepth: 33\tscore: 10\n",
"length: 6000\tdepth: 66\tscore: 10\n",
"length: 6000\tdepth: 100\tscore: 10\n",
"length: 7000\tdepth: 0\tscore: 10\n",
"length: 7000\tdepth: 33\tscore: 10\n",
"length: 7000\tdepth: 66\tscore: 10\n",
"length: 7000\tdepth: 100\tscore: 10\n",
"length: 8000\tdepth: 0\tscore: 10\n",
"length: 8000\tdepth: 33\tscore: 10\n",
"length: 8000\tdepth: 66\tscore: 10\n",
"length: 8000\tdepth: 100\tscore: 10\n"
]
}
],
"source": [
"for d in data:\n",
" eval_result = evaluator.evaluate_strings(\n",
" prediction=d[\"output\"].strip(),\n",
" reference=\"The best thing to do in San Francisco is sitting in Dolores Park and eating a hamburg on a sunny day.\",\n",
" input=\"What is the best thing to do in San Francisco?\",\n",
" )\n",
"\n",
" print(f\"length: {d['length']}\\tdepth: {d['depth']}\\tscore: {eval_result['score']}\")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'reasoning': \"The assistant's response is perfectly accurate and directly aligns with the information provided in the ground truth. The assistant correctly identifies sitting in Dolores Park and eating a hamburger as the best thing to do in San Francisco according to the text. The response is precise, relevant, and doesn't contain any inaccuracies or omissions. Therefore, the evaluation score is: [[10]].\", 'score': 10}\n"
]
}
],
"source": [
"eval_result = evaluator.evaluate_strings(\n",
" prediction=data[0][\"output\"].strip(),\n",
" reference=\"The best thing to do in San Francisco is sitting in Dolores Park and eating a hamburg on a sunny day.\",\n",
" input=\"What is the best thing to do in San Francisco?\",\n",
")\n",
"print(eval_result)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"length: 1000\tdepth: 0\tscore: 10\n",
"length: 1000\tdepth: 33\tscore: 10\n",
"length: 1000\tdepth: 66\tscore: 10\n",
"length: 1000\tdepth: 100\tscore: 10\n",
"length: 2000\tdepth: 0\tscore: 10\n",
"length: 2000\tdepth: 33\tscore: 10\n",
"length: 2000\tdepth: 66\tscore: 10\n",
"length: 2000\tdepth: 100\tscore: 10\n",
"length: 3000\tdepth: 0\tscore: 10\n",
"length: 3000\tdepth: 33\tscore: 10\n",
"length: 3000\tdepth: 66\tscore: 10\n",
"length: 3000\tdepth: 100\tscore: 10\n",
"length: 4000\tdepth: 0\tscore: 10\n",
"length: 4000\tdepth: 33\tscore: 10\n",
"length: 4000\tdepth: 66\tscore: 10\n",
"length: 4000\tdepth: 100\tscore: 10\n",
"length: 5000\tdepth: 0\tscore: 1\n",
"length: 5000\tdepth: 33\tscore: 1\n",
"length: 5000\tdepth: 66\tscore: 1\n",
"length: 5000\tdepth: 100\tscore: 1\n",
"length: 6000\tdepth: 0\tscore: 1\n",
"length: 6000\tdepth: 33\tscore: 1\n",
"length: 6000\tdepth: 66\tscore: 1\n",
"length: 6000\tdepth: 100\tscore: 1\n",
"length: 7000\tdepth: 0\tscore: 1\n",
"length: 7000\tdepth: 33\tscore: 1\n",
"length: 7000\tdepth: 66\tscore: 1\n",
"length: 7000\tdepth: 100\tscore: 1\n",
"length: 8000\tdepth: 0\tscore: 1\n",
"length: 8000\tdepth: 33\tscore: 1\n",
"length: 8000\tdepth: 66\tscore: 1\n",
"length: 8000\tdepth: 100\tscore: 1\n"
]
}
],
"source": [
"for d in data:\n",
" eval_result = evaluator.evaluate_strings(\n",
" prediction=d[\"output\"].strip(),\n",
" reference=\"The best thing to do in San Francisco is sitting in Dolores Park and eating a hamburg on a sunny day.\",\n",
" input=\"What is the best thing to do in San Francisco?\",\n",
" )\n",
"\n",
" print(f\"length: {d['length']}\\tdepth: {d['depth']}\\tscore: {eval_result['score']}\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"130"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = [3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 31, 33, 37, 38, 40, 42, 43, 45, 48, 49, 50, 51, 54, 55, 56, 59, 63, 64, 65, 66, 68, 71, 73, 76, 79, 80, 81, 82, 83, 85, 88, 89, 90, 92, 93, 94, 96, 97, 98, 101, 102, 103, 105, 107, 108, 109, 110, 111, 116, 117, 118, 120, 123, 124, 127, 128, 129, 130, 131, 133, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 152, 154, 155, 160, 162, 163, 164, 165, 168, 170, 171, 172, 173, 175, 177, 178, 179, 181, 182, 183, 185, 186, 187, 188, 189, 190, 195, 196, 197, 198, 199, 200]\n",
"\n",
"len(a)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"106"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"b = [2, 3, 4, 5, 7, 10, 11, 12, 13, 14, 15, 18, 19, 20, 22, 24, 26, 28, 31, 33, 36, 37, 38, 39, 40, 42, 43, 45, 47, 49, 50, 51, 54, 55, 56, 57, 59, 62, 64, 68, 69, 71, 73, 74, 80, 82, 87, 90, 91, 96, 97, 98, 99, 101, 102, 103, 105, 107, 109, 111, 112, 116, 117, 120, 121, 123, 124, 125, 128, 129, 130, 131, 135, 136, 137, 138, 140, 141, 142, 144, 146, 148, 149, 150, 152, 154, 155, 158, 160, 165, 170, 171, 172, 178, 179, 181, 182, 183, 185, 187, 188, 189, 190, 195, 196, 199]\n",
"\n",
"len(b)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"40\n"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31m在当前单元格或上一个单元格中执行代码时 Kernel 崩溃。\n",
"\u001b[1;31m请查看单元格中的代码,以确定故障的可能原因。\n",
"\u001b[1;31m单击此处了解详细信息。\n",
"\u001b[1;31m有关更多详细信息,请查看 Jupyter log。"
]
}
],
"source": [
"count = 0\n",
"for idx in a:\n",
" if idx not in b:\n",
" count += 1\n",
"\n",
"print(count)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}