<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yogeshwar Vishwanath on Medium]]></title>
        <description><![CDATA[Stories by Yogeshwar Vishwanath on Medium]]></description>
        <link>https://medium.com/@yogeshwar.vishwanath?source=rss-6873049e89bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Yogeshwar Vishwanath on Medium</title>
            <link>https://medium.com/@yogeshwar.vishwanath?source=rss-6873049e89bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 19:20:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yogeshwar.vishwanath/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Fine-Tuning Closed Domain Question Answering using GPT-3 without explicitly mentioning answers]]></title>
            <link>https://medium.com/digital-engineering-centific/fine-tuning-closed-domain-question-answering-using-gpt-3-without-explicitly-mentioning-answers-929c1bce990d?source=rss-6873049e89bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/929c1bce990d</guid>
            <dc:creator><![CDATA[Yogeshwar Vishwanath]]></dc:creator>
            <pubDate>Wed, 05 Apr 2023 15:39:32 GMT</pubDate>
            <atom:updated>2023-04-05T15:39:32.236Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome to the blog where we will be discussing our experiment on Fine-Tuning Closed Domain Question and Answering using GPT-3. Question answering systems have become an integral part of knowledge-based systems, and they are designed to understand natural language queries and provide relevant answers. The implementation of such systems depends on three crucial elements: the available data, the range of questions it can handle, and the data structure format: Question, Answer and Context.</p><p>In this blog, we will explore how to implement GPT-3 fine-tuning for Closed Domain Question and Answering without explicitly mentioning answers. The process is simplified into four steps, making it an easy task to achieve. Unlike traditional models, which require the explicit mention of answers, GPT-3 fine-tuning experiment does not need answers to be mentioned explicitly. Let’s dive in and learn more!</p><p>The following table compares the format of traditional Question Answering Models with that of the GPT-3 Question Answering Fine-Tuning experiment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*sqsBwYQMpg-ioAbI_tUIlw.png" /><figcaption><strong>Table:1 Comparison between Question Answering Models and GPT-3 Question Answering Fine-Tuning</strong></figcaption></figure><p>In the context of question answering models, one major drawback of BERT-based models is that the user must provide the relevant context along with the question to retrieve answers. In certain real-world applications, it may not be feasible to provide context with every question. On the other hand, with GPT-3 fine-tuning, there is no requirement to provide explicit context while retrieving answers once fine-tuned.</p><p><strong>Manipulating GPT-3 — Utilizing Question/Context Pairs Instead of Question/Answer Pairs:</strong></p><p>Our GPT-3 fine-Tuning experiment explores a novel technique of manipulating the model by incorporating question/context pairs instead of the traditional question/answer pairs. In the GPT-3 framework, the question is referred to as the “prompt,” and the context/answer is known as the “completion.” By implementing this approach, there’s no requirement to explicitly specify the answers, as the model generates the response based on the given context. To retrieve concise responses, specific parameters such as ‘stop=[“\n”]’ and max_tokens=’100&#39; can be utilized. This technique can prove incredibly valuable in certain scenarios and is certainly worth exploring to optimize your question answering tasks. This approach can potentially save time, money as it eliminates the need for an expert to prepare explicit answers.</p><p><strong>Using Open Domain Data for Representation in Closed Domain Contexts:</strong></p><p>When working with confidential closed domain contexts, such as official data that should not be accessed by individuals outside of your team, maintaining strict confidentiality is crucial. However, in our experiment, we will be using open domain health-related data and its context as a substitute for closed domain data.</p><p><strong>Sample Questions and Contexts</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1LLKna0RVCdxwboxiIJgZw.png" /><figcaption><strong>Table 2: Sample Questions and Contexts</strong></figcaption></figure><p>It is possible for multiple questions to have the answer within a given context.</p><p><strong>Input Data Format for Fine-Tuning:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*Efb3UwEYGuEdkdo4kV6UFg.png" /><figcaption><strong>Table 3: Sample Questions and Contexts Reformatted</strong></figcaption></figure><p>Here in the above example, we are using the concept of using the same context/completion for multiple questions/prompts. The idea is to provide the complete data to the model and allow the GPT-3 Davinci model to intelligently retrieve appropriate answers from the context. This approach can be a time-saving and efficient way to generate accurate answers to a variety of questions and feeding the closed domain context.</p><p>Obtaining an OpenAI API key is a prerequisite, and you can generate it by registering through the <a href="https://platform.openai.com/account/api-keys">OpenAI </a>website:</p><h3>Steps for Fine-tuning on custom Closed Domain Data:</h3><p><strong>Step 1 — Setting Up environment</strong></p><pre>#!pip install --upgrade openai<br>import os<br>import openai<br><br>os.chdir(r&#39;C:\Users\yogeshwarv\Desktop\OpenAI&#39;)<br><br>os.environ[&quot;OPENAI_API_KEY&quot;] = &quot;#############################################&quot;<br>openai.api_key = os.getenv(&quot;OPENAI_API_KEY&quot;)</pre><p>It’s worth noting that the OpenAI documentation recommends using the command “<strong>export OPENAI_API_KEY=”&lt;OPENAI_API_KEY&gt;</strong>” to set the API key, but it may not be executed successfully. Therefore, we suggest using the code snippet mentioned above instead.</p><p><strong>Step 2 — Preparing Data:</strong></p><pre>import pandas as pd<br>import json<br><br># Read the Excel file into a pandas DataFrame<br>df = pd.read_excel(r&quot;C:\Users\yogeshwarv\OpenAI\QnContextpairs.xlsx&quot;)<br><br><br># Open the JSONL file for writing<br>#Make sure the Questions header named &#39;prompts&#39; and &#39;context&#39; has header named &#39;completion&#39;<br>with open(r&quot;C:\Users\yogeshwarv\OpenAI\QnContextpairs.jsonl&quot;, mode=&#39;w&#39;) as jsonl_file:<br>    # Iterate over each row in the DataFrame<br>    for index, row in df.iterrows():<br>        # Create a dictionary with the question and answer fields<br>        qa_dict = {&#39;prompt&#39;: row[&#39;prompt&#39;], &#39;completion&#39;: row[&#39;completion&#39;]}<br>        <br>        # Write the dictionary as a JSON object to the JSONL file<br>        jsonl_file.write(json.dumps(qa_dict) + &#39;\n&#39;)</pre><p><strong>Note:</strong> Make sure the Questions header named ‘prompts’ and ‘context’ has header named ‘completion’.</p><p>The OpenAI documentation suggests using the command “<strong>openai tools fine_tunes.prepare_data -f &lt;LOCAL_FILE&gt;”</strong> to prepare the data, but it may not be executed successfully. As we’ve observed, this code doesn’t format data correctly in most cases. Therefore, we recommend using the code snippet mentioned above.</p><p><strong>Step 3 — Custom Fine-Tuning:</strong></p><pre>!openai api fine_tunes.create -t QnContextpairs.jsonl -m davinci<br># As we re running the code in notebook it is important to use &quot;!&quot; else you might encounter error.<br># </pre><p>“-m Davinci” represents the base model on top of which we are fine-tuning</p><p>Once we run the above code the result can be as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*5dvU9g4Ps1e8jMTiAjB0dw.png" /></figure><p>If the stream is interrupted, the feedback will suggest to re-run the finetuning with suggested code</p><p>You might require to run the code multiple time until following feedback is received.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*qCRdRq_TgzDAQBx1GZkF0Q.png" /></figure><p><strong>Step 4 — Retrieving Answers from fine-tuned model:</strong></p><pre>response = openai.Completion.create(<br>    model=&#39;davinci:ft-*******-*****-***-**-**-**-**&#39;,<br>    prompt=prompt,<br>    max_tokens=40,<br>    top_p=1,<br>    frequency_penalty=1,<br>    presence_penalty=1,<br>    stop=[&quot;\n&quot;]<br>)<br><br>print(&#39;*************************************&#39;)<br>print(&#39;Question: &#39;,prompt)<br>print(&#39;Bot Answer: &#39;response1.choices[0].text)</pre><p><strong>· </strong>Make sure to replace appropriate Model name which is generated in step-3, which is mentioned as “Uploaded Model”.</p><p><strong>· </strong>It is important to note that we are utilizing a max_tokens value of 40 and a stop value of ‘\n’ to obtain relevant answers, even when answers are not explicitly provided during training.</p><p><strong>Performance of Training in an Experiment Using a Closed-Domain Data Set:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*2vigZ0e3If0Gq2OYoFr96Q.png" /><figcaption><strong>Fig: Training Evaluation</strong></figcaption></figure><p>In order to evaluate the performance of such an experiment, two important metrics are often used: Training Sequence Accuracy and Training Token Accuracy. These metrics play a vital role in comparing various experiments and establishing a benchmark for future work.</p><p>However, relying solely on these metrics can be misleading. It’s important to validate the actual answers produced by the model by thoroughly examining them to ensure that they make sense. Simply achieving a high Training Sequence Accuracy or Training Token Accuracy doesn’t necessarily mean that the model is performing well in real-world scenarios.</p><p>To validate the answers produced by the model, it’s important to manually review a sample of the responses and ensure that they align with the expectations. This step ensures that the model is not simply memorizing the training data, but is capable of producing accurate responses to new inputs.</p><p><strong>Sample Answers retrieved from fine-tuned Model:</strong></p><p><strong>Question 1: </strong>What is diabetes?</p><p><strong>Bot Answer: </strong>Diabetes is a chronic condition that affects how your body processes blood sugar (glucose).</p><p><strong>Question 2:</strong> How does diabetes affect the body?</p><p><strong>Bot Answer:</strong> When there’s too much glucose in your blood, it can cause serious health problems.</p><p><strong>Question 3: </strong>What are the two types of diabetes?</p><p><strong>Bot Answer:</strong> Diabetes is divided into two types: type 1 and type 2.</p><p><strong>Question 4: </strong>When is type 1 diabetes usually diagnosed?</p><p><strong>Bot Answer:</strong> Type 1 diabetes is usually diagnosed in childhood.</p><p>Following snippet will help to evaluate on Test Data.</p><pre>openai api fine_tunes.create -t &lt;TRAIN_FILE_ID_OR_PATH&gt; \<br>  -v &lt;VALIDATION_FILE_ID_OR_PATH&gt; \<br>  -m &lt;MODEL&gt;</pre><p>Based on our experience, we were unable to successfully implement the above code. As a result, we relied on training evaluation as a reference.</p><h3><strong>Summary Closed Domain Data Fine-Tuning Experiment:</strong></h3><p>In the Closed Domain Data experiments, 212 examples of Question and Context pairs were used to train and evaluate a model. The training process was run for 800 steps and the training token accuracy was satisfactory. In conclusion, the closed domain data experiment demonstrated the potential of using GPT-3 fine-tuned models for closed domain question answering without explicitly providing answers. By using question/context pairs instead of question/answer pairs, the model was able to produce accurate and relevant answers with proper sentence formation and exact snippets of answers. The results showed that the GPT-3 fine-tuned model outperformed the Bert-based Question Answering model and required less training time. Overall, this approach has the potential to be useful in various scenarios to improve accuracy and efficiency in generating answers for closed domain contexts.</p><p><strong>Reference:</strong></p><p><a href="https://platform.openai.com/docs/guides/fine-tuning">https://platform.openai.com/docs/guides/fine-tuning</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=929c1bce990d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/digital-engineering-centific/fine-tuning-closed-domain-question-answering-using-gpt-3-without-explicitly-mentioning-answers-929c1bce990d">Fine-Tuning Closed Domain Question Answering using GPT-3 without explicitly mentioning answers</a> was originally published in <a href="https://medium.com/digital-engineering-centific">Digital Engineering @ Centific</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BerTopic Modelling -Advanced Topic Modelling:]]></title>
            <link>https://medium.com/digital-engineering-centific/bertopic-modelling-advanced-topic-modelling-73af7697b7f3?source=rss-6873049e89bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/73af7697b7f3</guid>
            <category><![CDATA[comparisions]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[topic-modeling]]></category>
            <category><![CDATA[bertopic]]></category>
            <dc:creator><![CDATA[Yogeshwar Vishwanath]]></dc:creator>
            <pubDate>Tue, 14 Mar 2023 14:37:59 GMT</pubDate>
            <atom:updated>2023-03-14T14:37:59.592Z</atom:updated>
            <content:encoded><![CDATA[<p>Because of their interpretability, so-called topic models, which come from the field of natural language processing, have attracted a lot of attention recently. Topic-modelling is a powerful tool for understanding the hidden structure in a text corpus. By automatically identifying the main topics in a collection of documents, topic models can help us make sense of large and complex data sets.</p><p>One of the main challenges when dealing with a large collection of documents is categorizing them into different groups based on their content. This can be time-consuming and difficult to do manually. However, by using topic modelling, it is possible to automatically identify the main topics and themes in the documents, which can then be used to label and categorize them accordingly.</p><p>It has many practical applications, from document categorization and sentiment analysis to trend analysis, content recommendation, and information retrieval. For instance, sentiment analysis, which involves analysing the sentiment of many customer reviews or social media posts. This can be challenging due to the sheer volume of data to be analysed. However, topic modelling can help identify the main themes and topics in the text, which can then be used to gauge the overall sentiment of the text. Trend analysis is another area where topic modelling can be useful. Tracking trends and changes in a particular domain or industry can be difficult when dealing with large volumes of data. However, by using topic modelling to identify the main topics and themes that are emerging over time, it is possible to track changes and identify new trends.</p><p>Unlike clustering, which groups documents together based on similarity, topic modelling generates clusters of words instead of documents, making it a method for unsupervised classification of documents. These word-based clusters can then be used to label new documents according to the topics they contain.</p><p>Most importantly will discuss some of the topic modelling techniques and Advance topic modelling known as BERTopic modelling that is more effective than others.</p><p><strong>A Typical Topic Modelling Architecture:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*6Vay36NI-AFiZ7TrOdRyNw.png" /><figcaption><strong>Fig 1: Topic Modelling Architecture</strong></figcaption></figure><p><strong>Different Topic Modelling Techniques:</strong></p><p>There are four major topic modelling techniques namely Latent Dirichlet Allocation (LDA), Latent Semantic Analysis (LSA), non-negative matrix factorization (NMF), Top2Vec.</p><p>· One of the most often used topic modelling methods is Latent Dirichlet Allocation (LDA). It is founded on the notion that each text is composed of a variety of subjects, and that each word in the document is related to one of those topics. These subjects and the words associated with them can be discovered using LDA.</p><p>· Latent Semantic Analysis, or LSA assumes that words that are close together in meaning will also be close together in terms of their distributional properties (i.e., their co-occurrence patterns with other words) and are made up of a variety of themes. This algorithm helps to reduce the dimensionality of the data while preserving as much of the original information as possible.</p><p>· Non-negative matrix factorization (NMF) based on the idea that data can be represented as a matrix, and that this matrix can be decomposed into two smaller matrices. The first matrix represents the topics, and the second matrix represents the documents. First, they all start with an initial guess of the two matrices (the topics and documents). Then they iteratively update these matrices until they converge on a good solution</p><p>· Top2Vec is a topic modelling algorithm that uses word embeddings (also known as vector space models) to improve the quality of the generated topics. Word embeddings are mathematical representations of words that capture relationships between them. By using word embeddings, Top2Vec can group together semantically similar words (e.g., car and automobile) and produce more accurate topics than traditional methods that rely on bag-of-words representations.</p><p>However, these techniques do have limitations. The results can be difficult to interpret due to many generated topics, and the computations can be intensive when working with large datasets. Additionally, the assumption that documents are a mixture of topics can sometimes lead to poor results. Despite these challenges, topic modelling continues to be a valuable tool for understanding hidden structures in text corpora.</p><p>· BERTopic is an advance topic modelling technique that leverages BERT embeddings and c-TF-IDF to create dense clusters allowing for easily interpretable topics whilst keeping important words in the topic descriptions also helps to visualize the topics generated. In other words, BERTopic extends clustering process by extracting coherent topic representation through the development of a class-based variation of TF-IDF.</p><p><strong>Comparison on Advantages and Disadvantages of Topic Modelling Techniques:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*8-fHlV_5oCRVK1_tfe82Cw.png" /><figcaption><strong>Table 1: Advantages and Disadvantages</strong></figcaption></figure><p>BERTopic constitutes main steps, namely the embedding of documents, the clustering of documents, the topic extraction, and the topic diversification</p><p><strong>BERTopic Architecture:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*SYZKlvevqW0yjTw9As8-ww.png" /><figcaption><strong>Fig 2: BERTopic Architecture:</strong></figcaption></figure><ol><li><strong>Documents Embedding:</strong></li></ol><p>Documents must initially be transformed into numerical representations. Although there are other ways to accomplish this, sentence-transformers are preferably employed as default embedding in BERTopic.</p><p><strong>2. Dimensionality reduction</strong></p><p>Dimensionality reduction of the embeddings is the next crucial component of BERTopic. Since UMAP can capture both the local and global high-dimensional space in smaller dimensions, UMAP is usually employed in BERTopic. However, there are alternative options available, such PCA and Truncated SVD.</p><p><strong>3. Clustering</strong></p><p>To extract topics, we must first reduce the dimensionality of our input embeddings and then group them into collections of related embeddings. The more effective our clustering approach is, the more precise our topic representations are therefore this clustering procedure is quite significant. You might wish to use k-Means instead than HDBSCAN even though it does well in BERTopic and is often recommended.</p><p><strong>4. Bag-of-Words:</strong></p><p>Approach for topic representation that has minimal to no expectations on the cluster’s intended structure is preferable. To achieve this, we first merge all the papers in a cluster into one document. Documents which are length in nature are then used to depict the cluster. After that, we can determine how frequently each word appears in each cluster. The frequency of each word in each cluster is contained in a representation known as a “bag of words” that is produced as a result. Because of this, the bag-of-words representation is on the cluster level rather than the document level.</p><p><strong>5. Topic Representation</strong></p><p>In the topic modelling we want to one cluster different from another. To address this, classical TF-IDF which is intended to reflect how important a word is to a <a href="https://en.wikipedia.org/wiki/Document">document</a> is tweaked such that it considers topics (i.e., clusters) instead of documents. This modified TF-IDF representation, known as c-TF-IDF, analyses what differentiates the documents in one cluster from those in another cluster. Each cluster is converted to a single document instead of a set of documents. Then, we extract the frequency of word x in class c, where c refers to the cluster we created before. This results in our class-based tf representation. This representation is L1-normalized to account for the differences in topic sizes.</p><p>The Main advantage of BERTopic is that it not only allocates clusters precisely but also give topic names suggestions based on clusters. BERT-based topic modelling does not require the number of topics to be specified in advance. However, it is still important to define a range of possible topics to guide the topic modelling process. Furthermore, Once the BERTopic model is trained, it is important to evaluate the quality of the topics generated. This can be done by examining the coherence and interpretability of the topics, as well as their ability to capture the main themes in the text data.</p><p>In summary, topic modelling is a versatile and powerful technique that can be used in many different applications, from document categorization and sentiment analysis to trend analysis, content recommendation, and information retrieval. By identifying the main topics and themes present in a collection of texts, it is possible to gain valuable insights into the data and improve many different aspects of text analysis and processing.</p><p><strong>References:</strong></p><p>· <a href="https://www.churchill.io/papers/evolution_of_topic_modeling.pdf">https://www.churchill.io/papers/evolution_of_topic_modeling.pdf</a></p><p>· <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9120935/">A Topic Modeling Comparison Between LDA, NMF, Top2Vec, and BERTopic to Demystify Twitter Posts — PMC (nih.gov)</a></p><p>· <a href="https://maartengr.github.io/BERTopic/algorithm/algorithm.html">https://maartengr.github.io/BERTopic/algorithm/algorithm.html</a></p><p>· <a href="https://arxiv.org/abs/2203.05794">https://arxiv.org/abs/2203.05794</a></p><p>· <a href="https://maartengr.github.io/BERTopic/api/bertopic.html">https://maartengr.github.io/BERTopic/api/bertopic.html</a></p><p>· <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9120935/">https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9120935/</a></p><p>· <a href="https://hackernoon.com/nlp-tutorial-topic-modeling-in-python-with-bertopic-372w35l9">https://hackernoon.com/nlp-tutorial-topic-modeling-in-python-with-bertopic-372w35l9</a></p><p>· <a href="https://arxiv.org/abs/2203.05794">https://arxiv.org/abs/2203.05794</a></p><p>· <a href="https://arxiv.org/pdf/1810.04805.pdf">https://arxiv.org/pdf/1810.04805.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73af7697b7f3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/digital-engineering-centific/bertopic-modelling-advanced-topic-modelling-73af7697b7f3">BerTopic Modelling -Advanced Topic Modelling:</a> was originally published in <a href="https://medium.com/digital-engineering-centific">Digital Engineering @ Centific</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>