<?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 Naveen Kashyap on Medium]]></title>
        <description><![CDATA[Stories by Naveen Kashyap on Medium]]></description>
        <link>https://medium.com/@naveen.maltesh?source=rss-4de9f913c07b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*af7eWHEOAXrbI5Ljrlryqg.jpeg</url>
            <title>Stories by Naveen Kashyap on Medium</title>
            <link>https://medium.com/@naveen.maltesh?source=rss-4de9f913c07b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 14:23:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@naveen.maltesh/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[BYOLM ]]></title>
            <link>https://medium.com/analytics-vidhya/byolm-32d728efbf21?source=rss-4de9f913c07b------2</link>
            <guid isPermaLink="false">https://medium.com/p/32d728efbf21</guid>
            <category><![CDATA[hugging-face]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[language-model]]></category>
            <dc:creator><![CDATA[Naveen Kashyap]]></dc:creator>
            <pubDate>Mon, 07 Sep 2020 10:00:26 GMT</pubDate>
            <atom:updated>2020-09-10T13:41:52.917Z</atom:updated>
            <content:encoded><![CDATA[<p>Build Your Own Language Model 📚</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rgexplrjB-SzefcjyiFpgw.jpeg" /><figcaption>kannada wordcloud</figcaption></figure><p>Long time ago there was need of computation power to build fascinating things in AI/ML domain , which actually contribute to human advancements like medicine research and identifying the cancer cell and even recent one finding cure for Covid-19 but with the advancements in the field of AI/ML and developments of robust libraries and frameworks made the dream come true to build/train the models any where from the world and even without need of heavy computing resources , so today I am briefing about one such advancement which made a huge contribution in the field of Natural Language Processing(NLP) .</p><blockquote>Hugging Face is a most promising team in the NLP world which revolutionized the NLP domain with their contributions to it with Transformers. Have a look at their website <a href="https://huggingface.co/">https://huggingface.co/</a> 🤗</blockquote><p>Today I will explain you on how you can train your own language model using <a href="http://huggingface/">HuggingFace’s</a> transformer library , given that you have the required data set for it. Don’t worry if you don’t have you can always try out with freely available data and train a model to gain the knowledge about it check this <a href="https://traces1.inria.fr/oscar/">wonderful site</a> for data set to try out or even you can do web scraping to get the needed data.</p><p>Once you have the data set , next comes the set up to train the model</p><p><strong>Hardware </strong>: If you have GPU machine available you can train on it, else make use of Google <a href="https://colab.research.google.com/">CoLab </a>or <a href="http://kaggle.com/">Kaggle </a>Notebooks to train given that you have sliced the data to fit for the CoLab/Kaggle RAM size so that it will be able to fit the data during training process or else you will see Out of memory errors or notebooks will hang.</p><p>Once you are ready with the hardware next comes the dependency packages to train the model.</p><pre># Install `transformers` from master</pre><pre>!pip install git+https://github.com/huggingface/transformers</pre><p>Training is broken down as below steps:</p><ul><li><strong>Tokenize</strong></li><li><strong>Config setup</strong></li><li><strong>Load Data set</strong></li><li><strong>Train</strong></li><li><strong>Test</strong></li><li><strong>Publish/Upload</strong></li></ul><ol><li><strong>Tokenize:</strong></li></ol><p>This is the process of splitting the sentences in to words we will use <strong><em>ByteLevelBPETokenizer -</em></strong>this is a byte level or character level tokenizer. read more <a href="https://medium.com/@pierre_guillou/byte-level-bpe-an-universal-tokenizer-but-aff932332ffe">about it here</a>.</p><pre>from pathlib import Path<br>from tokenizers import ByteLevelBPETokenizer<br><strong>#get all .txt files in the given path here you can point to data set file.</strong><br>paths = [str(x) for x in Path(&quot;.&quot;).glob(&quot;**/*.txt&quot;)] </pre><pre><strong># Initialize a tokenizer</strong><br>tokenizer = ByteLevelBPETokenizer()<br><strong># Customize training</strong><br>tokenizer.train(files=paths, vocab_size=52_000, min_frequency=2, special_tokens=[&quot;&lt;s&gt;&quot;,&quot;&lt;pad&gt;&quot;,&quot;&lt;/s&gt;&quot;,&quot;&lt;unk&gt;&quot;,&quot;&lt;mask&gt;&quot;,])</pre><pre><strong># save the tokenizer output to local folder change dir name as per your need here my dir name is myBERTo<br></strong>tokenizer.save_model(&quot;myBERTo&quot;)</pre><p><strong>2. Config setup</strong></p><p><a href="https://arxiv.org/abs/1907.11692">RoBERTA </a>is one of the training approach for BERT based models so we will use this to train our BERT model with below config. Play with the values of these hyper parameters and train accordingly to get better results.</p><pre>from transformers import RobertaConfig</pre><pre>config = RobertaConfig(<br>vocab_size=52_000,<br>max_position_embeddings=514,<br>num_attention_heads=12,<br>num_hidden_layers=6,<br>type_vocab_size=1,<br>)</pre><p>3. <strong>Load Data set</strong></p><p>Once we have the tokenized data and finalized the config params for RoBERTa lets see how we will load the data for training.</p><p>Assuming we have a txt file with data sentences arranged line by line we will use <strong>LineByLineTextDataset </strong>util from transformer to load the data file. Again here also you can play around with config params to fit best for your case.</p><p>And <strong>DataCollatorForLanguageModeling </strong>util for data back propagation required by Pytorch framework during training.</p><pre>from transformers import LineByLineTextDataset<br>dataset = LineByLineTextDataset(<br>tokenizer = tokenizer,<br>file_path=&quot;./language-data-file.txt&quot;, <strong>#this path is from step 1</strong><br>block_size=128,)</pre><pre><strong># need this util for data back propagation <br></strong>from transformers import DataCollatorForLanguageModeling<br>data_collator = DataCollatorForLanguageModeling(<br>tokenizer=tokenizer, mlm=True, mlm_probability=0.15)</pre><p>4. <strong>Train</strong></p><p>Now we are almost ready to train the model. First lest set up training arguments and few params needed for it.</p><pre><strong>#Set up training arguments</strong><br>from transformers import Trainer, TrainingArguments<br>training_args = TrainingArguments(<br>output_dir=&quot;./myBERTo&quot;, <strong>#this dir name is from step 1</strong><br>overwrite_output_dir=True,<br>num_train_epochs=10,<strong>#change epoch values as you need.more the number longer it takes to train.</strong><br>per_gpu_train_batch_size=64,<strong> #decrease this number for out of memory issues</strong><br>save_steps=10_000,<br>save_total_limit=2,<br>)</pre><pre><strong>#define trainer object with above training args</strong></pre><pre>trainer = Trainer(<br>model=model,<br>args=training_args,<br>data_collator=data_collator,<br>train_dataset=dataset,<br>prediction_loss_only=True,)</pre><pre><strong>#trigger the training <br></strong>trainer.train()</pre><pre><strong>#save the model in local directory<br></strong>trainer.save_model(&quot;./myBERTo&quot;)</pre><p>Training will take time depending on the config params you set up in above code.</p><p><strong>5. Test the trained model.</strong></p><p>If you wish to test the model do as below. and you can retrain the model if you are not happy with the results.</p><p>Transformer library from HugginFace used wrapper called Pipeline which binds the tokenizer and model to test the models.</p><pre>from transformers import pipeline<br>fill_mask = pipeline(<br>&quot;fill-mask&quot;,<br>model=&quot;./myBERTo&quot;,<br>tokenizer=&quot;./myBERTo&quot;)</pre><pre>fill_mask(&quot;i am &lt;mask&gt;.&quot;)</pre><pre><strong>#output will predict the mask word with probabilities</strong>.<br>[{&#39;score&#39;: 0.466119220793247223,<br>  &#39;sequence&#39;: &#39;&lt;s&gt; i am happy.&lt;/s&gt;&#39;,<br>  &#39;token&#39;: 316},<br> {&#39;score&#39;: 0.2403824366629124,<br>  &#39;sequence&#39;: &#39;&lt;s&gt; i am sorry.&lt;/s&gt;&#39;,<br>  &#39;token&#39;: 2340},<br>...</pre><p>6. <strong>Publish/Upload Model</strong></p><p>Once training is finished it will generate model file and other required config files and vocabulary files. If you wish to upload to <a href="https://huggingface.co/models">HuggingFace </a>website you can follow this step or else you can skip this and start using the model straight away within your applications.</p><p>Before uploading first create an account in <a href="https://huggingface.co/">HuggingFace </a>website and login with the same credentials using below commands once login success upload the model to it. Don’t forget to create Model_cards which is like a info card about your uploaded model on their site.</p><pre>transformers-cli login<br>transformers-cli upload ./myBERTo</pre><p>This is a short description of blog written by HuggingFace for detailed learning visit their website and blog which are mentioned in reference.</p><p><strong><em>I have trained a small model with 1Million data samples for </em></strong><a href="https://en.wikipedia.org/wiki/Kannada"><strong><em>Kannada</em></strong></a><strong><em> language which is native language of Karnataka state in India, by following aforementioned steps , you too can do same for your liked languages which will be contribution for advancement of that language.</em></strong></p><p><em>Keep learning and keep sharing .</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3o7btQsLqXMJAPu6Na%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3o7btQsLqXMJAPu6Na%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F3o7btQsLqXMJAPu6Na%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="290" frameborder="0" scrolling="no"><a href="https://medium.com/media/b80ff3cee4a059f44b2b3e71d20c5a9c/href">https://medium.com/media/b80ff3cee4a059f44b2b3e71d20c5a9c/href</a></iframe><h3><strong>References</strong>:</h3><ul><li><a href="https://huggingface.co/models">Models - Hugging Face</a></li><li><a href="https://github.com/huggingface">Hugging Face</a></li><li><a href="https://huggingface.co/blog/how-to-train">How to train a new language model from scratch using Transformers and Tokenizers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32d728efbf21" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/byolm-32d728efbf21">BYOLM 🤗</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generating Code Coverage Report Using GNU Gcov & Lcov.]]></title>
            <link>https://medium.com/@naveen.maltesh/generating-code-coverage-report-using-gnu-gcov-lcov-ee54a4de3f11?source=rss-4de9f913c07b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee54a4de3f11</guid>
            <category><![CDATA[code-coverage]]></category>
            <category><![CDATA[gcov]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[gtest]]></category>
            <category><![CDATA[lcov]]></category>
            <dc:creator><![CDATA[Naveen Kashyap]]></dc:creator>
            <pubDate>Fri, 13 Oct 2017 10:21:07 GMT</pubDate>
            <atom:updated>2020-09-09T12:04:01.852Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc/4.0/</cc:license>
            <content:encoded><![CDATA[<p>Hi Readers ,</p><p>Recently I was going through online contents on how to generate report for the code in C++ project . So I curated this article thinking that it might help other who are in dire need of setting up code coverage reports.</p><blockquote><a href="https://gcc.gnu.org/onlinedocs/gcc/Gcov.html">GCOV — GNU COVerage</a></blockquote><p>This is a tool developed to help user to generate reports for the C++ code written in the project . which helps you to know percentile of test cases covered</p><p>Usually project development cycle will be as</p><ol><li>You develop the software as per your pre-decided design.</li><li>Write Unit test cases to check the functionality of the code written.</li><li>Using these Test case written check the possible code coverage by your test cases.</li><li>And generate report with the above and try to maximize the code coverage percentile by covering more test cases and hitting more lines of codes in your api’s.</li></ol><p>I am not going to discuss all the 4 points above , as you might have already finalized your design and started coding accordingly with proper unit test cases , I will explain how to write unit test with a simple example code along with how to set up Gcov and other required tools for generating reports .</p><blockquote>Hands Onnnnn…</blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl2Je3ktsieOfOGa1G%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fmovie-the-rock-michael-bay-l2Je3ktsieOfOGa1G&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl2Je3ktsieOfOGa1G%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="188" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e7b38eba4b3bdd9d01ab5420b05dd4b/href">https://medium.com/media/8e7b38eba4b3bdd9d01ab5420b05dd4b/href</a></iframe><p>First we will write a simple program say for example Program which gives you the biggest number of given three number</p><p>main.cpp</p><pre>#include&lt;iostream&gt;<br>using namespace std;</pre><pre>int GreatestOfThree(int a,int b,int c){<br>  if((a&gt;b) &amp;&amp; (a&gt;c)){    //for a &gt; b and a&gt;c case<br>    return a;<br>   }<br>   else if(b&gt;c){    //for b&gt;c case <br>    return b;<br>   }<br>  else{<br>    return c;<br>  }<br> return 0;<br>}</pre><pre>//After checking for correctness comment main function to test //main_test.cpp<br>int main()<br>{<br> // your code goes here<br> int a,b,c;<br> cin&gt;&gt;a&gt;&gt;b&gt;&gt;c;<br> cout&lt;&lt;GreatestOfThree(a,b,c);<br> return 0;</pre><pre>}</pre><p>So above is our main program for finding out greatest number in the given three numbers .</p><p>now we will try to build and test whether above code works .. I am compiling my code in Linux machine so below is the command to build the main.cpp</p><pre>g++ -o main main.cpp</pre><p>g++ is the compiler here , -o option to mention the output file name here I am giving it as main and the source file which I want to compile i.e. main.cpp</p><p>once the above command is success without any errors in terminal</p><p>just run the binary/executable as follows</p><pre>$./main 1 2 3 <br>$ 3</pre><p>this should give out put as 3 shown above if everything is correct.</p><p>Next step is to write test cases , Here I am using Gtest, which is yet another opensource powerful library for writing Unit test cases for C++ developed by Google.</p><h3>Gtest Setup</h3><p>First to set up gtest in your machine you need to install gtest library ,so for this we have to get the source code first and build in our machine locally and link the libraries to standard lib path i.e. /usr/lib</p><p>Step 1 . get source from here</p><p><strong>Method 1</strong> . Download with one click</p><p><a href="https://github.com/google/googletest">GitHub - google/googletest: GoogleTest - Google Testing and Mocking Framework</a></p><p><strong>Method 2</strong>: Clone source from repository</p><p>if git program is not installed in your machine first get that and enter below command to get source</p><pre>git clone <a href="https://github.com/google/googletest.git">https://github.com/google/googletest.git</a></pre><p>Step 2 . Extract the archived googletest folder in current directory</p><pre>unzip googletest-master.zip</pre><p>Step 3 . cd in to make folder within googletest directory[cd-change directory ]</p><pre>cd googletest-master</pre><p>Step 4 . type <strong>make , </strong>this will build the googletest library</p><pre>make</pre><p>Step 5 . copy built libary in the current folder to /usr/lib because compiler checks for libs in default path which is /usr/lib</p><pre>sudo cp *.a /usr/lib</pre><p>now you can include gtest header and start writing test cases for your code</p><p>main_test.cpp</p><pre>#include &quot;gtest/gtest.h&quot;<br>#include &quot;main.cpp&quot;</pre><pre>TEST(GreaterTest,AisGreater){<br>EXPECT_EQ(3,GreatestOfThree(3,1,2));</pre><pre>};<br>TEST(GreaterTest,BisGreater){<br>EXPECT_EQ(3,GreatestOfThree(1,3,2));</pre><pre>};<br>TEST(GreaterTest,CisGreater){<br>EXPECT_EQ(3,GreatestOfThree(1,2,3));</pre><pre>};</pre><pre>int main(int argc,char**argv)<br>{<br>testing::InitGoogleTest(&amp;argc, argv);<br>    return RUN_ALL_TESTS();</pre><pre>}</pre><p>The above is the test file to test our GreatestOfThree function, but before building this file notice one thing here we are including main function in test file also so if you compile you will get error saying multiple main function , hence to test out test cases first comment the main function in main.cpp then compile it will work.</p><p>so to compile above code command is as below</p><pre>g++ -o main main_test.cpp -L /usr/lib -I/usr/include</pre><p>this will create an executable named main then just run that to see test cases executing in terminal</p><pre>./main<br>[==========] Running 3 tests from 1 test case.<br>[----------] Global test environment set-up.<br>[----------] 3 tests from GreaterTest<br>[ RUN      ] GreaterTest.AisGreater<br>[       OK ] GreaterTest.AisGreater (0 ms)<br>[ RUN      ] GreaterTest.BisGreater<br>[       OK ] GreaterTest.BisGreater (0 ms)<br>[ RUN      ] GreaterTest.CisGreater<br>[       OK ] GreaterTest.CisGreater (0 ms)<br>[----------] 3 tests from GreaterTest (0 ms total)</pre><pre>[----------] Global test environment tear-down<br>[==========] 3 tests from 1 test case ran. (0 ms total)<br>[  PASSED  ] 3 tests.</pre><p>You will get output as above if everything is correct.</p><h3>Generating Code Coverage Report</h3><p>Now I will show how to generate coverage report for the tests written till now</p><p>So, for this task we are using tool called Gcov , Usually this will come up with GCC inbuilt so no need to install separately to use this tool one must add flags to generate reports flags to be added as follows</p><pre>g++ -o main  -<strong>fprofile-arcs -ftest-coverage </strong>main_test.cpp -L /usr/lib -I/usr/include</pre><p>this will generate an executable with coverage flag enabled so next you need to run the executable to generate files required for coverage report generation</p><pre>./main</pre><p>This will generate two types of files one is ending with extension .gcno which has info for basic block construction and line numbers this is generated because of the <strong>-ftest-coverage</strong> flag which we added while compiling with g++ command , and other type is ending with .gcda will have profiling and coverage information which is generated because of flag -<strong>fprofile-arcs in g++ command </strong>. we need both to create coverage reports .</p><p>To generate report you need to pass your test file to gcov.</p><pre>gcov main_test.cpp</pre><p>this will generate coverage report . which will be named as main_test.cpp.gcov since the content is not much intuitive to read by layman there is another tool which is used to generate html files of these reports which can be viewed in the browser later.</p><p>So here we will use lcov tool to check line coverage and generate html reports . For this command is as shown below.</p><pre>lcov --coverage --directory . --output-file main_coverage.info</pre><p>This will create a coverage report by taking .gcno and .gcda files from ‘.’ i.e. current folder where these files are present and generate an output file with coverage info in file called main_coverage.info .</p><p>Now we have coverage info lets display it in html file using below command.</p><pre>genhtml main_coverage.info --output-directory out</pre><p>the above command will generate html reports in output directory named as out.</p><p>once it is done you can go through the out folder and open index.html to check coverage percentile. It will display both Line coverage and Function coverage as below .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vdt6Wz08UHq49V0sxB6LuA.jpeg" /></figure><p>By this you can conclude how much of your code is getting covered by test cases written by you. Since I just explained you with a simple example you can go through each library/framework documentation further to know more and modify according to your project requirements .</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FnGMnDqebzDcfm%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fanimation-computer-programmers-nGMnDqebzDcfm&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FnGMnDqebzDcfm%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="431" frameborder="0" scrolling="no"><a href="https://medium.com/media/da919c4579ce4b3102346e799e73718b/href">https://medium.com/media/da919c4579ce4b3102346e799e73718b/href</a></iframe><p>Sources:</p><p>Gtest source : <a href="https://github.com/google/googletest/tree/master/googletest"><em>https://github.com/google/googletest/tree/master/googletest</em></a></p><p>Gcov : <a href="https://gcc.gnu.org/onlinedocs/gcc/Gcov.html"><em>https://gcc.gnu.org/onlinedocs/gcc/Gcov.html</em></a></p><p>Lcov :<em> </em><a href="https://github.com/linux-test-project/lcov"><em>https://github.com/linux-test-project/lcov</em></a></p><p>gif image courtesy gify.com :)</p><p>I hope you liked this article .</p><p>Keep Exploring and Sharing :)</p><h3>Believe Strive and Achieve .</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee54a4de3f11" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>