From f752f81401eb46ba01d2d99e2bacf0ead981825a Mon Sep 17 00:00:00 2001
From: Anastasia Kabanovsky <124449724+keirialaa@users.noreply.github.com>
Date: Thu, 21 May 2026 21:03:08 +0200
Subject: [PATCH 1/3] Lab Submission
---
lab-extractive-question-answering.ipynb | 739 ++++++++++++++++++++++--
1 file changed, 679 insertions(+), 60 deletions(-)
diff --git a/lab-extractive-question-answering.ipynb b/lab-extractive-question-answering.ipynb
index 0cf5b39..9a87b4b 100644
--- a/lab-extractive-question-answering.ipynb
+++ b/lab-extractive-question-answering.ipynb
@@ -54,7 +54,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"id": "740a3cf7-830c-4f1d-bf8d-90d18f908a99",
"metadata": {},
"outputs": [],
@@ -112,7 +112,7 @@
},
"outputs": [],
"source": [
- "!pip install -qU datasets pinecone-client sentence-transformers torch"
+ "# !pip install -qU datasets pinecone-client sentence-transformers torch"
]
},
{
@@ -137,7 +137,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"id": "J250IJeh7NIb",
"metadata": {
"colab": {
@@ -237,17 +237,134 @@
"id": "J250IJeh7NIb",
"outputId": "6f249347-51f8-48be-ab90-a202eee648a7"
},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "Using the latest cached version of the dataset since squad couldn't be found on the Hugging Face Hub\n",
+ "Found the latest cached dataset configuration 'plain_text' at /Users/anastasiakabanovsky/.cache/huggingface/datasets/squad/plain_text/0.0.0/7b6d24c440a36b6815f21b70d25016731768db1f (last modified on Sun May 17 16:57:10 2026).\n"
+ ]
+ },
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " id | \n",
+ " title | \n",
+ " context | \n",
+ " question | \n",
+ " answers | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 5733be284776f41900661182 | \n",
+ " University_of_Notre_Dame | \n",
+ " Architecturally, the school has a Catholic cha... | \n",
+ " To whom did the Virgin Mary allegedly appear i... | \n",
+ " {'text': ['Saint Bernadette Soubirous'], 'answ... | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 5733be284776f4190066117f | \n",
+ " University_of_Notre_Dame | \n",
+ " Architecturally, the school has a Catholic cha... | \n",
+ " What is in front of the Notre Dame Main Building? | \n",
+ " {'text': ['a copper statue of Christ'], 'answe... | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 5733be284776f41900661180 | \n",
+ " University_of_Notre_Dame | \n",
+ " Architecturally, the school has a Catholic cha... | \n",
+ " The Basilica of the Sacred heart at Notre Dame... | \n",
+ " {'text': ['the Main Building'], 'answer_start'... | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 5733be284776f41900661181 | \n",
+ " University_of_Notre_Dame | \n",
+ " Architecturally, the school has a Catholic cha... | \n",
+ " What is the Grotto at Notre Dame? | \n",
+ " {'text': ['a Marian place of prayer and reflec... | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 5733be284776f4190066117e | \n",
+ " University_of_Notre_Dame | \n",
+ " Architecturally, the school has a Catholic cha... | \n",
+ " What sits on top of the Main Building at Notre... | \n",
+ " {'text': ['a golden statue of the Virgin Mary'... | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " id title \\\n",
+ "0 5733be284776f41900661182 University_of_Notre_Dame \n",
+ "1 5733be284776f4190066117f University_of_Notre_Dame \n",
+ "2 5733be284776f41900661180 University_of_Notre_Dame \n",
+ "3 5733be284776f41900661181 University_of_Notre_Dame \n",
+ "4 5733be284776f4190066117e University_of_Notre_Dame \n",
+ "\n",
+ " context \\\n",
+ "0 Architecturally, the school has a Catholic cha... \n",
+ "1 Architecturally, the school has a Catholic cha... \n",
+ "2 Architecturally, the school has a Catholic cha... \n",
+ "3 Architecturally, the school has a Catholic cha... \n",
+ "4 Architecturally, the school has a Catholic cha... \n",
+ "\n",
+ " question \\\n",
+ "0 To whom did the Virgin Mary allegedly appear i... \n",
+ "1 What is in front of the Notre Dame Main Building? \n",
+ "2 The Basilica of the Sacred heart at Notre Dame... \n",
+ "3 What is the Grotto at Notre Dame? \n",
+ "4 What sits on top of the Main Building at Notre... \n",
+ "\n",
+ " answers \n",
+ "0 {'text': ['Saint Bernadette Soubirous'], 'answ... \n",
+ "1 {'text': ['a copper statue of Christ'], 'answe... \n",
+ "2 {'text': ['the Main Building'], 'answer_start'... \n",
+ "3 {'text': ['a Marian place of prayer and reflec... \n",
+ "4 {'text': ['a golden statue of the Virgin Mary'... "
+ ]
+ },
+ "execution_count": 2,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"from datasets import load_dataset\n",
"\n",
"# load the squad dataset into a pandas dataframe\n",
- "df = load_dataset(\"squad\", split=\"train\").to_pandas()"
+ "df = load_dataset(\"squad\", split=\"train\").to_pandas()\n",
+ "df.head()"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"id": "FcmeNO97dHDO",
"metadata": {
"colab": {
@@ -257,12 +374,133 @@
"id": "FcmeNO97dHDO",
"outputId": "11af1908-8950-4433-f66d-7d363d010c97"
},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " title | \n",
+ " context | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " University_of_Notre_Dame | \n",
+ " Architecturally, the school has a Catholic cha... | \n",
+ "
\n",
+ " \n",
+ " | 5 | \n",
+ " University_of_Notre_Dame | \n",
+ " As at most other universities, Notre Dame's st... | \n",
+ "
\n",
+ " \n",
+ " | 10 | \n",
+ " University_of_Notre_Dame | \n",
+ " The university is the major seat of the Congre... | \n",
+ "
\n",
+ " \n",
+ " | 15 | \n",
+ " University_of_Notre_Dame | \n",
+ " The College of Engineering was established in ... | \n",
+ "
\n",
+ " \n",
+ " | 20 | \n",
+ " University_of_Notre_Dame | \n",
+ " All of Notre Dame's undergraduate students are... | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 87574 | \n",
+ " Kathmandu | \n",
+ " Institute of Medicine, the central college of ... | \n",
+ "
\n",
+ " \n",
+ " | 87579 | \n",
+ " Kathmandu | \n",
+ " Football and Cricket are the most popular spor... | \n",
+ "
\n",
+ " \n",
+ " | 87584 | \n",
+ " Kathmandu | \n",
+ " The total length of roads in Nepal is recorded... | \n",
+ "
\n",
+ " \n",
+ " | 87589 | \n",
+ " Kathmandu | \n",
+ " The main international airport serving Kathman... | \n",
+ "
\n",
+ " \n",
+ " | 87594 | \n",
+ " Kathmandu | \n",
+ " Kathmandu Metropolitan City (KMC), in order to... | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
18891 rows × 2 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " title \\\n",
+ "0 University_of_Notre_Dame \n",
+ "5 University_of_Notre_Dame \n",
+ "10 University_of_Notre_Dame \n",
+ "15 University_of_Notre_Dame \n",
+ "20 University_of_Notre_Dame \n",
+ "... ... \n",
+ "87574 Kathmandu \n",
+ "87579 Kathmandu \n",
+ "87584 Kathmandu \n",
+ "87589 Kathmandu \n",
+ "87594 Kathmandu \n",
+ "\n",
+ " context \n",
+ "0 Architecturally, the school has a Catholic cha... \n",
+ "5 As at most other universities, Notre Dame's st... \n",
+ "10 The university is the major seat of the Congre... \n",
+ "15 The College of Engineering was established in ... \n",
+ "20 All of Notre Dame's undergraduate students are... \n",
+ "... ... \n",
+ "87574 Institute of Medicine, the central college of ... \n",
+ "87579 Football and Cricket are the most popular spor... \n",
+ "87584 The total length of roads in Nepal is recorded... \n",
+ "87589 The main international airport serving Kathman... \n",
+ "87594 Kathmandu Metropolitan City (KMC), in order to... \n",
+ "\n",
+ "[18891 rows x 2 columns]"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# select only title and context column\n",
- "df = None\n",
+ "df = df[[\"title\", \"context\"]]\n",
"# drop rows containing duplicate context passages\n",
- "df = None\n",
+ "df = df.drop_duplicates(subset=[\"context\"])\n",
"df"
]
},
@@ -293,12 +531,12 @@
"metadata": {},
"outputs": [],
"source": [
- "!pip install -qU langchain-pinecone pinecone-notebooks"
+ "# !pip install -qU langchain-pinecone pinecone-notebooks"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"id": "092d1e71",
"metadata": {
"id": "092d1e71"
@@ -310,11 +548,9 @@
"spec = ServerlessSpec(\n",
" cloud=\"aws\", region=\"us-east-1\"\n",
")\n",
- "\n",
"# connect to pinecone environment\n",
"pc = Pinecone(\n",
- " api_key = PINECONE_API_KEY,\n",
- " environment='us-east-1' # find next to API key in console\n",
+ " api_key = PINECONE_API_KEY\n",
")"
]
},
@@ -330,21 +566,25 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 8,
"id": "b3206184",
"metadata": {
"id": "b3206184"
},
"outputs": [],
"source": [
- "index_name = None\n",
+ "index_name = \"question-answering\"\n",
"\n",
"# check if the extractive-question-answering index exists\n",
- "if index_name not in pinecone.list_indexes().names():\n",
- " # create the index if it does not exist\n",
- " None\n",
+ "if not pc.has_index(index_name):\n",
+ " pc.create_index(\n",
+ " name=index_name,\n",
+ " dimension=384,\n",
+ " metric=\"cosine\",\n",
+ " spec=spec\n",
+ " )\n",
"# connect to extractive-question-answering index we created\n",
- "index = pinecone.Index(index_name)"
+ "index = pc.Index(index_name)"
]
},
{
@@ -376,7 +616,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 9,
"id": "31a85bb3",
"metadata": {
"colab": {
@@ -542,7 +782,29 @@
"id": "31a85bb3",
"outputId": "6ee65615-6cd5-4e06-f5b6-97263e4d7474"
},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "Loading weights: 100%|██████████| 103/103 [00:00<00:00, 8976.90it/s]\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "SentenceTransformer(\n",
+ " (0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'BertModel'})\n",
+ " (1): Pooling({'embedding_dimension': 384, 'pooling_mode': 'mean', 'include_prompt': True})\n",
+ " (2): Normalize({})\n",
+ ")"
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"import torch\n",
"from sentence_transformers import SentenceTransformer\n",
@@ -550,7 +812,7 @@
"# set device to GPU if available\n",
"device = 'cuda' if torch.cuda.is_available() else 'cpu'\n",
"# load the retriever model from huggingface model hub\n",
- "retriever = None #use the 'multi-qa-MiniLM-L6-cos-v1' model from HuggingFace to build the retriever\n",
+ "retriever = SentenceTransformer('sentence-transformers/multi-qa-MiniLM-L6-cos-v1')\n",
"retriever"
]
},
@@ -576,7 +838,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"id": "a17824ef",
"metadata": {
"colab": {
@@ -600,7 +862,25 @@
"outputId": "c2b46e15-4648-4377-a5aa-19cb01d92a25",
"tags": []
},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "100%|██████████| 296/296 [05:19<00:00, 1.08s/it]\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "DescribeIndexStatsResponse(dimension=384, total_vector_count=18891, metric='cosine', namespaces=1)"
+ ]
+ },
+ "execution_count": 10,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"from tqdm.auto import tqdm\n",
"\n",
@@ -609,17 +889,17 @@
"\n",
"for i in tqdm(range(0, len(df), batch_size)):\n",
" # find end of batch\n",
- " None\n",
+ " i_end = min(i + batch_size, len(df))\n",
" # extract batch\n",
- " None\n",
+ " batch = df.iloc[i:i_end]\n",
" # generate embeddings for batch\n",
- " emb = None\n",
+ " emb = retriever.encode(batch[\"context\"].tolist()).tolist()\n",
" # get metadata\n",
- " meta = None\n",
+ " meta = batch.to_dict(orient=\"records\")\n",
" # create unique IDs\n",
- " ids = None\n",
+ " ids = [str(idx) for idx in batch.index]\n",
" # add all to upsert list\n",
- " to_upsert = None\n",
+ " to_upsert = list(zip(ids, emb, meta))\n",
" # upsert/insert these records to pinecone\n",
" _ = index.upsert(vectors=to_upsert)\n",
"\n",
@@ -649,7 +929,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 20,
"id": "hg9XTDkIJzH_",
"metadata": {
"colab": {
@@ -716,14 +996,34 @@
"id": "hg9XTDkIJzH_",
"outputId": "0309c40e-b037-44f0-b2d1-8da457201b93"
},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "Loading weights: 100%|██████████| 199/199 [00:00<00:00, 14068.91it/s]\n"
+ ]
+ }
+ ],
"source": [
- "from transformers import pipeline\n",
+ "from transformers import AutoTokenizer, AutoModelForQuestionAnswering\n",
"\n",
"model_name = 'deepset/electra-base-squad2'\n",
- "# load the reader model into a question-answering pipeline\n",
- "reader = pipeline(tokenizer=model_name, model=model_name, task='question-answering', device=device)\n",
- "reader"
+ "\n",
+ "tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
+ "model = AutoModelForQuestionAnswering.from_pretrained(model_name).to(device)\n",
+ "def reader(question, context):\n",
+ " inputs = tokenizer(question, context, return_tensors='pt', truncation=True, max_length=512).to(device)\n",
+ " with torch.no_grad():\n",
+ " outputs = model(**inputs)\n",
+ " \n",
+ " start = outputs.start_logits.argmax()\n",
+ " end = outputs.end_logits.argmax() + 1\n",
+ " \n",
+ " answer = tokenizer.convert_tokens_to_string(\n",
+ " tokenizer.convert_ids_to_tokens(inputs['input_ids'][0][start:end])\n",
+ " )\n",
+ " return {\"answer\": answer, \"score\": outputs.start_logits.max().item()}"
]
},
{
@@ -738,7 +1038,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 16,
"id": "lyYaY3QEQiHZ",
"metadata": {
"id": "lyYaY3QEQiHZ"
@@ -748,17 +1048,17 @@
"# gets context passages from the pinecone index\n",
"def get_context(question, top_k):\n",
" # generate embeddings for the question\n",
- " xq = None\n",
+ " xq = retriever.encode(question)\n",
" # search pinecone index for context passage with the answer\n",
- " xc = None\n",
+ " xc = index.query(vector=xq.tolist(), top_k=5, include_metadata=True)\n",
" # extract the context passage from pinecone search result\n",
- " c = None\n",
+ " c = [x['metadata']['context'] for x in xc['matches']]\n",
" return c"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 17,
"id": "Dc9VYOiUQA7B",
"metadata": {
"id": "Dc9VYOiUQA7B"
@@ -783,7 +1083,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 21,
"id": "5E3a3dkJ5ZQD",
"metadata": {
"colab": {
@@ -792,7 +1092,22 @@
"id": "5E3a3dkJ5ZQD",
"outputId": "9c49972e-d87b-47f8-b17a-92c616d14f3f"
},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "['Egypt was producing 691,000 bbl/d of oil and 2,141.05 Tcf of natural gas (in 2013), which makes Egypt as the largest oil producer not member of the Organization of the Petroleum Exporting Countries (OPEC) and the second-largest dry natural gas producer in Africa. In 2013, Egypt was the largest consumer of oil and natural gas in Africa, as more than 20% of total oil consumption and more than 40% of total dry natural gas consumption in Africa. Also, Egypt possesses the largest oil refinery capacity in Africa 726,000 bbl/d (in 2012). Egypt is currently planning to build its first nuclear power plant in El Dabaa city, northern Egypt.',\n",
+ " 'Egypt has a developed energy market based on coal, oil, natural gas, and hydro power. Substantial coal deposits in the northeast Sinai are mined at the rate of about 600,000 tonnes (590,000 long tons; 660,000 short tons) per year. Oil and gas are produced in the western desert regions, the Gulf of Suez, and the Nile Delta. Egypt has huge reserves of gas, estimated at 2,180 cubic kilometres (520 cu mi), and LNG up to 2012 exported to many countries. In 2013, the Egyptian General Petroleum Co (EGPC) said the country will cut exports of natural gas and tell major industries to slow output this summer to avoid an energy crisis and stave off political unrest, Reuters has reported. Egypt is counting on top liquid natural gas (LNG) exporter Qatar to obtain additional gas volumes in summer, while encouraging factories to plan their annual maintenance for those months of peak demand, said EGPC chairman, Tarek El Barkatawy. Egypt produces its own energy, but has been a net oil importer since 2008 and is rapidly becoming a net importer of natural gas.',\n",
+ " \"Iran has the second largest proved gas reserves in the world after Russia, with 33.6 trillion cubic metres, and third largest natural gas production in the world after Indonesia, and Russia. It also ranks fourth in oil reserves with an estimated 153,600,000,000 barrels. It is OPEC's 2nd largest oil exporter and is an energy superpower. In 2005, Iran spent US$4 billion on fuel imports, because of contraband and inefficient domestic use. Oil industry output averaged 4 million barrels per day (640,000 m3/d) in 2005, compared with the peak of six million barrels per day reached in 1974. In the early years of the 2000s (decade), industry infrastructure was increasingly inefficient because of technological lags. Few exploratory wells were drilled in 2005.\",\n",
+ " \"Egypt's economy depends mainly on agriculture, media, petroleum imports, natural gas, and tourism; there are also more than three million Egyptians working abroad, mainly in Saudi Arabia, the Persian Gulf and Europe. The completion of the Aswan High Dam in 1970 and the resultant Lake Nasser have altered the time-honored place of the Nile River in the agriculture and ecology of Egypt. A rapidly growing population, limited arable land, and dependence on the Nile all continue to overtax resources and stress the economy.\",\n",
+ " 'Rajasthan is[when?] earning Rs. 150 million (approx. US$2.5 million) per day as revenue from the crude oil sector. This earning is expected to reach ₹250 million per day in 2013 (which is an increase of ₹100 million or more than 66 percent). The government of India has given permission to extract 300,000 barrels of crude per day from Barmer region which is now 175,000 barrels per day. Once this limit is achieved Rajasthan will become a leader in Crude extraction in Country. Bombay High leads with a production of 250,000 barrels crude per day. Once the limit if 300,000 barrels per day is reached, the overall production of the country will increase by 15 percent. Cairn India is doing the work of exploration and extraction of crude oil in Rajasthan.']"
+ ]
+ },
+ "execution_count": 21,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"question = \"How much oil is Egypt producing in a day?\"\n",
"context = get_context(question, top_k = 1)\n",
@@ -811,7 +1126,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 22,
"id": "DQ4GWdbMSjPl",
"metadata": {
"colab": {
@@ -820,7 +1135,99 @@
"id": "DQ4GWdbMSjPl",
"outputId": "73eabb60-e42a-4983-ed7f-a90e51eb9781"
},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[{'answer': '691, 000 bbl / d',\n",
+ " 'context': 'Egypt was producing 691,000 bbl/d of oil and 2,141.05 Tcf of '\n",
+ " 'natural gas (in 2013), which makes Egypt as the largest oil '\n",
+ " 'producer not member of the Organization of the Petroleum '\n",
+ " 'Exporting Countries (OPEC) and the second-largest dry natural '\n",
+ " 'gas producer in Africa. In 2013, Egypt was the largest consumer '\n",
+ " 'of oil and natural gas in Africa, as more than 20% of total oil '\n",
+ " 'consumption and more than 40% of total dry natural gas '\n",
+ " 'consumption in Africa. Also, Egypt possesses the largest oil '\n",
+ " 'refinery capacity in Africa 726,000 bbl/d (in 2012). Egypt is '\n",
+ " 'currently planning to build its first nuclear power plant in El '\n",
+ " 'Dabaa city, northern Egypt.',\n",
+ " 'score': 10.66650390625},\n",
+ " {'answer': '[SEP] rajasthan is [ when? ] earning rs. 150 million ( approx. us '\n",
+ " '$ 2. 5 million ) per day as revenue from the crude oil sector. '\n",
+ " 'this earning is expected to reach ₹250 million per day in 2013 ( '\n",
+ " 'which is an increase of ₹100 million or more than 66 percent ). '\n",
+ " 'the government of india has given permission to extract 300, 000 '\n",
+ " 'barrels of crude per day from barmer region which is now 175, 000 '\n",
+ " 'barrels per day. once this limit is achieved rajasthan will '\n",
+ " 'become a leader in crude extraction in country. bombay high leads '\n",
+ " 'with a production of 250, 000 barrels crude per day. once the '\n",
+ " 'limit if 300, 000 barrels per day is reached, the overall '\n",
+ " 'production of the country will increase by 15 percent. cairn '\n",
+ " 'india is doing the work of exploration and extraction of crude '\n",
+ " 'oil in rajasthan. [SEP]',\n",
+ " 'context': 'Rajasthan is[when?] earning Rs. 150 million (approx. US$2.5 '\n",
+ " 'million) per day as revenue from the crude oil sector. This '\n",
+ " 'earning is expected to reach ₹250 million per day in 2013 (which '\n",
+ " 'is an increase of ₹100 million or more than 66 percent). The '\n",
+ " 'government of India has given permission to extract 300,000 '\n",
+ " 'barrels of crude per day from Barmer region which is now 175,000 '\n",
+ " 'barrels per day. Once this limit is achieved Rajasthan will '\n",
+ " 'become a leader in Crude extraction in Country. Bombay High '\n",
+ " 'leads with a production of 250,000 barrels crude per day. Once '\n",
+ " 'the limit if 300,000 barrels per day is reached, the overall '\n",
+ " 'production of the country will increase by 15 percent. Cairn '\n",
+ " 'India is doing the work of exploration and extraction of crude '\n",
+ " 'oil in Rajasthan.',\n",
+ " 'score': 7.590670585632324},\n",
+ " {'answer': '[CLS]',\n",
+ " 'context': 'Iran has the second largest proved gas reserves in the world '\n",
+ " 'after Russia, with 33.6 trillion cubic metres, and third largest '\n",
+ " 'natural gas production in the world after Indonesia, and Russia. '\n",
+ " 'It also ranks fourth in oil reserves with an estimated '\n",
+ " \"153,600,000,000 barrels. It is OPEC's 2nd largest oil exporter \"\n",
+ " 'and is an energy superpower. In 2005, Iran spent US$4 billion on '\n",
+ " 'fuel imports, because of contraband and inefficient domestic '\n",
+ " 'use. Oil industry output averaged 4 million barrels per day '\n",
+ " '(640,000 m3/d) in 2005, compared with the peak of six million '\n",
+ " 'barrels per day reached in 1974. In the early years of the 2000s '\n",
+ " '(decade), industry infrastructure was increasingly inefficient '\n",
+ " 'because of technological lags. Few exploratory wells were '\n",
+ " 'drilled in 2005.',\n",
+ " 'score': 6.90549898147583},\n",
+ " {'answer': '[CLS]',\n",
+ " 'context': 'Egypt has a developed energy market based on coal, oil, natural '\n",
+ " 'gas, and hydro power. Substantial coal deposits in the northeast '\n",
+ " 'Sinai are mined at the rate of about 600,000 tonnes (590,000 '\n",
+ " 'long tons; 660,000 short tons) per year. Oil and gas are '\n",
+ " 'produced in the western desert regions, the Gulf of Suez, and '\n",
+ " 'the Nile Delta. Egypt has huge reserves of gas, estimated at '\n",
+ " '2,180 cubic kilometres (520 cu mi), and LNG up to 2012 exported '\n",
+ " 'to many countries. In 2013, the Egyptian General Petroleum Co '\n",
+ " '(EGPC) said the country will cut exports of natural gas and tell '\n",
+ " 'major industries to slow output this summer to avoid an energy '\n",
+ " 'crisis and stave off political unrest, Reuters has reported. '\n",
+ " 'Egypt is counting on top liquid natural gas (LNG) exporter Qatar '\n",
+ " 'to obtain additional gas volumes in summer, while encouraging '\n",
+ " 'factories to plan their annual maintenance for those months of '\n",
+ " 'peak demand, said EGPC chairman, Tarek El Barkatawy. Egypt '\n",
+ " 'produces its own energy, but has been a net oil importer since '\n",
+ " '2008 and is rapidly becoming a net importer of natural gas.',\n",
+ " 'score': 4.752947807312012},\n",
+ " {'answer': '[CLS]',\n",
+ " 'context': \"Egypt's economy depends mainly on agriculture, media, petroleum \"\n",
+ " 'imports, natural gas, and tourism; there are also more than '\n",
+ " 'three million Egyptians working abroad, mainly in Saudi Arabia, '\n",
+ " 'the Persian Gulf and Europe. The completion of the Aswan High '\n",
+ " 'Dam in 1970 and the resultant Lake Nasser have altered the '\n",
+ " 'time-honored place of the Nile River in the agriculture and '\n",
+ " 'ecology of Egypt. A rapidly growing population, limited arable '\n",
+ " 'land, and dependence on the Nile all continue to overtax '\n",
+ " 'resources and stress the economy.',\n",
+ " 'score': 1.0393000841140747}]\n"
+ ]
+ }
+ ],
"source": [
"extract_answer(question, context)"
]
@@ -837,7 +1244,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 23,
"id": "_4NRgV4mGWoj",
"metadata": {
"colab": {
@@ -846,7 +1253,84 @@
"id": "_4NRgV4mGWoj",
"outputId": "4140fe3e-32b9-42ad-8631-303d07df6dda"
},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[{'answer': 'hurley and chen',\n",
+ " 'context': 'According to a story that has often been repeated in the media, '\n",
+ " 'Hurley and Chen developed the idea for YouTube during the early '\n",
+ " 'months of 2005, after they had experienced difficulty sharing '\n",
+ " \"videos that had been shot at a dinner party at Chen's apartment \"\n",
+ " 'in San Francisco. Karim did not attend the party and denied that '\n",
+ " 'it had occurred, but Chen commented that the idea that YouTube '\n",
+ " 'was founded after a dinner party \"was probably very strengthened '\n",
+ " 'by marketing ideas around creating a story that was very '\n",
+ " 'digestible\".',\n",
+ " 'score': 8.594069480895996},\n",
+ " {'answer': '',\n",
+ " 'context': 'The first web browser was invented in 1990 by Sir Tim '\n",
+ " 'Berners-Lee. Berners-Lee is the director of the World Wide Web '\n",
+ " \"Consortium (W3C), which oversees the Web's continued \"\n",
+ " 'development, and is also the founder of the World Wide Web '\n",
+ " 'Foundation. His browser was called WorldWideWeb and later '\n",
+ " 'renamed Nexus.',\n",
+ " 'score': 7.221705436706543},\n",
+ " {'answer': '[SEP] in june 2007, youtube began trials of a system for '\n",
+ " 'automatic detection of uploaded videos that infringe copyright. '\n",
+ " 'google ceo eric schmidt regarded this system as necessary for '\n",
+ " 'resolving lawsuits such as the one from viacom, which alleged '\n",
+ " 'that youtube profited from content that it did not have the right '\n",
+ " 'to distribute. the system, which became known as content id, '\n",
+ " 'creates an id file for copyrighted audio and video material, and '\n",
+ " 'stores it in a database. when a video is uploaded, it is checked '\n",
+ " 'against the database, and flags the video as a copyright '\n",
+ " 'violation if a match is found. [SEP]',\n",
+ " 'context': 'In June 2007, YouTube began trials of a system for automatic '\n",
+ " 'detection of uploaded videos that infringe copyright. Google CEO '\n",
+ " 'Eric Schmidt regarded this system as necessary for resolving '\n",
+ " 'lawsuits such as the one from Viacom, which alleged that YouTube '\n",
+ " 'profited from content that it did not have the right to '\n",
+ " 'distribute. The system, which became known as Content ID, '\n",
+ " 'creates an ID File for copyrighted audio and video material, and '\n",
+ " 'stores it in a database. When a video is uploaded, it is checked '\n",
+ " 'against the database, and flags the video as a copyright '\n",
+ " 'violation if a match is found.',\n",
+ " 'score': 6.786528587341309},\n",
+ " {'answer': 'ronaldinho',\n",
+ " 'context': 'YouTube offered the public a beta test of the site in May 2005. '\n",
+ " 'The first video to reach one million views was a Nike '\n",
+ " 'advertisement featuring Ronaldinho in September 2005. Following '\n",
+ " 'a $3.5 million investment from Sequoia Capital in November, the '\n",
+ " 'site launched officially on December 15, 2005, by which time the '\n",
+ " 'site was receiving 8 million views a day. The site grew rapidly, '\n",
+ " 'and in July 2006 the company announced that more than 65,000 new '\n",
+ " 'videos were being uploaded every day, and that the site was '\n",
+ " 'receiving 100 million video views per day. According to data '\n",
+ " 'published by market research company comScore, YouTube is the '\n",
+ " 'dominant provider of online video in the United States, with a '\n",
+ " 'market share of around 43% and more than 14 billion views of '\n",
+ " 'videos in May 2010.',\n",
+ " 'score': 6.743083477020264},\n",
+ " {'answer': '[CLS]',\n",
+ " 'context': 'Observing that face-to-face communication of the type that '\n",
+ " 'online videos convey has been \"fine-tuned by millions of years '\n",
+ " 'of evolution\", TED curator Chris Anderson referred to several '\n",
+ " 'YouTube contributors and asserted that \"what Gutenberg did for '\n",
+ " 'writing, online video can now do for face-to-face '\n",
+ " 'communication\". Anderson asserted that it\\'s not far-fetched to '\n",
+ " 'say that online video will dramatically accelerate scientific '\n",
+ " 'advance, and that video contributors may be about to launch \"the '\n",
+ " 'biggest learning cycle in human history.\" In education, for '\n",
+ " 'example, the Khan Academy grew from YouTube video tutoring '\n",
+ " \"sessions for founder Salman Khan's cousin into what Forbes' \"\n",
+ " 'Michael Noer called \"the largest school in the world\", with '\n",
+ " 'technology poised to disrupt how people learn.',\n",
+ " 'score': 3.768488883972168}]\n"
+ ]
+ }
+ ],
"source": [
"question = \"What are the first names of the men that invented youtube?\"\n",
"context = get_context(question, top_k=1)\n",
@@ -855,7 +1339,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 24,
"id": "juXlctWgJgMF",
"metadata": {
"colab": {
@@ -864,7 +1348,80 @@
"id": "juXlctWgJgMF",
"outputId": "e25d311a-5ff5-4b5a-f1f2-f07bf606a076"
},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[{'answer': 'his theories of special relativity and general relativity',\n",
+ " 'context': 'Albert Einstein is known for his theories of special relativity '\n",
+ " 'and general relativity. He also made important contributions to '\n",
+ " 'statistical mechanics, especially his mathematical treatment of '\n",
+ " 'Brownian motion, his resolution of the paradox of specific '\n",
+ " 'heats, and his connection of fluctuations and dissipation. '\n",
+ " 'Despite his reservations about its interpretation, Einstein also '\n",
+ " 'made contributions to quantum mechanics and, indirectly, quantum '\n",
+ " 'field theory, primarily through his theoretical studies of the '\n",
+ " 'photon.',\n",
+ " 'score': 5.752651214599609},\n",
+ " {'answer': 'industrial prince \"',\n",
+ " 'context': 'In October 1919, Albert went up to Trinity College, Cambridge, '\n",
+ " 'where he studied history, economics and civics for a year. On 4 '\n",
+ " 'June 1920, he was created Duke of York, Earl of Inverness and '\n",
+ " 'Baron Killarney. He began to take on more royal duties. He '\n",
+ " 'represented his father, and toured coal mines, factories, and '\n",
+ " 'railyards. Through such visits he acquired the nickname of the '\n",
+ " '\"Industrial Prince\". His stammer, and his embarrassment over it, '\n",
+ " 'together with his tendency to shyness, caused him to appear much '\n",
+ " 'less impressive than his older brother, Edward. However, he was '\n",
+ " 'physically active and enjoyed playing tennis. He played at '\n",
+ " \"Wimbledon in the Men's Doubles with Louis Greig in 1926, losing \"\n",
+ " 'in the first round. He developed an interest in working '\n",
+ " 'conditions, and was President of the Industrial Welfare Society. '\n",
+ " 'His series of annual summer camps for boys between 1921 and 1939 '\n",
+ " 'brought together boys from different social backgrounds.',\n",
+ " 'score': 3.201995849609375},\n",
+ " {'answer': '',\n",
+ " 'context': 'Another who contributed significantly to the spirituality of the '\n",
+ " 'order is Albertus Magnus, the only person of the period to be '\n",
+ " 'given the appellation \"Great\". His influence on the brotherhood '\n",
+ " 'permeated nearly every aspect of Dominican life. Albert was a '\n",
+ " 'scientist, philosopher, astrologer, theologian, spiritual '\n",
+ " 'writer, ecumenist, and diplomat. Under the auspices of Humbert '\n",
+ " 'of Romans, Albert molded the curriculum of studies for all '\n",
+ " 'Dominican students, introduced Aristotle to the classroom and '\n",
+ " 'probed the work of Neoplatonists, such as Plotinus. Indeed, it '\n",
+ " 'was the thirty years of work done by Thomas Aquinas and himself '\n",
+ " '(1245–1274) that allowed for the inclusion of Aristotelian study '\n",
+ " 'in the curriculum of Dominican schools.',\n",
+ " 'score': 2.5859487056732178},\n",
+ " {'answer': '',\n",
+ " 'context': 'Von Neumann liked to eat and drink; his wife, Klara, said that '\n",
+ " 'he could count everything except calories. He enjoyed Yiddish '\n",
+ " 'and \"off-color\" humor (especially limericks). He was a '\n",
+ " 'non-smoker. At Princeton he received complaints for regularly '\n",
+ " 'playing extremely loud German march music on his gramophone, '\n",
+ " 'which distracted those in neighbouring offices, including Albert '\n",
+ " 'Einstein, from their work. Von Neumann did some of his best work '\n",
+ " 'blazingly fast in noisy, chaotic environments, and once '\n",
+ " 'admonished his wife for preparing a quiet study for him to work '\n",
+ " \"in. He never used it, preferring the couple's living room with \"\n",
+ " 'its television playing loudly.',\n",
+ " 'score': 2.254808187484741},\n",
+ " {'answer': 'his defense of classical liberalism',\n",
+ " 'context': 'Friedrich Hayek CH (German: [ˈfʁiːdʁɪç ˈaʊ̯ɡʊst ˈhaɪ̯ɛk]; 8 May '\n",
+ " '1899 – 23 March 1992), born in Austria-Hungary as Friedrich '\n",
+ " 'August von Hayek and frequently referred to as F. A. Hayek, was '\n",
+ " 'an Austrian and British economist and philosopher best known for '\n",
+ " 'his defense of classical liberalism. Hayek shared the 1974 Nobel '\n",
+ " 'Memorial Prize in Economic Sciences with Gunnar Myrdal for his '\n",
+ " '\"pioneering work in the theory of money and economic '\n",
+ " 'fluctuations and ... penetrating analysis of the interdependence '\n",
+ " 'of economic, social and institutional phenomena.\"',\n",
+ " 'score': 1.5893915891647339}]\n"
+ ]
+ }
+ ],
"source": [
"question = \"What is Albert Eistein famous for?\"\n",
"context = get_context(question, top_k=1)\n",
@@ -883,7 +1440,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 25,
"id": "iXACn71xmett",
"metadata": {
"colab": {
@@ -892,7 +1449,74 @@
"id": "iXACn71xmett",
"outputId": "18463177-9144-4145-ef00-1bef3ae175c4"
},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[{'answer': 'frank borman',\n",
+ " 'context': 'On December 21, 1968, Frank Borman, James Lovell, and William '\n",
+ " 'Anders became the first humans to ride the Saturn V rocket into '\n",
+ " 'space on Apollo 8. They also became the first to leave low-Earth '\n",
+ " 'orbit and go to another celestial body, and entered lunar orbit '\n",
+ " 'on December 24. They made ten orbits in twenty hours, and '\n",
+ " 'transmitted one of the most watched TV broadcasts in history, '\n",
+ " 'with their Christmas Eve program from lunar orbit, that '\n",
+ " 'concluded with a reading from the biblical Book of Genesis. Two '\n",
+ " 'and a half hours after the broadcast, they fired their engine to '\n",
+ " 'perform the first trans-Earth injection to leave lunar orbit and '\n",
+ " 'return to the Earth. Apollo 8 safely landed in the Pacific ocean '\n",
+ " \"on December 27, in NASA's first dawn splashdown and recovery.\",\n",
+ " 'score': 7.283915042877197},\n",
+ " {'answer': 'neil armstrong',\n",
+ " 'context': 'Apollo 11 was prepared with the goal of a July landing in the '\n",
+ " 'Sea of Tranquility. The crew, selected in January 1969, '\n",
+ " 'consisted of commander (CDR) Neil Armstrong, Command Module '\n",
+ " 'Pilot (CMP) Michael Collins, and Lunar Module Pilot (LMP) Edwin '\n",
+ " '\"Buzz\" Aldrin. They trained for the mission until just before '\n",
+ " 'the actual launch day. On July 16, 1969, at exactly 9:32 am EDT, '\n",
+ " 'the Saturn V rocket, AS-506, lifted off from Kennedy Space '\n",
+ " 'Center Launch Complex 39 in Florida.',\n",
+ " 'score': 5.545875549316406},\n",
+ " {'answer': 'armstrong',\n",
+ " 'context': 'The trip to the Moon took just over three days. After achieving '\n",
+ " 'orbit, Armstrong and Aldrin transferred into the Lunar Module, '\n",
+ " 'named Eagle, and after a landing gear inspection by Collins '\n",
+ " 'remaining in the Command/Service Module Columbia, began their '\n",
+ " 'descent. After overcoming several computer overload alarms '\n",
+ " 'caused by an antenna switch left in the wrong position, and a '\n",
+ " 'slight downrange error, Armstrong took over manual flight '\n",
+ " 'control at about 180 meters (590 ft), and guided the Lunar '\n",
+ " 'Module to a safe landing spot at 20:18:04 UTC, July 20, 1969 '\n",
+ " '(3:17:04 pm CDT). The first humans on the Moon would wait '\n",
+ " 'another six hours before they ventured out of their craft. At '\n",
+ " '02:56 UTC, July 21 (9:56 pm CDT July 20), Armstrong became the '\n",
+ " 'first human to set foot on the Moon.',\n",
+ " 'score': 5.238486289978027},\n",
+ " {'answer': 'apollo 10',\n",
+ " 'context': 'The American Lunar Module was finally ready for a successful '\n",
+ " 'piloted test flight in low Earth orbit on Apollo 9 in March '\n",
+ " '1969. The next mission, Apollo 10, conducted a \"dress rehearsal\" '\n",
+ " 'for the first landing in May 1969, flying the LM in lunar orbit '\n",
+ " 'as close as 47,400 feet (14.4 km) above the surface, the point '\n",
+ " 'where the powered descent to the surface would begin. With the '\n",
+ " 'LM proven to work well, the next step was to attempt the actual '\n",
+ " 'landing.',\n",
+ " 'score': 2.8688693046569824},\n",
+ " {'answer': 'aldrin',\n",
+ " 'context': 'The first step was witnessed by at least one-fifth of the '\n",
+ " 'population of Earth, or about 723 million people. His first '\n",
+ " \"words when he stepped off the LM's landing footpad were, \"\n",
+ " '\"That\\'s one small step for [a] man, one giant leap for '\n",
+ " 'mankind.\" Aldrin joined him on the surface almost 20 minutes '\n",
+ " 'later. Altogether, they spent just under two and one-quarter '\n",
+ " 'hours outside their craft. The next day, they performed the '\n",
+ " 'first launch from another celestial body, and rendezvoused back '\n",
+ " 'with Columbia.',\n",
+ " 'score': -2.276970863342285}]\n"
+ ]
+ }
+ ],
"source": [
"question = \"Who was the first person to step foot on the moon?\"\n",
"context = get_context(question, top_k=3)\n",
@@ -911,7 +1535,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 26,
"id": "d83f9f55-b099-4280-a12e-1d0192f4f5aa",
"metadata": {},
"outputs": [],
@@ -942,7 +1566,7 @@
},
"gpuClass": "standard",
"kernelspec": {
- "display_name": "Python 3 (ipykernel)",
+ "display_name": ".venv (3.14.0)",
"language": "python",
"name": "python3"
},
@@ -956,7 +1580,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.11.8"
+ "version": "3.14.0"
},
"papermill": {
"default_parameters": {},
@@ -970,11 +1594,6 @@
"start_time": "2021-04-15T21:06:38.122812",
"version": "2.3.3"
},
- "vscode": {
- "interpreter": {
- "hash": "5fe10bf018ef3e697f9035d60bf60847932a12bface18908407fd371fe880db9"
- }
- },
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"00b344135da443ac90e6e6a0f53cfe0f": {
From fba5aff2a7090245829a6417d729dd51ace16d6e Mon Sep 17 00:00:00 2001
From: Anastasia Kabanovsky <124449724+keirialaa@users.noreply.github.com>
Date: Thu, 21 May 2026 21:03:52 +0200
Subject: [PATCH 2/3] Lab Submission
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
create mode 100644 .gitignore
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2eea525
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.env
\ No newline at end of file
From daaed1cf4d82a181ce8555635e56367883974f1d Mon Sep 17 00:00:00 2001
From: Anastasia Kabanovsky <124449724+keirialaa@users.noreply.github.com>
Date: Thu, 21 May 2026 21:20:28 +0200
Subject: [PATCH 3/3] Lab Submission
---
lab-extractive-question-answering.ipynb | 661 +-----------------------
1 file changed, 26 insertions(+), 635 deletions(-)
diff --git a/lab-extractive-question-answering.ipynb b/lab-extractive-question-answering.ipynb
index 9a87b4b..3411eb8 100644
--- a/lab-extractive-question-answering.ipynb
+++ b/lab-extractive-question-answering.ipynb
@@ -54,7 +54,7 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": null,
"id": "740a3cf7-830c-4f1d-bf8d-90d18f908a99",
"metadata": {},
"outputs": [],
@@ -137,7 +137,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": null,
"id": "J250IJeh7NIb",
"metadata": {
"colab": {
@@ -237,123 +237,7 @@
"id": "J250IJeh7NIb",
"outputId": "6f249347-51f8-48be-ab90-a202eee648a7"
},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Using the latest cached version of the dataset since squad couldn't be found on the Hugging Face Hub\n",
- "Found the latest cached dataset configuration 'plain_text' at /Users/anastasiakabanovsky/.cache/huggingface/datasets/squad/plain_text/0.0.0/7b6d24c440a36b6815f21b70d25016731768db1f (last modified on Sun May 17 16:57:10 2026).\n"
- ]
- },
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " id | \n",
- " title | \n",
- " context | \n",
- " question | \n",
- " answers | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " | 0 | \n",
- " 5733be284776f41900661182 | \n",
- " University_of_Notre_Dame | \n",
- " Architecturally, the school has a Catholic cha... | \n",
- " To whom did the Virgin Mary allegedly appear i... | \n",
- " {'text': ['Saint Bernadette Soubirous'], 'answ... | \n",
- "
\n",
- " \n",
- " | 1 | \n",
- " 5733be284776f4190066117f | \n",
- " University_of_Notre_Dame | \n",
- " Architecturally, the school has a Catholic cha... | \n",
- " What is in front of the Notre Dame Main Building? | \n",
- " {'text': ['a copper statue of Christ'], 'answe... | \n",
- "
\n",
- " \n",
- " | 2 | \n",
- " 5733be284776f41900661180 | \n",
- " University_of_Notre_Dame | \n",
- " Architecturally, the school has a Catholic cha... | \n",
- " The Basilica of the Sacred heart at Notre Dame... | \n",
- " {'text': ['the Main Building'], 'answer_start'... | \n",
- "
\n",
- " \n",
- " | 3 | \n",
- " 5733be284776f41900661181 | \n",
- " University_of_Notre_Dame | \n",
- " Architecturally, the school has a Catholic cha... | \n",
- " What is the Grotto at Notre Dame? | \n",
- " {'text': ['a Marian place of prayer and reflec... | \n",
- "
\n",
- " \n",
- " | 4 | \n",
- " 5733be284776f4190066117e | \n",
- " University_of_Notre_Dame | \n",
- " Architecturally, the school has a Catholic cha... | \n",
- " What sits on top of the Main Building at Notre... | \n",
- " {'text': ['a golden statue of the Virgin Mary'... | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " id title \\\n",
- "0 5733be284776f41900661182 University_of_Notre_Dame \n",
- "1 5733be284776f4190066117f University_of_Notre_Dame \n",
- "2 5733be284776f41900661180 University_of_Notre_Dame \n",
- "3 5733be284776f41900661181 University_of_Notre_Dame \n",
- "4 5733be284776f4190066117e University_of_Notre_Dame \n",
- "\n",
- " context \\\n",
- "0 Architecturally, the school has a Catholic cha... \n",
- "1 Architecturally, the school has a Catholic cha... \n",
- "2 Architecturally, the school has a Catholic cha... \n",
- "3 Architecturally, the school has a Catholic cha... \n",
- "4 Architecturally, the school has a Catholic cha... \n",
- "\n",
- " question \\\n",
- "0 To whom did the Virgin Mary allegedly appear i... \n",
- "1 What is in front of the Notre Dame Main Building? \n",
- "2 The Basilica of the Sacred heart at Notre Dame... \n",
- "3 What is the Grotto at Notre Dame? \n",
- "4 What sits on top of the Main Building at Notre... \n",
- "\n",
- " answers \n",
- "0 {'text': ['Saint Bernadette Soubirous'], 'answ... \n",
- "1 {'text': ['a copper statue of Christ'], 'answe... \n",
- "2 {'text': ['the Main Building'], 'answer_start'... \n",
- "3 {'text': ['a Marian place of prayer and reflec... \n",
- "4 {'text': ['a golden statue of the Virgin Mary'... "
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"from datasets import load_dataset\n",
"\n",
@@ -364,7 +248,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": null,
"id": "FcmeNO97dHDO",
"metadata": {
"colab": {
@@ -374,128 +258,7 @@
"id": "FcmeNO97dHDO",
"outputId": "11af1908-8950-4433-f66d-7d363d010c97"
},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " title | \n",
- " context | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " | 0 | \n",
- " University_of_Notre_Dame | \n",
- " Architecturally, the school has a Catholic cha... | \n",
- "
\n",
- " \n",
- " | 5 | \n",
- " University_of_Notre_Dame | \n",
- " As at most other universities, Notre Dame's st... | \n",
- "
\n",
- " \n",
- " | 10 | \n",
- " University_of_Notre_Dame | \n",
- " The university is the major seat of the Congre... | \n",
- "
\n",
- " \n",
- " | 15 | \n",
- " University_of_Notre_Dame | \n",
- " The College of Engineering was established in ... | \n",
- "
\n",
- " \n",
- " | 20 | \n",
- " University_of_Notre_Dame | \n",
- " All of Notre Dame's undergraduate students are... | \n",
- "
\n",
- " \n",
- " | ... | \n",
- " ... | \n",
- " ... | \n",
- "
\n",
- " \n",
- " | 87574 | \n",
- " Kathmandu | \n",
- " Institute of Medicine, the central college of ... | \n",
- "
\n",
- " \n",
- " | 87579 | \n",
- " Kathmandu | \n",
- " Football and Cricket are the most popular spor... | \n",
- "
\n",
- " \n",
- " | 87584 | \n",
- " Kathmandu | \n",
- " The total length of roads in Nepal is recorded... | \n",
- "
\n",
- " \n",
- " | 87589 | \n",
- " Kathmandu | \n",
- " The main international airport serving Kathman... | \n",
- "
\n",
- " \n",
- " | 87594 | \n",
- " Kathmandu | \n",
- " Kathmandu Metropolitan City (KMC), in order to... | \n",
- "
\n",
- " \n",
- "
\n",
- "
18891 rows × 2 columns
\n",
- "
"
- ],
- "text/plain": [
- " title \\\n",
- "0 University_of_Notre_Dame \n",
- "5 University_of_Notre_Dame \n",
- "10 University_of_Notre_Dame \n",
- "15 University_of_Notre_Dame \n",
- "20 University_of_Notre_Dame \n",
- "... ... \n",
- "87574 Kathmandu \n",
- "87579 Kathmandu \n",
- "87584 Kathmandu \n",
- "87589 Kathmandu \n",
- "87594 Kathmandu \n",
- "\n",
- " context \n",
- "0 Architecturally, the school has a Catholic cha... \n",
- "5 As at most other universities, Notre Dame's st... \n",
- "10 The university is the major seat of the Congre... \n",
- "15 The College of Engineering was established in ... \n",
- "20 All of Notre Dame's undergraduate students are... \n",
- "... ... \n",
- "87574 Institute of Medicine, the central college of ... \n",
- "87579 Football and Cricket are the most popular spor... \n",
- "87584 The total length of roads in Nepal is recorded... \n",
- "87589 The main international airport serving Kathman... \n",
- "87594 Kathmandu Metropolitan City (KMC), in order to... \n",
- "\n",
- "[18891 rows x 2 columns]"
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"# select only title and context column\n",
"df = df[[\"title\", \"context\"]]\n",
@@ -536,7 +299,7 @@
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": null,
"id": "092d1e71",
"metadata": {
"id": "092d1e71"
@@ -566,7 +329,7 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": null,
"id": "b3206184",
"metadata": {
"id": "b3206184"
@@ -616,7 +379,7 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": null,
"id": "31a85bb3",
"metadata": {
"colab": {
@@ -782,29 +545,7 @@
"id": "31a85bb3",
"outputId": "6ee65615-6cd5-4e06-f5b6-97263e4d7474"
},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Loading weights: 100%|██████████| 103/103 [00:00<00:00, 8976.90it/s]\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "SentenceTransformer(\n",
- " (0): Transformer({'transformer_task': 'feature-extraction', 'modality_config': {'text': {'method': 'forward', 'method_output_name': 'last_hidden_state'}}, 'module_output_name': 'token_embeddings', 'architecture': 'BertModel'})\n",
- " (1): Pooling({'embedding_dimension': 384, 'pooling_mode': 'mean', 'include_prompt': True})\n",
- " (2): Normalize({})\n",
- ")"
- ]
- },
- "execution_count": 9,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"import torch\n",
"from sentence_transformers import SentenceTransformer\n",
@@ -838,7 +579,7 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": null,
"id": "a17824ef",
"metadata": {
"colab": {
@@ -862,25 +603,7 @@
"outputId": "c2b46e15-4648-4377-a5aa-19cb01d92a25",
"tags": []
},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "100%|██████████| 296/296 [05:19<00:00, 1.08s/it]\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "DescribeIndexStatsResponse(dimension=384, total_vector_count=18891, metric='cosine', namespaces=1)"
- ]
- },
- "execution_count": 10,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"from tqdm.auto import tqdm\n",
"\n",
@@ -929,7 +652,7 @@
},
{
"cell_type": "code",
- "execution_count": 20,
+ "execution_count": null,
"id": "hg9XTDkIJzH_",
"metadata": {
"colab": {
@@ -996,15 +719,7 @@
"id": "hg9XTDkIJzH_",
"outputId": "0309c40e-b037-44f0-b2d1-8da457201b93"
},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "Loading weights: 100%|██████████| 199/199 [00:00<00:00, 14068.91it/s]\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"from transformers import AutoTokenizer, AutoModelForQuestionAnswering\n",
"\n",
@@ -1038,7 +753,7 @@
},
{
"cell_type": "code",
- "execution_count": 16,
+ "execution_count": null,
"id": "lyYaY3QEQiHZ",
"metadata": {
"id": "lyYaY3QEQiHZ"
@@ -1058,7 +773,7 @@
},
{
"cell_type": "code",
- "execution_count": 17,
+ "execution_count": null,
"id": "Dc9VYOiUQA7B",
"metadata": {
"id": "Dc9VYOiUQA7B"
@@ -1083,7 +798,7 @@
},
{
"cell_type": "code",
- "execution_count": 21,
+ "execution_count": null,
"id": "5E3a3dkJ5ZQD",
"metadata": {
"colab": {
@@ -1092,22 +807,7 @@
"id": "5E3a3dkJ5ZQD",
"outputId": "9c49972e-d87b-47f8-b17a-92c616d14f3f"
},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "['Egypt was producing 691,000 bbl/d of oil and 2,141.05 Tcf of natural gas (in 2013), which makes Egypt as the largest oil producer not member of the Organization of the Petroleum Exporting Countries (OPEC) and the second-largest dry natural gas producer in Africa. In 2013, Egypt was the largest consumer of oil and natural gas in Africa, as more than 20% of total oil consumption and more than 40% of total dry natural gas consumption in Africa. Also, Egypt possesses the largest oil refinery capacity in Africa 726,000 bbl/d (in 2012). Egypt is currently planning to build its first nuclear power plant in El Dabaa city, northern Egypt.',\n",
- " 'Egypt has a developed energy market based on coal, oil, natural gas, and hydro power. Substantial coal deposits in the northeast Sinai are mined at the rate of about 600,000 tonnes (590,000 long tons; 660,000 short tons) per year. Oil and gas are produced in the western desert regions, the Gulf of Suez, and the Nile Delta. Egypt has huge reserves of gas, estimated at 2,180 cubic kilometres (520 cu mi), and LNG up to 2012 exported to many countries. In 2013, the Egyptian General Petroleum Co (EGPC) said the country will cut exports of natural gas and tell major industries to slow output this summer to avoid an energy crisis and stave off political unrest, Reuters has reported. Egypt is counting on top liquid natural gas (LNG) exporter Qatar to obtain additional gas volumes in summer, while encouraging factories to plan their annual maintenance for those months of peak demand, said EGPC chairman, Tarek El Barkatawy. Egypt produces its own energy, but has been a net oil importer since 2008 and is rapidly becoming a net importer of natural gas.',\n",
- " \"Iran has the second largest proved gas reserves in the world after Russia, with 33.6 trillion cubic metres, and third largest natural gas production in the world after Indonesia, and Russia. It also ranks fourth in oil reserves with an estimated 153,600,000,000 barrels. It is OPEC's 2nd largest oil exporter and is an energy superpower. In 2005, Iran spent US$4 billion on fuel imports, because of contraband and inefficient domestic use. Oil industry output averaged 4 million barrels per day (640,000 m3/d) in 2005, compared with the peak of six million barrels per day reached in 1974. In the early years of the 2000s (decade), industry infrastructure was increasingly inefficient because of technological lags. Few exploratory wells were drilled in 2005.\",\n",
- " \"Egypt's economy depends mainly on agriculture, media, petroleum imports, natural gas, and tourism; there are also more than three million Egyptians working abroad, mainly in Saudi Arabia, the Persian Gulf and Europe. The completion of the Aswan High Dam in 1970 and the resultant Lake Nasser have altered the time-honored place of the Nile River in the agriculture and ecology of Egypt. A rapidly growing population, limited arable land, and dependence on the Nile all continue to overtax resources and stress the economy.\",\n",
- " 'Rajasthan is[when?] earning Rs. 150 million (approx. US$2.5 million) per day as revenue from the crude oil sector. This earning is expected to reach ₹250 million per day in 2013 (which is an increase of ₹100 million or more than 66 percent). The government of India has given permission to extract 300,000 barrels of crude per day from Barmer region which is now 175,000 barrels per day. Once this limit is achieved Rajasthan will become a leader in Crude extraction in Country. Bombay High leads with a production of 250,000 barrels crude per day. Once the limit if 300,000 barrels per day is reached, the overall production of the country will increase by 15 percent. Cairn India is doing the work of exploration and extraction of crude oil in Rajasthan.']"
- ]
- },
- "execution_count": 21,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"question = \"How much oil is Egypt producing in a day?\"\n",
"context = get_context(question, top_k = 1)\n",
@@ -1126,7 +826,7 @@
},
{
"cell_type": "code",
- "execution_count": 22,
+ "execution_count": null,
"id": "DQ4GWdbMSjPl",
"metadata": {
"colab": {
@@ -1135,99 +835,7 @@
"id": "DQ4GWdbMSjPl",
"outputId": "73eabb60-e42a-4983-ed7f-a90e51eb9781"
},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[{'answer': '691, 000 bbl / d',\n",
- " 'context': 'Egypt was producing 691,000 bbl/d of oil and 2,141.05 Tcf of '\n",
- " 'natural gas (in 2013), which makes Egypt as the largest oil '\n",
- " 'producer not member of the Organization of the Petroleum '\n",
- " 'Exporting Countries (OPEC) and the second-largest dry natural '\n",
- " 'gas producer in Africa. In 2013, Egypt was the largest consumer '\n",
- " 'of oil and natural gas in Africa, as more than 20% of total oil '\n",
- " 'consumption and more than 40% of total dry natural gas '\n",
- " 'consumption in Africa. Also, Egypt possesses the largest oil '\n",
- " 'refinery capacity in Africa 726,000 bbl/d (in 2012). Egypt is '\n",
- " 'currently planning to build its first nuclear power plant in El '\n",
- " 'Dabaa city, northern Egypt.',\n",
- " 'score': 10.66650390625},\n",
- " {'answer': '[SEP] rajasthan is [ when? ] earning rs. 150 million ( approx. us '\n",
- " '$ 2. 5 million ) per day as revenue from the crude oil sector. '\n",
- " 'this earning is expected to reach ₹250 million per day in 2013 ( '\n",
- " 'which is an increase of ₹100 million or more than 66 percent ). '\n",
- " 'the government of india has given permission to extract 300, 000 '\n",
- " 'barrels of crude per day from barmer region which is now 175, 000 '\n",
- " 'barrels per day. once this limit is achieved rajasthan will '\n",
- " 'become a leader in crude extraction in country. bombay high leads '\n",
- " 'with a production of 250, 000 barrels crude per day. once the '\n",
- " 'limit if 300, 000 barrels per day is reached, the overall '\n",
- " 'production of the country will increase by 15 percent. cairn '\n",
- " 'india is doing the work of exploration and extraction of crude '\n",
- " 'oil in rajasthan. [SEP]',\n",
- " 'context': 'Rajasthan is[when?] earning Rs. 150 million (approx. US$2.5 '\n",
- " 'million) per day as revenue from the crude oil sector. This '\n",
- " 'earning is expected to reach ₹250 million per day in 2013 (which '\n",
- " 'is an increase of ₹100 million or more than 66 percent). The '\n",
- " 'government of India has given permission to extract 300,000 '\n",
- " 'barrels of crude per day from Barmer region which is now 175,000 '\n",
- " 'barrels per day. Once this limit is achieved Rajasthan will '\n",
- " 'become a leader in Crude extraction in Country. Bombay High '\n",
- " 'leads with a production of 250,000 barrels crude per day. Once '\n",
- " 'the limit if 300,000 barrels per day is reached, the overall '\n",
- " 'production of the country will increase by 15 percent. Cairn '\n",
- " 'India is doing the work of exploration and extraction of crude '\n",
- " 'oil in Rajasthan.',\n",
- " 'score': 7.590670585632324},\n",
- " {'answer': '[CLS]',\n",
- " 'context': 'Iran has the second largest proved gas reserves in the world '\n",
- " 'after Russia, with 33.6 trillion cubic metres, and third largest '\n",
- " 'natural gas production in the world after Indonesia, and Russia. '\n",
- " 'It also ranks fourth in oil reserves with an estimated '\n",
- " \"153,600,000,000 barrels. It is OPEC's 2nd largest oil exporter \"\n",
- " 'and is an energy superpower. In 2005, Iran spent US$4 billion on '\n",
- " 'fuel imports, because of contraband and inefficient domestic '\n",
- " 'use. Oil industry output averaged 4 million barrels per day '\n",
- " '(640,000 m3/d) in 2005, compared with the peak of six million '\n",
- " 'barrels per day reached in 1974. In the early years of the 2000s '\n",
- " '(decade), industry infrastructure was increasingly inefficient '\n",
- " 'because of technological lags. Few exploratory wells were '\n",
- " 'drilled in 2005.',\n",
- " 'score': 6.90549898147583},\n",
- " {'answer': '[CLS]',\n",
- " 'context': 'Egypt has a developed energy market based on coal, oil, natural '\n",
- " 'gas, and hydro power. Substantial coal deposits in the northeast '\n",
- " 'Sinai are mined at the rate of about 600,000 tonnes (590,000 '\n",
- " 'long tons; 660,000 short tons) per year. Oil and gas are '\n",
- " 'produced in the western desert regions, the Gulf of Suez, and '\n",
- " 'the Nile Delta. Egypt has huge reserves of gas, estimated at '\n",
- " '2,180 cubic kilometres (520 cu mi), and LNG up to 2012 exported '\n",
- " 'to many countries. In 2013, the Egyptian General Petroleum Co '\n",
- " '(EGPC) said the country will cut exports of natural gas and tell '\n",
- " 'major industries to slow output this summer to avoid an energy '\n",
- " 'crisis and stave off political unrest, Reuters has reported. '\n",
- " 'Egypt is counting on top liquid natural gas (LNG) exporter Qatar '\n",
- " 'to obtain additional gas volumes in summer, while encouraging '\n",
- " 'factories to plan their annual maintenance for those months of '\n",
- " 'peak demand, said EGPC chairman, Tarek El Barkatawy. Egypt '\n",
- " 'produces its own energy, but has been a net oil importer since '\n",
- " '2008 and is rapidly becoming a net importer of natural gas.',\n",
- " 'score': 4.752947807312012},\n",
- " {'answer': '[CLS]',\n",
- " 'context': \"Egypt's economy depends mainly on agriculture, media, petroleum \"\n",
- " 'imports, natural gas, and tourism; there are also more than '\n",
- " 'three million Egyptians working abroad, mainly in Saudi Arabia, '\n",
- " 'the Persian Gulf and Europe. The completion of the Aswan High '\n",
- " 'Dam in 1970 and the resultant Lake Nasser have altered the '\n",
- " 'time-honored place of the Nile River in the agriculture and '\n",
- " 'ecology of Egypt. A rapidly growing population, limited arable '\n",
- " 'land, and dependence on the Nile all continue to overtax '\n",
- " 'resources and stress the economy.',\n",
- " 'score': 1.0393000841140747}]\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"extract_answer(question, context)"
]
@@ -1244,7 +852,7 @@
},
{
"cell_type": "code",
- "execution_count": 23,
+ "execution_count": null,
"id": "_4NRgV4mGWoj",
"metadata": {
"colab": {
@@ -1253,84 +861,7 @@
"id": "_4NRgV4mGWoj",
"outputId": "4140fe3e-32b9-42ad-8631-303d07df6dda"
},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[{'answer': 'hurley and chen',\n",
- " 'context': 'According to a story that has often been repeated in the media, '\n",
- " 'Hurley and Chen developed the idea for YouTube during the early '\n",
- " 'months of 2005, after they had experienced difficulty sharing '\n",
- " \"videos that had been shot at a dinner party at Chen's apartment \"\n",
- " 'in San Francisco. Karim did not attend the party and denied that '\n",
- " 'it had occurred, but Chen commented that the idea that YouTube '\n",
- " 'was founded after a dinner party \"was probably very strengthened '\n",
- " 'by marketing ideas around creating a story that was very '\n",
- " 'digestible\".',\n",
- " 'score': 8.594069480895996},\n",
- " {'answer': '',\n",
- " 'context': 'The first web browser was invented in 1990 by Sir Tim '\n",
- " 'Berners-Lee. Berners-Lee is the director of the World Wide Web '\n",
- " \"Consortium (W3C), which oversees the Web's continued \"\n",
- " 'development, and is also the founder of the World Wide Web '\n",
- " 'Foundation. His browser was called WorldWideWeb and later '\n",
- " 'renamed Nexus.',\n",
- " 'score': 7.221705436706543},\n",
- " {'answer': '[SEP] in june 2007, youtube began trials of a system for '\n",
- " 'automatic detection of uploaded videos that infringe copyright. '\n",
- " 'google ceo eric schmidt regarded this system as necessary for '\n",
- " 'resolving lawsuits such as the one from viacom, which alleged '\n",
- " 'that youtube profited from content that it did not have the right '\n",
- " 'to distribute. the system, which became known as content id, '\n",
- " 'creates an id file for copyrighted audio and video material, and '\n",
- " 'stores it in a database. when a video is uploaded, it is checked '\n",
- " 'against the database, and flags the video as a copyright '\n",
- " 'violation if a match is found. [SEP]',\n",
- " 'context': 'In June 2007, YouTube began trials of a system for automatic '\n",
- " 'detection of uploaded videos that infringe copyright. Google CEO '\n",
- " 'Eric Schmidt regarded this system as necessary for resolving '\n",
- " 'lawsuits such as the one from Viacom, which alleged that YouTube '\n",
- " 'profited from content that it did not have the right to '\n",
- " 'distribute. The system, which became known as Content ID, '\n",
- " 'creates an ID File for copyrighted audio and video material, and '\n",
- " 'stores it in a database. When a video is uploaded, it is checked '\n",
- " 'against the database, and flags the video as a copyright '\n",
- " 'violation if a match is found.',\n",
- " 'score': 6.786528587341309},\n",
- " {'answer': 'ronaldinho',\n",
- " 'context': 'YouTube offered the public a beta test of the site in May 2005. '\n",
- " 'The first video to reach one million views was a Nike '\n",
- " 'advertisement featuring Ronaldinho in September 2005. Following '\n",
- " 'a $3.5 million investment from Sequoia Capital in November, the '\n",
- " 'site launched officially on December 15, 2005, by which time the '\n",
- " 'site was receiving 8 million views a day. The site grew rapidly, '\n",
- " 'and in July 2006 the company announced that more than 65,000 new '\n",
- " 'videos were being uploaded every day, and that the site was '\n",
- " 'receiving 100 million video views per day. According to data '\n",
- " 'published by market research company comScore, YouTube is the '\n",
- " 'dominant provider of online video in the United States, with a '\n",
- " 'market share of around 43% and more than 14 billion views of '\n",
- " 'videos in May 2010.',\n",
- " 'score': 6.743083477020264},\n",
- " {'answer': '[CLS]',\n",
- " 'context': 'Observing that face-to-face communication of the type that '\n",
- " 'online videos convey has been \"fine-tuned by millions of years '\n",
- " 'of evolution\", TED curator Chris Anderson referred to several '\n",
- " 'YouTube contributors and asserted that \"what Gutenberg did for '\n",
- " 'writing, online video can now do for face-to-face '\n",
- " 'communication\". Anderson asserted that it\\'s not far-fetched to '\n",
- " 'say that online video will dramatically accelerate scientific '\n",
- " 'advance, and that video contributors may be about to launch \"the '\n",
- " 'biggest learning cycle in human history.\" In education, for '\n",
- " 'example, the Khan Academy grew from YouTube video tutoring '\n",
- " \"sessions for founder Salman Khan's cousin into what Forbes' \"\n",
- " 'Michael Noer called \"the largest school in the world\", with '\n",
- " 'technology poised to disrupt how people learn.',\n",
- " 'score': 3.768488883972168}]\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"question = \"What are the first names of the men that invented youtube?\"\n",
"context = get_context(question, top_k=1)\n",
@@ -1339,7 +870,7 @@
},
{
"cell_type": "code",
- "execution_count": 24,
+ "execution_count": null,
"id": "juXlctWgJgMF",
"metadata": {
"colab": {
@@ -1348,80 +879,7 @@
"id": "juXlctWgJgMF",
"outputId": "e25d311a-5ff5-4b5a-f1f2-f07bf606a076"
},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[{'answer': 'his theories of special relativity and general relativity',\n",
- " 'context': 'Albert Einstein is known for his theories of special relativity '\n",
- " 'and general relativity. He also made important contributions to '\n",
- " 'statistical mechanics, especially his mathematical treatment of '\n",
- " 'Brownian motion, his resolution of the paradox of specific '\n",
- " 'heats, and his connection of fluctuations and dissipation. '\n",
- " 'Despite his reservations about its interpretation, Einstein also '\n",
- " 'made contributions to quantum mechanics and, indirectly, quantum '\n",
- " 'field theory, primarily through his theoretical studies of the '\n",
- " 'photon.',\n",
- " 'score': 5.752651214599609},\n",
- " {'answer': 'industrial prince \"',\n",
- " 'context': 'In October 1919, Albert went up to Trinity College, Cambridge, '\n",
- " 'where he studied history, economics and civics for a year. On 4 '\n",
- " 'June 1920, he was created Duke of York, Earl of Inverness and '\n",
- " 'Baron Killarney. He began to take on more royal duties. He '\n",
- " 'represented his father, and toured coal mines, factories, and '\n",
- " 'railyards. Through such visits he acquired the nickname of the '\n",
- " '\"Industrial Prince\". His stammer, and his embarrassment over it, '\n",
- " 'together with his tendency to shyness, caused him to appear much '\n",
- " 'less impressive than his older brother, Edward. However, he was '\n",
- " 'physically active and enjoyed playing tennis. He played at '\n",
- " \"Wimbledon in the Men's Doubles with Louis Greig in 1926, losing \"\n",
- " 'in the first round. He developed an interest in working '\n",
- " 'conditions, and was President of the Industrial Welfare Society. '\n",
- " 'His series of annual summer camps for boys between 1921 and 1939 '\n",
- " 'brought together boys from different social backgrounds.',\n",
- " 'score': 3.201995849609375},\n",
- " {'answer': '',\n",
- " 'context': 'Another who contributed significantly to the spirituality of the '\n",
- " 'order is Albertus Magnus, the only person of the period to be '\n",
- " 'given the appellation \"Great\". His influence on the brotherhood '\n",
- " 'permeated nearly every aspect of Dominican life. Albert was a '\n",
- " 'scientist, philosopher, astrologer, theologian, spiritual '\n",
- " 'writer, ecumenist, and diplomat. Under the auspices of Humbert '\n",
- " 'of Romans, Albert molded the curriculum of studies for all '\n",
- " 'Dominican students, introduced Aristotle to the classroom and '\n",
- " 'probed the work of Neoplatonists, such as Plotinus. Indeed, it '\n",
- " 'was the thirty years of work done by Thomas Aquinas and himself '\n",
- " '(1245–1274) that allowed for the inclusion of Aristotelian study '\n",
- " 'in the curriculum of Dominican schools.',\n",
- " 'score': 2.5859487056732178},\n",
- " {'answer': '',\n",
- " 'context': 'Von Neumann liked to eat and drink; his wife, Klara, said that '\n",
- " 'he could count everything except calories. He enjoyed Yiddish '\n",
- " 'and \"off-color\" humor (especially limericks). He was a '\n",
- " 'non-smoker. At Princeton he received complaints for regularly '\n",
- " 'playing extremely loud German march music on his gramophone, '\n",
- " 'which distracted those in neighbouring offices, including Albert '\n",
- " 'Einstein, from their work. Von Neumann did some of his best work '\n",
- " 'blazingly fast in noisy, chaotic environments, and once '\n",
- " 'admonished his wife for preparing a quiet study for him to work '\n",
- " \"in. He never used it, preferring the couple's living room with \"\n",
- " 'its television playing loudly.',\n",
- " 'score': 2.254808187484741},\n",
- " {'answer': 'his defense of classical liberalism',\n",
- " 'context': 'Friedrich Hayek CH (German: [ˈfʁiːdʁɪç ˈaʊ̯ɡʊst ˈhaɪ̯ɛk]; 8 May '\n",
- " '1899 – 23 March 1992), born in Austria-Hungary as Friedrich '\n",
- " 'August von Hayek and frequently referred to as F. A. Hayek, was '\n",
- " 'an Austrian and British economist and philosopher best known for '\n",
- " 'his defense of classical liberalism. Hayek shared the 1974 Nobel '\n",
- " 'Memorial Prize in Economic Sciences with Gunnar Myrdal for his '\n",
- " '\"pioneering work in the theory of money and economic '\n",
- " 'fluctuations and ... penetrating analysis of the interdependence '\n",
- " 'of economic, social and institutional phenomena.\"',\n",
- " 'score': 1.5893915891647339}]\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"question = \"What is Albert Eistein famous for?\"\n",
"context = get_context(question, top_k=1)\n",
@@ -1440,7 +898,7 @@
},
{
"cell_type": "code",
- "execution_count": 25,
+ "execution_count": null,
"id": "iXACn71xmett",
"metadata": {
"colab": {
@@ -1449,74 +907,7 @@
"id": "iXACn71xmett",
"outputId": "18463177-9144-4145-ef00-1bef3ae175c4"
},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[{'answer': 'frank borman',\n",
- " 'context': 'On December 21, 1968, Frank Borman, James Lovell, and William '\n",
- " 'Anders became the first humans to ride the Saturn V rocket into '\n",
- " 'space on Apollo 8. They also became the first to leave low-Earth '\n",
- " 'orbit and go to another celestial body, and entered lunar orbit '\n",
- " 'on December 24. They made ten orbits in twenty hours, and '\n",
- " 'transmitted one of the most watched TV broadcasts in history, '\n",
- " 'with their Christmas Eve program from lunar orbit, that '\n",
- " 'concluded with a reading from the biblical Book of Genesis. Two '\n",
- " 'and a half hours after the broadcast, they fired their engine to '\n",
- " 'perform the first trans-Earth injection to leave lunar orbit and '\n",
- " 'return to the Earth. Apollo 8 safely landed in the Pacific ocean '\n",
- " \"on December 27, in NASA's first dawn splashdown and recovery.\",\n",
- " 'score': 7.283915042877197},\n",
- " {'answer': 'neil armstrong',\n",
- " 'context': 'Apollo 11 was prepared with the goal of a July landing in the '\n",
- " 'Sea of Tranquility. The crew, selected in January 1969, '\n",
- " 'consisted of commander (CDR) Neil Armstrong, Command Module '\n",
- " 'Pilot (CMP) Michael Collins, and Lunar Module Pilot (LMP) Edwin '\n",
- " '\"Buzz\" Aldrin. They trained for the mission until just before '\n",
- " 'the actual launch day. On July 16, 1969, at exactly 9:32 am EDT, '\n",
- " 'the Saturn V rocket, AS-506, lifted off from Kennedy Space '\n",
- " 'Center Launch Complex 39 in Florida.',\n",
- " 'score': 5.545875549316406},\n",
- " {'answer': 'armstrong',\n",
- " 'context': 'The trip to the Moon took just over three days. After achieving '\n",
- " 'orbit, Armstrong and Aldrin transferred into the Lunar Module, '\n",
- " 'named Eagle, and after a landing gear inspection by Collins '\n",
- " 'remaining in the Command/Service Module Columbia, began their '\n",
- " 'descent. After overcoming several computer overload alarms '\n",
- " 'caused by an antenna switch left in the wrong position, and a '\n",
- " 'slight downrange error, Armstrong took over manual flight '\n",
- " 'control at about 180 meters (590 ft), and guided the Lunar '\n",
- " 'Module to a safe landing spot at 20:18:04 UTC, July 20, 1969 '\n",
- " '(3:17:04 pm CDT). The first humans on the Moon would wait '\n",
- " 'another six hours before they ventured out of their craft. At '\n",
- " '02:56 UTC, July 21 (9:56 pm CDT July 20), Armstrong became the '\n",
- " 'first human to set foot on the Moon.',\n",
- " 'score': 5.238486289978027},\n",
- " {'answer': 'apollo 10',\n",
- " 'context': 'The American Lunar Module was finally ready for a successful '\n",
- " 'piloted test flight in low Earth orbit on Apollo 9 in March '\n",
- " '1969. The next mission, Apollo 10, conducted a \"dress rehearsal\" '\n",
- " 'for the first landing in May 1969, flying the LM in lunar orbit '\n",
- " 'as close as 47,400 feet (14.4 km) above the surface, the point '\n",
- " 'where the powered descent to the surface would begin. With the '\n",
- " 'LM proven to work well, the next step was to attempt the actual '\n",
- " 'landing.',\n",
- " 'score': 2.8688693046569824},\n",
- " {'answer': 'aldrin',\n",
- " 'context': 'The first step was witnessed by at least one-fifth of the '\n",
- " 'population of Earth, or about 723 million people. His first '\n",
- " \"words when he stepped off the LM's landing footpad were, \"\n",
- " '\"That\\'s one small step for [a] man, one giant leap for '\n",
- " 'mankind.\" Aldrin joined him on the surface almost 20 minutes '\n",
- " 'later. Altogether, they spent just under two and one-quarter '\n",
- " 'hours outside their craft. The next day, they performed the '\n",
- " 'first launch from another celestial body, and rendezvoused back '\n",
- " 'with Columbia.',\n",
- " 'score': -2.276970863342285}]\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"question = \"Who was the first person to step foot on the moon?\"\n",
"context = get_context(question, top_k=3)\n",
@@ -1535,7 +926,7 @@
},
{
"cell_type": "code",
- "execution_count": 26,
+ "execution_count": null,
"id": "d83f9f55-b099-4280-a12e-1d0192f4f5aa",
"metadata": {},
"outputs": [],