avatarKathy Parker

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

4588

Abstract

on't know, don't try to make up an answer. """</span>

<span class="hljs-comment"># Prepend context if used</span>
<span class="hljs-keyword">if</span> context != <span class="hljs-string">""</span>:
    question = <span class="hljs-string">"Use the following context to answer the users question:\n```\n"</span> + context + <span class="hljs-string">"\n```\n\n"</span> + question

response = openai.ChatCompletion.create(
    engine=<span class="hljs-string">"gpt-35-turbo"</span>,
    messages = [{<span class="hljs-string">"role"</span>:<span class="hljs-string">"system"</span>,<span class="hljs-string">"content"</span>:system},{<span class="hljs-string">"role"</span>:<span class="hljs-string">"user"</span>,<span class="hljs-string">"content"</span>:question}],
    temperature=<span class="hljs-number">0.0</span>,
    max_tokens=<span class="hljs-number">500</span>,
    top_p=<span class="hljs-number">0.95</span>,
    frequency_penalty=<span class="hljs-number">0</span>,
    presence_penalty=<span class="hljs-number">0</span>,
    stop=<span class="hljs-literal">None</span>)
    
<span class="hljs-keyword">return</span> response[<span class="hljs-string">'choices'</span>][<span class="hljs-number">0</span>][<span class="hljs-string">'message'</span>][<span class="hljs-string">'content'</span>]</pre></div><p id="212c">This first one, <code>ask</code> is simply a wrapper to calling OpenAI GPT 3.5. Turbo, including a System Prompt about looking through research papers. It also accepts a <code>context</code>variable which is included in the prompt as necessary.</p><div id="6164"><pre><span class="hljs-keyword">def</span> <span class="hljs-title function_">extract_section</span>(<span class="hljs-params">documents, section_name, debug=<span class="hljs-literal">False</span></span>):
section_page = <span class="hljs-string">""</span>
section_text = <span class="hljs-string">""</span>

<span class="hljs-keyword">for</span> idx, page <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(documents):
    <span class="hljs-keyword">if</span> section_text == <span class="hljs-string">""</span> <span class="hljs-keyword">and</span> section_name <span class="hljs-keyword">in</span> page.text.lower():
        <span class="hljs-keyword">if</span> debug: <span class="hljs-built_in">print</span>(idx)

        context = page.text
        <span class="hljs-keyword">if</span> idx &lt; <span class="hljs-built_in">len</span>(documents)-<span class="hljs-number">2</span>:
            context += <span class="hljs-string">"\n"</span> + documents[idx+<span class="hljs-number">1</span>].text
            context += <span class="hljs-string">"\n"</span> + documents[idx+<span class="hljs-number">2</span>].text

        answer = ask(<span class="hljs-string">f"Does the above have the section called '<span class="hljs-subst">{section_name}</span>' or similar, and does it, in detail, explain the <span class="hljs-subst">{section_name}</span>?"</span>, context)
        <span class="hljs-keyword">if</span> answer.startswith(<span class="hljs-string">"Yes"</span>):
            answer = ask(<span class="hljs-string">f"\n-----\nWhat is the <span class="hljs-subst">{section_name}</span> in the document? Return everything in this section, up to the next heading. Do not interpret it, give me the verbatim text."</span>, context)
            <span class="hljs-keyword">if</span> debug: <span class="hljs-built_in">print</span>(answer + <span class="hljs-string">"\n----------"</span>)
            section_page = idx + <span class="hljs-number">1</span>
            section_text = answer
            <span class="hljs-keyword">if</span> debug: <span class="hljs-built_in">print</span>(section_page, section_text, validate)

<span class="hljs-keyword">return</span> section_text, section_page</pre></div><p id="f08f">In the <code>extract_section</code>function, we do a couple of things:</p><ol><li>We use the <code>section_name</code>we pass in to do a really simple check. We iterate through all pages in the document and see if the text in <code>section_name</code>exists in the lower case version of the page</li><li>If it does, it uses that page and the two subsequent pages and pass them into a couple of LLM prompts to see if it has a section named <code>section_name</code> and if so, it extracts the section verbatim</li><li>Returns a tuple of the the section text, and the page it which it was found</li></ol><p i

Options

d="5b9a">Of course, this is a one time activity. In reality this would be used and ran to extract the relevant sections and cache them for future use.</p><p id="eede">So let’s first start to build up a <code>sections</code>variable. For the first section I am actually going to cheat a little and not use <code>extract_section</code>function because the section I want, <code>authors</code>does not have a section heading, so we just use the <code>ask</code>function and pass in the first page of the document.</p><div id="0aa4"><pre>sections = {}

sections[<span class="hljs-string">"authors"</span>] = (ask(<span class="hljs-string">"Who are the authors mentioned before the abstract"</span>, documents[<span class="hljs-number">0</span>].text), <span class="hljs-number">1</span>) sections[<span class="hljs-string">"authors"</span>]</pre></div><figure id="2fc0"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*iXz3LsCIKxj0qAHG2IV0bQ.png"><figcaption></figcaption></figure><p id="3aa2">OK that looks good. now let’s use the <code>extract_section</code>function to extract the <code>abstract</code>section.</p><div id="c468"><pre>sections[<span class="hljs-string">"abstract"</span>] = extract_section(documents, <span class="hljs-string">"abstract"</span>) sections[<span class="hljs-string">"abstract"</span>]</pre></div><figure id="4c09"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*AaGiiD9HRReA34Laz6ODCw.png"><figcaption></figcaption></figure><p id="e4af">OK so lets see if what we’ve done is of any use.</p><p id="9052">First let’s look at what license is applicable to this. We’ll start with the Llama Index search:</p><div id="601a"><pre>%%<span class="hljs-built_in">time</span>

query = <span class="hljs-string">'What licenses are mentioned?'</span> <span class="hljs-built_in">print</span>(query) answer = query_engine.query(query) <span class="hljs-built_in">print</span>(answer.response)</pre></div><figure id="5b74"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*LjefM-QYa773vVlv_M9JVg.png"><figcaption></figcaption></figure><p id="f59c">Oh that's a little disappointing. It couldn't find anything.</p><p id="67c9">What about if we use just the abstract section.</p><div id="c085"><pre>%%time

ask(query, sections[<span class="hljs-string">"abstract"</span>][<span class="hljs-number">0</span>])</pre></div><figure id="3cee"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*QqBO27pBanGBmPf-89Sz-w.png"><figcaption></figcaption></figure><p id="ebe0">That looks good. Not only did it get the right answer, it was also quicker because we only use the section of interest in the prompt, and not the k chunks that the semantic search thought would be relevant.</p><p id="ef28">OK another quick check. Let’s ask a question about an author. This author was responsible for one of the papers in the References, but not actually an author of this paper. So asking if they are an author of this paper should say no, right?</p><div id="ae97"><pre>%%<span class="hljs-built_in">time</span>

query = <span class="hljs-string">'Is Jacob Austin an author of this paper?'</span> <span class="hljs-built_in">print</span>(query) answer = query_engine.query(query) <span class="hljs-built_in">print</span>(answer.response)</pre></div><figure id="8ee4"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*2Bvv0A6CRjdrd-SbEVil9Q.png"><figcaption></figcaption></figure><p id="a977">OK well that’s a little odd. It thinks he was an author of this paper, And it thinks that because the semantic search found him as an author, but not distinguished it as being a paper in the reference and not the paper itself.</p><p id="f0a0">What about using the sections specifically?</p><div id="2ffe"><pre>%%time

ask(query, sections[<span class="hljs-string">"authors"</span>][<span class="hljs-number">0</span>])</pre></div><figure id="5d52"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*JdCeCo313dTBVHVmAL0HqQ.png"><figcaption></figcaption></figure><p id="a781">Well yes of course that it would work and recognise he is not an author of this paper. And of course it’s quicker because we only use the section of interest in the prompt, and not the k chunks that the semantic search thought would be relevant.</p><p id="5ce2">I personally use this approach a fair bit. I’m not saying it’s better. I’m saying it’s simpler. More Balanced. An alternate approach and another tool in your arsenal.</p><p id="dfff">So, how about it? KISS and BRAG?</p><p id="4a3a">Thanks for reading.</p></article></body>

I Have Been a Mother for Twenty Years — Here’s What Nobody Told Me

I can say now that being a mother has been the best thing I have ever done. But I couldn’t always have said that.

Photo by Tamara Bellis on Unsplash

I was twenty-one years-old when my first son entered the world.

He came early; two weeks before his expected date and with such haste the midwife delivered him before the doctor made an appearance. After him, there were three more — my second son and two daughters, all within six years, all with their own birth stories, their own personalities, their own idiosyncrasies that make them unmistakably who they are — vastly different from one another despite being raised so symmetrically.

I hadn’t planned on having my first child so soon; life had chosen otherwise. Though married, I was young. In hindsight, too young. But I was determined to be prepared. I read pregnancy books, birthing books, parenting books. I was prepared for the ways my body would change. I was prepared for the ways my life would change.

But I wasn’t prepared for the ways I would change.

I can say now that being a mother has been the best thing I have ever done, the best part of who I am. But I couldn’t always have said that. I glance back to those early days and my fingers slip through the faded recollection of how difficult they actually were — a decade that passed by through a filter of exhaustion and loneliness.

There were so many days I struggled for air, so many days I wept for the village that was nowhere to be found; moreover, wept for the woman I once was, also nowhere to be found. I grieved for her — the responsibilities and obligations of motherhood had taken her from me and in her place stood a foreigner, a woman I no longer recognised or wanted to be.

I hadn’t expected to feel such a loss of my own identity, to become so desolate in the abyss of who I used to be and who I had yet to become. I hadn’t expected to feel so unanchored, so adrift, so alone. Once extroverted, confident and capable, I soon found myself flailing helplessly in an ocean of my own inadequacies.

We lived on a 2500-acre farm in rural South Australia, aka the middle of nowhere, or so it seemed. I had no family close by, no support network to turn to. While my friends undertook university courses, careers and travel, I no longer even seemed capable to leave the house without deteriorating into a mire of irrational anxiety. Exhausted, burnt out, worn out, I lost my confidence, my capabilities, my ambition, my passion — and most days it appeared — my mind, too.

It wasn’t an issue of love; a woman’s heart will never beat with such fierceness as for that which she has created within herself. It was the belief that because I loved my children, I should love being a mother. But I didn’t. All I felt was the loneliness, the isolation, the invisibility, the loss of self, the ambivalence, the exhaustion, the guilt, the shame of all I lacked.

Every night I would collapse into bed, overcome with guilt that I couldn’t be what they needed me to be, that I wasn’t as capable as other mothers, that I wasn’t enough. I would lie awake, despondent, reciting promises in my head: tomorrow I will try harder, tomorrow I will do better. But always, they fell short. Always, I fell short.

I wasn’t prepared for those feelings, for the mental and emotional upheaval that came with being a mother. These were the things not written in books, the things nobody speaks of because we’re all too busy being ashamed of our scarcity, too worried everything we feel is wrong, too afraid of being judged by those we compare ourselves to. When little do we know, they too stand inside the valley of their own inadequacies and break apart for how short they believe they fall in their comparison to us.

This year I will celebrate my twentieth Mother’s Day. It has taken me this long to find the joy in being a mother. To no longer wake each morning to the words — this too shall pass — scrawled on sticky-notes on my bathroom mirror. To love and appreciate all my children bring to my life. To understand what it means to hold, first in my womb and now in my arms, the next generation — a generation I have been given the privilege to teach of compassion, tolerance, respect, kindness, goodness, love. A generation of world-changers.

It’s taken twenty years to understand that being a mother is not something we are, but something we become.

As we watch our children grow and learn from us, likewise, we grow and learn from them. They awaken us; force us to pay attention as we tread upon unsure ground, help us find our footing and become decided in our steps even when we walk in darkness.

They soften our hard edges as they teach us of patience, sacrifice and unconditional love. They help us forgive our own humanity through the grace we offer theirs. They show us what it means to love as a result of the love they give to us, even when we are undeserving of such a profuse gift — especially when we are undeserving of such a profuse gift — and because of that, we are found better.

There is no way, twenty years ago, I could have been prepared for the ways being a mother would change me.

But nor could I have ever been prepared for the way my children would become the most beautiful part of everything I am today.

Like my articles? Subscribe here to have them delivered straight to your inbox.

Similar articles:

Mothers Day
Motherhood
Women
Parenting
Self-awareness
Recommended from ReadMedium