{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":12863,"databundleVersionId":788719,"sourceType":"competition"},{"sourceId":3176,"sourceType":"datasetVersion","datasetId":1835}],"dockerImageVersionId":30698,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import json\nfrom tqdm.notebook import tqdm\n\nimport numpy as np \nimport pandas as pd\nimport matplotlib.pyplot as plt\n\nimport tensorflow as tf\nfrom tensorflow.keras.layers import LSTM, Bidirectional, GlobalMaxPooling1D, SpatialDropout1D, Dense, Dropout, Input, concatenate, Conv1D, Activation, Flatten\n\nfrom nltk.corpus import stopwords\nimport re","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-04-25T23:10:44.624508Z","iopub.execute_input":"2024-04-25T23:10:44.624877Z","iopub.status.idle":"2024-04-25T23:11:01.5923Z","shell.execute_reply.started":"2024-04-25T23:10:44.624846Z","shell.execute_reply":"2024-04-25T23:11:01.591394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# data to load\nNUM_OF_TRAIN_QUESTIONS = 1000\nNUM_OF_VAL_QUESTIONS = 1050\nSAMPLE_RATE = 15\nTRAIN_PATH = '../input/tensorflow2-question-answering/simplified-nq-train.jsonl'\n\n# TOKENIZATION\nFILTERS = '!\"#$%&()*+,-./:;<=>?@[\\\\]^_`{|}~\\t\\n'\nLOWER_CASE = True\nMAX_LEN = 300\n\n# long answer model parameters\nEPOCHS = 40\nBATCH_SIZE = 64\nEMBED_SIZE = 100\nCLASS_WEIGHTS = {0: 0.5, 1: 5.}\n\n# short answer model parameters\nSHORT_EPOCHS = 80\nSHORT_BATCH_SIZE = 32\nSHORT_EMBED_SIZE = 200","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:11:34.742609Z","iopub.execute_input":"2024-04-25T23:11:34.743593Z","iopub.status.idle":"2024-04-25T23:11:34.750412Z","shell.execute_reply.started":"2024-04-25T23:11:34.743554Z","shell.execute_reply":"2024-04-25T23:11:34.748536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_line_of_data(file):\n    line = file.readline()\n    line = json.loads(line)\n    \n    return line\n\n\ndef get_question_and_document(line):\n    question = line['question_text']\n    text = line['document_text'].split(' ')\n    annotations = line['annotations'][0]\n    \n    return question, text, annotations\n                \n                \ndef get_long_candidate(i, annotations, candidate):\n    # check if this candidate is the correct answer\n    if i == annotations['long_answer']['candidate_index']:\n        label = True\n    else:\n        label = False\n\n    # get place where long answer starts and ends in the document text\n    long_start = candidate['start_token']\n    long_end = candidate['end_token']\n    \n    return label, long_start, long_end\n\n\ndef form_data_row(question, label, text, long_start, long_end):\n    row = {\n        'question': question,\n        'long_answer': ' '.join(text[long_start:long_end]),\n        'is_long_answer': label,\n    }\n    \n    return row\n\n\ndef load_data(file_path, questions_start, questions_end):\n    rows = []\n    \n    with open(file_path) as file:\n\n        for i in tqdm(range(questions_start, questions_end)):\n            line = get_line_of_data(file)\n            question, text, annotations = get_question_and_document(line)\n\n            for i, candidate in enumerate(line['long_answer_candidates']):\n                label, long_start, long_end = get_long_candidate(i, annotations, candidate)\n\n                if label == True or (i % SAMPLE_RATE == 0):\n                    rows.append(\n                        form_data_row(question, label, text, long_start, long_end)\n                    )\n        \n    return pd.DataFrame(rows)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:11:59.110375Z","iopub.execute_input":"2024-04-25T23:11:59.110754Z","iopub.status.idle":"2024-04-25T23:11:59.122081Z","shell.execute_reply.started":"2024-04-25T23:11:59.110725Z","shell.execute_reply":"2024-04-25T23:11:59.120962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = load_data(TRAIN_PATH, 0, NUM_OF_TRAIN_QUESTIONS)\nval_df = load_data(TRAIN_PATH, NUM_OF_TRAIN_QUESTIONS, NUM_OF_VAL_QUESTIONS)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:20:42.178602Z","iopub.execute_input":"2024-04-25T23:20:42.179073Z","iopub.status.idle":"2024-04-25T23:20:43.990171Z","shell.execute_reply.started":"2024-04-25T23:20:42.179037Z","shell.execute_reply":"2024-04-25T23:20:43.989301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:21:13.761392Z","iopub.execute_input":"2024-04-25T23:21:13.761769Z","iopub.status.idle":"2024-04-25T23:21:13.784378Z","shell.execute_reply.started":"2024-04-25T23:21:13.761739Z","shell.execute_reply":"2024-04-25T23:21:13.78269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def remove_stopwords(sentence):\n    words = sentence.split()\n    words = [word for word in words if word not in stopwords.words('english')]\n    \n    return ' '.join(words)\n\n\ndef remove_html(sentence):\n    html = re.compile(r'<.*?>')\n    return html.sub(r'', sentence)\n\n\ndef clean_df(df):\n    df['long_answer'] = df['long_answer'].apply(lambda x : remove_stopwords(x))\n    df['long_answer'] = df['long_answer'].apply(lambda x : remove_html(x))\n\n    df['question'] = df['question'].apply(lambda x : remove_stopwords(x))\n    df['question'] = df['question'].apply(lambda x : remove_html(x))\n    \n    return df","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:21:49.260243Z","iopub.execute_input":"2024-04-25T23:21:49.260632Z","iopub.status.idle":"2024-04-25T23:21:49.26967Z","shell.execute_reply.started":"2024-04-25T23:21:49.260602Z","shell.execute_reply":"2024-04-25T23:21:49.268156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = clean_df(train_df)\nval_df = clean_df(val_df)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:25:00.681688Z","iopub.execute_input":"2024-04-25T23:25:00.682138Z","iopub.status.idle":"2024-04-25T23:26:06.132659Z","shell.execute_reply.started":"2024-04-25T23:25:00.682098Z","shell.execute_reply":"2024-04-25T23:26:06.131327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:26:11.349199Z","iopub.execute_input":"2024-04-25T23:26:11.349686Z","iopub.status.idle":"2024-04-25T23:26:11.360347Z","shell.execute_reply.started":"2024-04-25T23:26:11.349652Z","shell.execute_reply":"2024-04-25T23:26:11.359214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def define_tokenizer(df_series):\n    sentences = pd.concat(df_series)\n    \n    tokenizer = tf.keras.preprocessing.text.Tokenizer(\n        filters=FILTERS, \n        lower=LOWER_CASE\n    )\n    tokenizer.fit_on_texts(sentences)\n    \n    return tokenizer\n\n    \ndef encode(sentences, tokenizer):\n    encoded_sentences = tokenizer.texts_to_sequences(sentences)\n    \n    encoded_sentences = tf.keras.preprocessing.sequence.pad_sequences(\n        encoded_sentences, \n        padding='post',\n        maxlen=MAX_LEN\n    )\n    \n    return encoded_sentences","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:26:37.123365Z","iopub.execute_input":"2024-04-25T23:26:37.123718Z","iopub.status.idle":"2024-04-25T23:26:37.129726Z","shell.execute_reply.started":"2024-04-25T23:26:37.123693Z","shell.execute_reply":"2024-04-25T23:26:37.128822Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tokenizer = define_tokenizer([\n    train_df.long_answer, \n    train_df.question,\n    val_df.long_answer, \n    val_df.question\n])","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:26:49.403573Z","iopub.execute_input":"2024-04-25T23:26:49.403961Z","iopub.status.idle":"2024-04-25T23:26:50.147758Z","shell.execute_reply.started":"2024-04-25T23:26:49.403933Z","shell.execute_reply":"2024-04-25T23:26:50.146795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tokenizer.word_index['tracy']","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:27:04.09781Z","iopub.execute_input":"2024-04-25T23:27:04.098197Z","iopub.status.idle":"2024-04-25T23:27:04.105898Z","shell.execute_reply.started":"2024-04-25T23:27:04.098167Z","shell.execute_reply":"2024-04-25T23:27:04.104531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_long_answers = encode(train_df['long_answer'].values, tokenizer)\ntrain_questions = encode(train_df['question'].values, tokenizer)\n\nval_long_answers = encode(val_df['long_answer'].values, tokenizer)\nval_questions = encode(val_df['question'].values, tokenizer)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:27:16.838567Z","iopub.execute_input":"2024-04-25T23:27:16.838946Z","iopub.status.idle":"2024-04-25T23:27:17.427191Z","shell.execute_reply.started":"2024-04-25T23:27:16.838918Z","shell.execute_reply":"2024-04-25T23:27:17.426346Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_long_answers[0]","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:27:36.283327Z","iopub.execute_input":"2024-04-25T23:27:36.283704Z","iopub.status.idle":"2024-04-25T23:27:36.293262Z","shell.execute_reply.started":"2024-04-25T23:27:36.283676Z","shell.execute_reply":"2024-04-25T23:27:36.291993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels = train_df.is_long_answer.astype(int).values\nval_labels = val_df.is_long_answer.astype(int).values","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:27:48.263598Z","iopub.execute_input":"2024-04-25T23:27:48.263964Z","iopub.status.idle":"2024-04-25T23:27:48.270625Z","shell.execute_reply.started":"2024-04-25T23:27:48.263937Z","shell.execute_reply":"2024-04-25T23:27:48.269227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:27:56.624498Z","iopub.execute_input":"2024-04-25T23:27:56.625295Z","iopub.status.idle":"2024-04-25T23:27:56.632232Z","shell.execute_reply.started":"2024-04-25T23:27:56.625243Z","shell.execute_reply":"2024-04-25T23:27:56.631383Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"embedding_dict = {}\n\nwith open('../input/glove-global-vectors-for-word-representation/glove.6B.' + str(EMBED_SIZE) + 'd.txt','r') as f:\n    for line in f:\n        values = line.split()\n        word = values[0]\n        vectors = np.asarray(values[1:],'float32')\n        embedding_dict[word] = vectors\n        \nf.close()\n","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:31:19.966912Z","iopub.execute_input":"2024-04-25T23:31:19.967785Z","iopub.status.idle":"2024-04-25T23:31:31.978983Z","shell.execute_reply.started":"2024-04-25T23:31:19.967748Z","shell.execute_reply":"2024-04-25T23:31:31.977579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_words = len(tokenizer.word_index) + 1\nembedding_matrix = np.zeros((num_words, EMBED_SIZE))\n\nfor word, i in tokenizer.word_index.items():\n    if i > num_words:\n        continue\n    \n    emb_vec = embedding_dict.get(word)\n    \n    if emb_vec is not None:\n        embedding_matrix[i] = emb_vec","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:32:23.31929Z","iopub.execute_input":"2024-04-25T23:32:23.319686Z","iopub.status.idle":"2024-04-25T23:32:23.473628Z","shell.execute_reply.started":"2024-04-25T23:32:23.319648Z","shell.execute_reply":"2024-04-25T23:32:23.471215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"embedding = tf.keras.layers.Embedding(\n    len(tokenizer.word_index) + 1,\n    EMBED_SIZE,\n    embeddings_initializer = tf.keras.initializers.Constant(embedding_matrix),\n    trainable = False\n)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:32:33.730454Z","iopub.execute_input":"2024-04-25T23:32:33.730866Z","iopub.status.idle":"2024-04-25T23:32:33.742639Z","shell.execute_reply.started":"2024-04-25T23:32:33.730835Z","shell.execute_reply":"2024-04-25T23:32:33.741626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# question encoding\nquestion_input = Input(shape=(None,))\nquestion_x = embedding(question_input)\nquestion_x = SpatialDropout1D(0.2)(question_x)\nquestion_x = Bidirectional(LSTM(100, return_sequences=True))(question_x)\nquestion_x = GlobalMaxPooling1D()(question_x)\n\n# answer encoding\nanswer_input = Input(shape=(None,))\nanswer_x = embedding(answer_input)\nanswer_x = SpatialDropout1D(0.2)(answer_x)\nanswer_x = Bidirectional(LSTM(150, return_sequences=True))(answer_x)\nanswer_x = GlobalMaxPooling1D()(answer_x)\n\n# classification\ncombined_x = concatenate([question_x, answer_x])\ncombined_x = Dense(300, activation='relu')(combined_x)\ncombined_x = Dropout(0.5)(combined_x)\ncombined_x = Dense(300, activation='relu')(combined_x)\ncombined_x = Dropout(0.5)(combined_x)\noutput = Dense(1, activation='sigmoid')(combined_x)\n\n# combine model parts into one\nmodel = tf.keras.models.Model(inputs=[answer_input, question_input], outputs=output)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:32:47.003707Z","iopub.execute_input":"2024-04-25T23:32:47.004111Z","iopub.status.idle":"2024-04-25T23:32:47.33151Z","shell.execute_reply.started":"2024-04-25T23:32:47.004077Z","shell.execute_reply":"2024-04-25T23:32:47.330456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(\n    loss='binary_crossentropy', \n    optimizer='adam',\n    metrics=['BinaryAccuracy', 'Recall', 'Precision']\n)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:32:57.274525Z","iopub.execute_input":"2024-04-25T23:32:57.275972Z","iopub.status.idle":"2024-04-25T23:32:57.29316Z","shell.execute_reply.started":"2024-04-25T23:32:57.275925Z","shell.execute_reply":"2024-04-25T23:32:57.292037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"callbacks = [\n    tf.keras.callbacks.ReduceLROnPlateau(monitor='loss', patience=2, verbose=1),\n    tf.keras.callbacks.EarlyStopping(monitor='loss', patience=5, verbose=1),\n]","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:33:06.476221Z","iopub.execute_input":"2024-04-25T23:33:06.476635Z","iopub.status.idle":"2024-04-25T23:33:06.481683Z","shell.execute_reply.started":"2024-04-25T23:33:06.476603Z","shell.execute_reply":"2024-04-25T23:33:06.480779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(\n    x = [train_long_answers, train_questions], \n    y = train_labels,\n    validation_data = (\n        [val_long_answers, val_questions], \n        val_labels\n    ),\n    epochs = EPOCHS,\n    callbacks = callbacks,\n    class_weight = CLASS_WEIGHTS,\n    batch_size = BATCH_SIZE,\n    shuffle = True\n)","metadata":{"execution":{"iopub.status.busy":"2024-04-25T23:33:15.555928Z","iopub.execute_input":"2024-04-25T23:33:15.556337Z","iopub.status.idle":"2024-04-26T01:31:09.845317Z","shell.execute_reply.started":"2024-04-25T23:33:15.556301Z","shell.execute_reply":"2024-04-26T01:31:09.843956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Epochs: {0}'.format(\n    len(history.history['loss'])\n))","metadata":{"execution":{"iopub.status.busy":"2024-04-26T01:32:48.27818Z","iopub.execute_input":"2024-04-26T01:32:48.278603Z","iopub.status.idle":"2024-04-26T01:32:48.284091Z","shell.execute_reply.started":"2024-04-26T01:32:48.278571Z","shell.execute_reply":"2024-04-26T01:32:48.282988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"recall = history.history['Recall'][-1]\nprecision = history.history['Precision'][-1]\n\nprint('Train F1 score: {0:.4f}'.format(\n    2 * (precision * recall) / (precision + recall)\n))","metadata":{"execution":{"iopub.status.busy":"2024-04-26T01:33:42.612762Z","iopub.execute_input":"2024-04-26T01:33:42.613131Z","iopub.status.idle":"2024-04-26T01:33:42.619396Z","shell.execute_reply.started":"2024-04-26T01:33:42.613095Z","shell.execute_reply":"2024-04-26T01:33:42.618372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"recall = history.history['val_Recall'][-1]\nprecision = history.history['val_Precision'][-1]\n\nprint('Validation F1 score: {0:.4f}'.format(\n    2 * (precision * recall) / (precision + recall)\n))","metadata":{"execution":{"iopub.status.busy":"2024-04-26T01:34:28.186597Z","iopub.execute_input":"2024-04-26T01:34:28.187008Z","iopub.status.idle":"2024-04-26T01:34:28.194029Z","shell.execute_reply.started":"2024-04-26T01:34:28.186976Z","shell.execute_reply":"2024-04-26T01:34:28.19275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def test_question(question, positive, negative):\n    sentences = [question, positive, negative]\n    \n    for i in range(3):\n        sentences[i] = remove_stopwords(sentences[i])\n        sentences[i] = remove_html(sentences[i])\n    \n    sentences = encode(sentences, tokenizer)\n    \n    predictions = model.predict(\n        [np.expand_dims(sentences[1], axis=0), np.expand_dims(sentences[0], axis=0)]\n    )\n\n    print('Positive: {0:.2f}'.format(predictions[0][0]))\n\n    predictions = model.predict(\n        [np.expand_dims(sentences[2], axis=0), np.expand_dims(sentences[0], axis=0)]\n    )\n\n    print('Negative: {0:.2f}'.format(predictions[0][0]))","metadata":{"execution":{"iopub.status.busy":"2024-04-26T01:34:58.34944Z","iopub.execute_input":"2024-04-26T01:34:58.349818Z","iopub.status.idle":"2024-04-26T01:34:58.359177Z","shell.execute_reply.started":"2024-04-26T01:34:58.34979Z","shell.execute_reply":"2024-04-26T01:34:58.358079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"question = 'which is the most common use of opt-in e-mail marketing'\n\npositive = \"<P> A common example of permission marketing is a newsletter sent to an advertising firm 's customers . Such newsletters inform customers of upcoming events or promotions , or new products . In this type of advertising , a company that wants to send a newsletter to their customers may ask them at the point of purchase if they would like to receive the newsletter . </P>\"\n\nnegative = '<P> Email marketing has evolved rapidly alongside the technological growth of the 21st century . Prior to this growth , when emails were novelties to the majority of customers , email marketing was not as effective . In 1978 , Gary Thuerk of Digital Equipment Corporation ( DEC ) sent out the first mass email to approximately 400 potential clients via the Advanced Research Projects Agency Network ( ARPANET ) . This email resulted in $13 million worth of sales in DEC products , and highlighted the potential of marketing through mass emails . However , as email marketing developed as an effective means of direct communication , users began blocking out content from emails with filters and blocking programs . In order to effectively communicate a message through email , marketers had to develop a way of pushing content through to the end user , without being cut out by automatic filters and spam removing software . This resulted in the birth of triggered marketing emails , which are sent to specific users based on their tracked online browsing patterns . </P>'","metadata":{"execution":{"iopub.status.busy":"2024-04-26T01:35:25.425663Z","iopub.execute_input":"2024-04-26T01:35:25.42607Z","iopub.status.idle":"2024-04-26T01:35:25.432521Z","shell.execute_reply.started":"2024-04-26T01:35:25.426041Z","shell.execute_reply":"2024-04-26T01:35:25.431349Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_question(question, positive, negative)","metadata":{"execution":{"iopub.status.busy":"2024-04-26T01:35:35.24174Z","iopub.execute_input":"2024-04-26T01:35:35.242133Z","iopub.status.idle":"2024-04-26T01:35:36.317834Z","shell.execute_reply.started":"2024-04-26T01:35:35.242103Z","shell.execute_reply":"2024-04-26T01:35:36.316856Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"question = 'how i.met your mother who is the mother'\n\npositive = \"<P> Tracy McConnell , better known as `` The Mother '' , is the title character from the CBS television sitcom How I Met Your Mother . The show , narrated by Future Ted , tells the story of how Ted Mosby met The Mother . Tracy McConnell appears in 8 episodes from `` Lucky Penny '' to `` The Time Travelers '' as an unseen character ; she was first seen fully in `` Something New '' and was promoted to a main character in season 9 . The Mother is played by Cristin Milioti . </P>\"\n\nnegative = \"<P> In `` Bass Player Wanted '' , the Mother picks up a hitchhiking Marshall , carrying his son Marvin , on her way to Farhampton Inn . On their way , it is revealed that the Mother is a bass player in the band , that is scheduled to play at the wedding reception . But the band 's leader , Darren , forced her to quit . The Mother ultimately decides to confront Darren and retake the band . She ends up alone at the bar , and while practicing a speech to give Darren , Darren walks up to her furious the groom 's best man punched him for `` no reason . '' Amused by this , the Mother laughs , and Darren quits the band in anger . </P>\"","metadata":{"execution":{"iopub.status.busy":"2024-04-26T01:36:04.43036Z","iopub.execute_input":"2024-04-26T01:36:04.43071Z","iopub.status.idle":"2024-04-26T01:36:04.436234Z","shell.execute_reply.started":"2024-04-26T01:36:04.430684Z","shell.execute_reply":"2024-04-26T01:36:04.435026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_question(question, positive, negative)","metadata":{"execution":{"iopub.status.busy":"2024-04-26T01:36:11.829276Z","iopub.execute_input":"2024-04-26T01:36:11.829675Z","iopub.status.idle":"2024-04-26T01:36:12.192593Z","shell.execute_reply.started":"2024-04-26T01:36:11.82964Z","shell.execute_reply":"2024-04-26T01:36:12.191564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"question = 'how i met your mother who is the mother'\ntest_question(question, positive, negative)","metadata":{"execution":{"iopub.status.busy":"2024-04-26T01:36:28.109611Z","iopub.execute_input":"2024-04-26T01:36:28.110013Z","iopub.status.idle":"2024-04-26T01:36:28.465898Z","shell.execute_reply.started":"2024-04-26T01:36:28.109978Z","shell.execute_reply":"2024-04-26T01:36:28.464876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"question = 'who is tracy mcconnell'\ntest_question(question, positive, negative)","metadata":{"execution":{"iopub.status.busy":"2024-04-26T01:36:38.174524Z","iopub.execute_input":"2024-04-26T01:36:38.174913Z","iopub.status.idle":"2024-04-26T01:36:38.508597Z","shell.execute_reply.started":"2024-04-26T01:36:38.174884Z","shell.execute_reply":"2024-04-26T01:36:38.507196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}