<?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 Srilal S. Siriwardhane on Medium]]></title>
        <description><![CDATA[Stories by Srilal S. Siriwardhane on Medium]]></description>
        <link>https://medium.com/@srilals?source=rss-95b06d6d3ef1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BcX7SXZm6XAofkma_hJb3w.jpeg</url>
            <title>Stories by Srilal S. Siriwardhane on Medium</title>
            <link>https://medium.com/@srilals?source=rss-95b06d6d3ef1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 19:51:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@srilals/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[Typing Sinhala in English letters is harder than it looks]]></title>
            <link>https://srilals.medium.com/typing-sinhala-in-english-letters-is-harder-than-it-looks-35331e29b1b0?source=rss-95b06d6d3ef1------2</link>
            <guid isPermaLink="false">https://medium.com/p/35331e29b1b0</guid>
            <category><![CDATA[orthography]]></category>
            <category><![CDATA[language]]></category>
            <category><![CDATA[sinhala]]></category>
            <category><![CDATA[unicode]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Srilal S. Siriwardhane]]></dc:creator>
            <pubDate>Mon, 19 Oct 2026 17:36:55 GMT</pubDate>
            <atom:updated>2026-10-19T17:36:55.486Z</atom:updated>
            <content:encoded><![CDATA[<p>I collected the rules of Sinhala spelling, checked them by machine on 3.98 million inputs, and measured how people really write. Here is what I learned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-E6N7TvkjFRycP0pwMQMMA.png" /><figcaption>dumriya should become දුම්රිය, not දුම්‍රිය</figcaption></figure><p>Type “<strong>dumriya</strong>” into a Sinhala phonetic converter and you expect <strong>දුම්රිය</strong>, “<strong>train</strong>”. For a while, mine gave me <strong>දුම්‍රිය </strong>instead. The difference is a single invisible character, a zero-width joiner, and it turns the <strong>ර</strong> into a small stroke under the <strong>ම</strong>. No Sinhala reader writes the word that way.</p><p>It looks like a tiny bug. It turned out to be a good example of a bigger problem: the rules that decide how a Sinhala word is spelled have never been written down in one place, in a form a computer can check.<br>So, I tried to do that. The result is an open research project: you can read it and try the converter on the <a href="https://srilals.github.io/Sinhala-Phonetic-Orthography/"><strong>Project site</strong></a>, and the data, code and every number in this article are in the <a href="https://github.com/SrilalS/Sinhala-Phonetic-Orthography"><strong>GitHub repository</strong></a>.</p><h3>Why this is hard</h3><p>Most Sri Lankans who type Sinhala on a phone or a laptop type it phonetically, in English letters: “kohomada” becomes <strong>කොහොමද</strong>. It feels natural, but Latin letters throw away information the Sinhala<br>script keeps.</p><p><strong><em>About 14 groups of Sinhala letters sound the same.</em></strong> <strong>ත</strong> and <strong>ථ, ද</strong> and <strong>ධ, න</strong> and <strong>ණ, ල</strong> and <strong>ළ, ශ, ෂ</strong> and <strong>ස</strong>, and more. When you type “<strong>l</strong>”, nothing in the sound tells the computer whether you meant <strong>ල</strong> or <strong>ළ</strong>. Only knowing the word does.</p><p>P<em>eople Romanize in their own ways.</em> The same word appears as “<strong>kohomada</strong>”, “<strong>kohomadha</strong>” and “<strong>kohomd</strong>”. Vowel length is almost never marked: in a dataset of Romanized sentences written by native speakers,<br><strong>ා</strong> was typed as a plain “<strong>a</strong>” 97% of the time.</p><p><strong><em>The script has rules that a naive converter breaks.</em></strong> Some letters never take a hal (the vowel-killing mark), some never start a word, two vowels are never written side by side, and some joined forms need that invisible joiner while others must not have it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hXaYP_gmSO73UybBii9Jcw.png" /><figcaption>Same sound: <strong>ත ථ, ද ධ, ල ළ</strong>. Many spellings: <strong>kohomada</strong>, <strong>kohomadha</strong>, <strong>kohomd</strong>. Invisible rules: <strong>ක්‍රමය</strong> is joined, <strong>දුම්රිය</strong> is not</figcaption></figure><h3>What I built</h3><p>I started with the sources: the Unicode Standard, the Sri Lankan standard SLS 1134, the ICANN Sinhala script panel, linguistics papers and school grammar material. From them I wrote seven topic studies (letters, vowel signs, conjuncts, nasals, sound patterns and sandhi, romanization) and merged them into one list of <strong>88 rules</strong>. Each rule is marked:</p><p>- <strong>HARD</strong>: never violated in correct text (for example, <strong>ඟ ඦ ඬ ඳ ඹ</strong> never take a hal).<br>- <strong>SOFT</strong>: a tendency, useful for ranking spellings.<br>- <strong>STYLE</strong>: two accepted spellings, both correct.</p><p>On top of the rules sit three things:</p><ol><li><strong>A validity table for all 923 Sinhala letter forms:</strong> every consonant with every vowel sign, marked valid, loan-only, rare, unattested or never.</li><li><strong>A converter</strong> that turns Romanized text into Sinhala and is designed never to produce a form the rules forbid.</li><li><strong>A word-frequency layer</strong> that picks the dictionary spelling when the sound is ambiguous, so “honda” becomes <strong>හොඳ </strong>and “sinhala” becomes <strong>සිංහල</strong>.</li></ol><p>Everything is public, with a Sinhala translation of every study. The<br><a href="https://srilals.github.io/Sinhala-Phonetic-Orthography/">site </a>has the studies, the full rule list, an explorer for all 923 letter forms and a playground that runs the converter in your browser. The <a href="https://github.com/SrilalS/Sinhala-Phonetic-Orthography">repository </a>has the source, the data files and the checking tools, under the MIT license.</p><h3>Three things the data taught me</h3><p>I did not want the rules to rest on my intuition, so I counted. The counts come from three public sources: the University of Moratuwa’s word-frequency list (2.1 million distinct words from news text), Google’s Dakshina dataset of Sinhala sentences Romanized by native speakers, and a dated dump of Sinhala Wikipedia. One script downloads them and recomputes every number below.</p><h4>1. “<strong>d</strong>” should mean <strong>ද</strong>, even though older keyboards say otherwise.</h4><p>Many older Sinhala keyboards map “d” to <strong>ඩ</strong> and “dh” to <strong>ද</strong>, mirroring “t” for <strong>ට</strong> and “th” for <strong>ත</strong>. It looks tidy. But it is not how people write. In the Romanized sentences, people typed <strong>ද</strong> as “d” 99% of the time. - In running text, ද is 5 times as frequent as ඩ (74% of the d-letters against 15%).</p><p>So the unmarked key should go to the common letter. Because many people’s fingers learned the old way, the converter offers the older convention as a setting instead of forcing either one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hyXCBgQlBjNqa95rkgElOA.png" /><figcaption>Share of the d-letters in running text: ද 74.1%, <strong>ඩ</strong> 14.9%, <strong>ධ</strong> 11.1%, <strong>ඪ</strong> under 0.1%</figcaption></figure><h4>2. Textbooks say ක්‍රූර. Writers say කෲර</h4><p>The Unicode Standard illustrates the word “<strong>krūra”</strong> (“cruel”) with rakaransaya plus a u sign: <strong>ක්‍රූර</strong>. Real writing disagrees.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zuGHhGBEsttQbvvr1kyunw.png" /><figcaption><strong>කෲර</strong> 1,667, <strong>ක්‍රෑර</strong> 186 (wrong look-alike),<strong> ක්‍රූර</strong> 9 (textbook form)</figcaption></figure><p>Sinhala Wikipedia agrees: <strong>කෲර</strong> appears in 126 articles and<strong> ක්‍රූර</strong> in none.</p><p>The middle row is the interesting one, and the cause is probably the font. Unicode describes a special shape for rakaransaya plus<strong> ූ</strong>: a stroke after the cluster. Fonts such as Noto Sans Sinhala draw exactly that, and it looks just like the vowel sign<strong> ෑ</strong>. So the correct <strong>ක්‍රූර</strong> and the wrong <strong>ක්‍රෑර</strong> look **“identical” on screen, and a writer who wants that shape can get it by typing<strong> ෑ</strong>, which stores a different vowel (<strong>/æ/</strong>). Windows fonts go the other way: they attach a plain<strong> ූ </strong>below, so in them the correct spelling is the one that looks odd. Either way, the font hides the spelling, and the safe<br>choice for writers is <strong>කෲර</strong>.</p><p>The converter writes <strong>කෲර</strong> by default and offers <strong>ක්‍රූර</strong> as an option for those who prefer it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x7D8AoED5nHLaunRWcB5vg.png" /><figcaption><strong>ෲර</strong> 1,667, <strong>ක්‍රෑර</strong> 186 (wrong vowel), <strong>ක්‍රූර</strong> 9 (correct). In Noto Sans Sinhala, <strong>ක්‍රෑර</strong> and<strong> ක්‍රූර</strong> look identical</figcaption></figure><h4>3. The invisible joiner has an exception</h4><p>When a consonant is followed by <strong>ර</strong> inside a syllable, Sinhala writes it with a rakaransaya, and that needs the zero-width joiner:<strong> ක්‍රමය</strong> (“method”) appears 26,312 times, the joiner-less <strong>ක්රමය</strong> only 175. So my first rule was simple: always join.</p><p>That rule produced <strong>දුම්‍රිය</strong>. The data showed the exception:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IZD3HpDbTy0YXMyszv9NAQ.png" /><figcaption><strong>දුම්රිය</strong>: 30,800 plain vs 82 joined; all<strong> ම්ර</strong>: 46,496 vs 383</figcaption></figure><p>After <strong>ම, න</strong> and <strong>ල</strong>, the <strong>ර</strong> usually starts a new syllable (<strong>දුම් + රිය</strong>, <strong>හෙන්රි </strong>“Henry”), so it takes a plain hal. The rule now says exactly that, and the converter follows it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VmG8wo6jvm9OIPdwH4OdXw.png" /><figcaption><strong>ක්‍රමය</strong> is joined (26,312 vs 175); <strong>දුම්රිය</strong> is not (30,800 vs 82)</figcaption></figure><p>A note on “correct”: some words have two accepted spellings. <strong>තත්ත්වය</strong> is the grammatical form (Sanskrit *tat + tva*); <strong>තත්වය </strong>is the modern one, and both are valid. In news text they are almost equally common (25,852 against 21,484). The rule set records these as STYLE: accept both, never “correct” one into the other.</p><h3>How I know it works</h3><p>This is the part I care about most, and the part most Sinhala tools skip: checking.</p><h4><strong>The rules are checked exhaustively.</strong></h4><p>The converter reads input as a sequence of units (“k”, “aa”, “th”, and so on). I fed it every combination of up to three units, plus a space, under each of its six option sets: 3.98 million inputs in all. Every output was checked against 14 forbidden patterns taken from the HARD rules (a hal on <strong>ඟ</strong>, two vowel signs in a row, a word starting with <strong>ඬ</strong>, and so on).</p><ul><li><strong>0 violations.</strong> And every letter forms the rules allow can actually be typed: 791 of 791.</li></ul><h4><strong>The dictionary layer is measured.</strong></h4><p>On 27 everyday words written the way people actually Romanize them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2uco_u0dOVg7Evq86zCkpA.png" /><figcaption>Rules alone: 9 of 27; rules + word frequency: 27 of 27</figcaption></figure><h4>The ports are tested against the reference.</h4><p>The reference implementation is in Python. A TypeScript version is checked against it on more than 60,000 inputs (golden tests), and anyone porting it to another language can use the same test files.</p><pre>python tools/check_romanization.py<br>coverage: 791/791; gaps: []<br>safety[default]: 643,538 inputs, 0 violations</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*32m-mrFzbgz4cuhCCjiasw.png" /><figcaption>3.98 million inputs checked, 0 rule violations, 791 of 791 allowed letter forms typeable</figcaption></figure><h3>සිංහලෙන් කෙටියෙන්</h3><p>ඉංග්‍රීසි අකුරින් සිංහල ලිවීමේදී එකම ශබ්දය ඇති අකුරු 14 ක් පමණ කාණ්ඩ ඇති බැවින් (<strong>ත/ථ, ද/ධ, ල/ළ</strong> වැනි), නිවැරදි අක්ෂර වින්‍යාසය ශබ්දයෙන් පමණක් තීරණය කළ නොහැකිය. එබැවින් සිංහල අක්ෂර වින්‍යාසයේ නීති 88 ක් මූලාශ්‍ර සහිතව එක් තැනකට ගෙන, ඒවා Inputs මිලියන 3.98ක් මතින් පරීක්ෂා කරන ලදී. එක් නීතියක්වත් උල්ලංඝනය නොවුනු අතර පොදු දත්ත මූලාශ්‍ර තුනකින් වර්ථමානයේ සැබවින්ම ලියන ආකාරයද මැන බලන ලදී: “d” යනු 99% ක්ම දයන්න වන අතර, <strong>කෲර, ක්‍රූර</strong> ට වඩා බොහෝ සුලබය. <strong>දුම්රිය </strong>වැනි වදන් ZWJ නැතිව ලියවිය යුතුවේ.</p><h3>Try it, use it, correct it</h3><ul><li>🌐 <strong>Read the studies and try the converter in your browser:</strong> <a href="https://srilals.github.io/Sinhala-Phonetic-Orthography/">https://srilals.github.io/Sinhala-Phonetic-Orthography/</a> (also in Sinhala)</li><li>💻 <strong>Get the source, data and tools:</strong> <a href="https://github.com/SrilalS/Sinhala-Phonetic-Orthography">https://github.com/SrilalS/Sinhala-Phonetic-Orthography</a></li><li>📦<strong>Use it in JavaScript or TypeScript:</strong> “npm install sinhala-orthography”</li><li>📚 <strong>Cite it:</strong> doi:10.5281/zenodo.23244126</li><li>💬<strong> Correct it:</strong> Some rules still rest on a single source, and every study ends with its open questions. If you know Sinhala grammar better than a corpus does, I would like to hear from you.</li></ul><p>The individual facts about Sinhala spelling are not new. What I hope is useful is having them in one place, with sources, numbers anyone can recompute, and a converter that is checked against them. Sinhala<br>deserves tools that get the details right.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35331e29b1b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI Detection tools DOESN’T WORK!]]></title>
            <link>https://srilals.medium.com/ai-detection-tools-doesnt-work-6968c8dd9508?source=rss-95b06d6d3ef1------2</link>
            <guid isPermaLink="false">https://medium.com/p/6968c8dd9508</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[academia]]></category>
            <dc:creator><![CDATA[Srilal S. Siriwardhane]]></dc:creator>
            <pubDate>Tue, 27 Feb 2024 19:01:34 GMT</pubDate>
            <atom:updated>2024-02-27T19:01:34.188Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BJoQ-D9WHOEa9PQERDo6lA.jpeg" /></figure><p>Before discussing the “Why” let’s have a little bit of background into this. a few months back I saw a few people in academics saying that Turnitin can detect AI-generated content now. and some even saying they will punish students if they get caught using GenAI content. recently i saw some students got caught by Turnitin as it detected their work was AI-generated. problem is no one can prove they used GenAI or not!. (From here and out, GenAI will generally refer to LLMs.)</p><p>Now, In a paper (<a href="https://arxiv.org/abs/2303.11156">Link</a>) published by a team of computer scientists and mathematicians at the University of Maryland, they have shown that even with the LLM watermarking method, these AI Detectors have no more than 50% accuracy at best. to quote Dr. Soheil Feizi, <strong>“It will be very close to a random coin flip in terms of detecting AI-generated text or human-generated text”.</strong></p><p>So, the below code can predict if a text is written by GenAI with equal accuracy to all the so-called AI detection tools.</p><pre>const randomNumber: number = Math.floor(Math.random() * 101);<br>console.log(`GenAI Probability: ${randomNumber}%`);</pre><p>You would get better results asking chatGPT if he wrote the It! It doesn’t matter if the tool says it’s 0% AI-generated or 100% AI-generated, in the end, this number is meaningless.</p><p>But why we can’t build something that can detect GenAI content? This is simply because modern Large Language Models (LLMs) closely resemble human writing more than the average human does. think of how an average human writes. half the population writes worse than that. If you were to place LLMs in the bell curve of Human writing abilities, modern LLMs will be on the far right side!</p><p>This is why OpenAI has abandoned its efforts to create an AI detection tool. in a Blog post from OpenAI (<a href="https://help.openai.com/en/articles/8313351-how-can-educators-respond-to-students-presenting-ai-generated-content-as-their-own">Link</a>) they state that <strong>“…Our research into detectors didn’t show them to be reliable enough given that educators could be making judgments about students with potentially lasting consequences.”</strong></p><p>In their marketing, Turnitin claims to only have a false positive/negative rate of 1% but as studies have shown it’s much higher than that (it’s only accurate only about 50%). for example, if you put a paragraph from a famous book, like from the Bible, it will say it’s AI-generated with a high probability. that shows how inaccurate these things are. these so-called AI Detection tools only exist to extort money from gullible academic institutions. since Turnitin is used by many academic institutions it’s just a bit more marketing on their side to sell this.</p><p>Let’s say an institution with 1000 students uses a so-called AI detection tool to detect if students submit AI-generated content. even if this tool only has a 1% false positive rate that means about 10 students will get falsely accused of using AI-generated content.</p><p>But how can they prove if a student used AI? How do they prove if a given text is AI-generated?</p><p>Well, obviously they can’t! these AI detection tools cannot provide any actual evidence other than some arbitrary percentage number pulled from its algorithmic posteriors!</p><p>after all, since these tools themself are AI’s, they are Blackboxes. you won’t get any reasons why they think that it’s AI-generated. even in some cases, changing a single letter will drastically change the detected probability. since all academic writing is similar in style, the chances of a false positive increase. also for someone whose English is the second language chances of false positives, or even false negatives can be increased.</p><p>Even some universities have stopped using Turnitin or any other so-called AI Detection tools altogether due to this unreliable nature. this article (<a href="https://www.vanderbilt.edu/brightspace/2023/08/16/guidance-on-ai-detection-and-why-were-disabling-turnitins-ai-detector/">Link</a>) from <strong>Vanderbilt University in Tennessee, USA</strong> provides the reasoning behind their decision. Bloomberg reports (<a href="https://www.bloomberg.com/news/newsletters/2023-09-21/universities-rethink-using-ai-writing-detectors-to-vet-students-work">Link</a>), some universities have decided to stop using AI writing detection tools to evaluate students’ work.</p><p>Instead of trying to fight an already lost war on AI Detection, the best course of action would be to adopt the GenAI into academics and we see some universities have already started this process.</p><p><strong>The Northwestern University in Illinois, USA</strong> has provided some guidelines (<a href="https://ai.northwestern.edu/education/use-of-generative-artificial-intelligence-in-courses.html">Link</a>) on how to adopt GenAI into the classroom. also in their reasoning, they state a very important fact. to quote them directly, <strong>“GAI is integrated deeply into many tools and will become increasingly difficult to opt out of.” </strong>(The provided link from Northwestern University is a very interesting and helpful course on using GenAI. they have written a set of articles that will be essential for anyone who uses GenAI)</p><p>As more and more tools we use start to implement GenAI, such as Microsoft Office, it will be difficult to actually not use GenAI even if the writer wanted to. Many have already introduced how to cite GenAI in various citing formats.</p><ul><li><a href="https://subjectguides.uwaterloo.ca/chatgpt_generative_ai/aigeneratedcontentcitation">AI-generated content and citation — ChatGPT and Generative Artificial Intelligence (AI) — Research guides at University of Waterloo (uwaterloo.ca)</a></li><li><a href="https://apastyle.apa.org/blog/how-to-cite-chatgpt">How to cite ChatGPT (apa.org)</a></li><li><a href="https://style.mla.org/citing-generative-ai/">How do I cite generative AI in MLA style? | MLA Style Center</a></li></ul><p>Finally, if anyone falsely accuses you of using GenAI, ask for proof. Also, you can simply find a piece of text written by the accuser and put it in multiple so-called AI Detection tools. and unsurprisingly each tool will have a different opinion and will show the text having AI-generated parts with arbitrary probability numbers that cannot be proven.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6968c8dd9508" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Large Language Model Parameters Explained]]></title>
            <link>https://srilals.medium.com/large-language-model-parameters-explained-646bbb44a0aa?source=rss-95b06d6d3ef1------2</link>
            <guid isPermaLink="false">https://medium.com/p/646bbb44a0aa</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Srilal S. Siriwardhane]]></dc:creator>
            <pubDate>Mon, 24 Jul 2023 11:44:35 GMT</pubDate>
            <atom:updated>2023-07-24T11:44:35.908Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ofUWZoV5aiEjlregRNi8ww.jpeg" /></figure><p>When we use any large language model (LLM) we can set a few parameters to customize the behavior of the model. Even though these are utilized in every application that uses a LLM, they are yet largely misunderstood by many people. To understand what they are and how they affect the model let’s first look at how an LLM outputs text.</p><p>The Sole task of a LLM is to predict the next word or phrase.</p><p>Let’s assume we ask the model a question and let’s assume this question has N number of tokens. Now the model’s task is to predict the N+1th word. To do this model first look at the Nth tokens “Final Hidden State Vector”. Final hidden state vector represents the internal state of the model after processing the entire input sequence up to and including the Nth token.</p><p>Now this final hidden state vector is multiplied by the transpose of the embedding matrix used to convert original N input tokens into vectors. This transposed embedding matrix is called the “unembedding matrix”. (The embedding matrix is a matrix of weights that is learned during training).</p><p>The output of the above operation is a set of Logits. Logits are essentially just a probability set. In this case the sum of these probabilities don’t add up to 1. So these are called unnormalized log probabilities. Before going into the next step these Logits are normalized so they add up to a 1.</p><p>Now the SoftMax function is used to generate a normalized probability distribution for the possible tokens and the output token is chosen based on this probability distribution. For the N+2, this whole process repeats but the calculation will include the newly generated N+1th token. Essentially the N+2 becomes the new N+1.</p><p>Now we know how these models output text, let’s see how the main 2 parameters affect the model’s output.</p><h3>Temperature</h3><p>This is the most misunderstood parameter of all. Most people think of this parameter as the value that controls the creativity of a model. While that is true, it’s just a byproduct of this parameter.</p><p>Temperature comes into play In the step where the softmax is calculated. Below is a rough representation of how the softmax function is used in turning logits into probabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/192/0*poz7gUlgRsm1Iyjt" /></figure><p>In the above equation the T is the temperature value.</p><p><em>When T is 0, the equation becomes,</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/0*yK3y1oChKo0us1xL" /></figure><p>This means that the probability of the predicted class is 1 and all other classes have a probability of 0.</p><p><em>When T is 1, the equation becomes:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/185/0*RV7GzkL9QUXdP8Fx" /></figure><p>The temperature parameter T controls the “softness” of the probability distribution. When T is high, the distribution becomes softer and more uniform. When T is low, the distribution becomes sharper and more peaked.</p><p>Simply said, the temperature parameter T controls the “softness” of the probability distribution. When T is high, the distribution becomes softer and more uniform. This means that the model is more likely to generate creative and diverse outputs. When T is low, the distribution becomes sharper and more peaked. This means that the model is more likely to generate outputs that are similar to the training data.</p><p>Let’s Look at a few examples of how Temperature affects the model outputs. <em>(All examples use text-davinci-002 Model and the Top P is kept at a 1)</em></p><p>At different temperature values let’s look at how models generate from the same starting text.</p><p>Text : “My favorite animal is ”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*dw1u6suNIPsDGUJhAc7p-A.png" /><figcaption>Effect of Temperature Value</figcaption></figure><p>As we decrease the temperature the outputs become more constant and less detailed but highly focused.</p><h3>Top P</h3><p>Top P is a decoding method used to decode the output token from the selected token probabilities.</p><p>Let’s assume you set the Top P value as P (0 ≤ P ≤ 1).</p><p>Now we have a set of words from the previous step with various probabilities. How Top P works is if it finds the smallest group of words whose cumulative probability exceeds the value of P. This way, the number of words in the set can dynamically increase and decrease according to the next word probability distribution.</p><p>If the value of P is 0, then “Top P” will select the word with the highest probability. This is equivalent to greedy decoding.</p><p>If the value of P is 1, then “Top P” will select the entire set of words. This is equivalent to sampling from the entire distribution.</p><p>For Top P examples, the same text-davinci-002 model is used with a constant temperature of 0.5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*ZYSXygnFILsv2joEkt8hkw.png" /><figcaption>Effect of Top P Value</figcaption></figure><p>With a higher value of K or P, the LLM has more options to choose from, resulting in more varied output. Conversely, lower values restrict the choices and make the output more focused and coherent.</p><h3>Conclusion</h3><p>In conclusion, we now have an explanation of two important parameters that can be used to customize the behavior of large language models (LLMs): Temperature and Top P. The primary task of an LLM is to predict the next word or phrase based on the input sequence. To achieve this, the model calculates a set of logits representing unnormalized probabilities, which are then normalized using the SoftMax function to generate a probability distribution for the possible tokens. Understanding and appropriately using these parameters can significantly impact the output of large language models, allowing users to tailor the model’s behavior to their specific needs. Temperature and Top P provide valuable tools to strike a balance between creativity and adherence to the training data, enabling LLMs to be more versatile and better suited for various applications.</p><h4>References:</h4><p><a href="https://www.lesswrong.com/posts/pHPmMGEMYefk9jLeh/llm-basics-embedding-spaces-transformer-token-vectors-are">LLM Basics: Embedding Spaces — Transformer Token Vectors Are Not Points in Space — LessWrong</a></p><p><a href="https://newsletter.victordibia.com/p/practical-steps-to-reduce-hallucination">Practical Steps to Reduce Hallucination and Improve Performance of Systems Built with Large Language Models — Issue #11 (victordibia.com)</a></p><p><a href="https://huggingface.co/blog/how-to-generate">How to generate text: using different decoding methods for language generation with Transformers (huggingface.co)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=646bbb44a0aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Optimize VueJs + Vuetify SPA Builds with Laravel MIX]]></title>
            <link>https://srilals.medium.com/how-to-optimize-vuejs-vuetify-spa-builds-with-laravel-mix-e5a031a63909?source=rss-95b06d6d3ef1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5a031a63909</guid>
            <category><![CDATA[laravel-mix]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[vuetify]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[optimize]]></category>
            <dc:creator><![CDATA[Srilal S. Siriwardhane]]></dc:creator>
            <pubDate>Tue, 26 Oct 2021 07:28:50 GMT</pubDate>
            <atom:updated>2021-10-26T12:53:21.826Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BwH51H8wyWDVFTC3Wyaz6Q.png" /></figure><p>If you have ever built an application with Laravel as backend and Vue/Vuetify for frontend you know how “Heavy” the UI Js Bundles get even with GZIP. Vuetify alone will eat up more than half a megabyte. That may sound not a lot but for your users, it is. That 0.5MB will cause your application’s First content full paint to lag for at least a second or two on an average connection. BUT remember if that’s the average, a half of your yours will have worse loading times than that. (You can use <a href="https://bundlephobia.com/">https://bundlephobia.com/</a> to get a rough idea on loading times and sizes but these values will be quite different in reality)</p><h3>So, what’s the solution?</h3><p>Well, there are multiple solutions. But most ignored and overlooked one is trying to tree shake and reduce the size of your Js bundles even if you split it into few parts. And sometimes splitting Js bundles may increase the loading times depending on well, dependencies! Staring with Tree shaking will be always a good bet.</p><p>Many not know but with most recent version of Laravel mix, you can do Tree Shaking for VueJs UIs that are using Vuetify UI Library. To get started you will need to install few dependencies and update few that may already be installed in your project.</p><h3>Prerequisites</h3><p>First make sure your Laravel Mix version is upgraded to the latest version and at least 6.X. upgrading mix is bit messy if you are using an older version. But sticking to the official upgrade guide from <a href="https://laravel-mix.com/docs/6.0/upgrade">here</a> will sort most of these issues out.</p><blockquote><strong><em>Special Note: As of writing this there is a compatibility issue with Sass library. Simply use no more than version 1.32.X. The more recent version will break your builds and Dev Runs.</em></strong></blockquote><p>And remember to update your build scripts as well.</p><h3><strong>Configure Vuetify Import Options</strong></h3><p>The Vuetify tree shaking only happen if we import Vuetify libraries instead the whole Vuetify itself. This allows for the Vuetify loader to import only the used components and saves the build sizes. In the place where you have imported Vuetify, make sure to import Vuetify by only the Vuetify Libs. And you don’t need to import the CSS now because the Vuetify Loader will do it for you.</p><pre><strong>import Vuetify from ‘vuetify/lib’;</strong></pre><h3>Laravel Mix Bundle Analyzer</h3><p>Now let’s install webpack bundle analyzer. What’s the points if we can’t measure how much bytes we saved by doing all this! We cannot use the regular bundle analyzer, we need “<strong>Laravel-mix-bundle-analyzer” </strong>a wrapper around the Webpack bundle analyzer with compatibility with Laravel Mix.</p><p>· You can install it by running:</p><pre><strong>npm i laravel-mix-bundle-analyzer — save-dev</strong></pre><p>· More info and full details:</p><p><a href="https://www.npmjs.com/package/laravel-mix-bundle-analyzer">laravel-mix-bundle-analyzer</a></p><h3><strong>Vuetify Mix Extension</strong></h3><p>this one will help the Laravel Mix with Vuetify. it’s a wrapper around official vuetify webpack plugin for Mix. It also provides a key option in tree shaking for Vuetify.</p><p>· You can install it by running:</p><pre><strong>npm i vuetifyjs-mix-extension — save-dev</strong></pre><p>· More info and full details:</p><p><a href="https://www.npmjs.com/package/vuetifyjs-mix-extension">vuetifyjs-mix-extension</a></p><h3>Vuetify Loader</h3><p>This will automatically import all Vuetify components as you use them so unused components can be safely ignored. thus, decreasing build size.</p><p>· You can install it by running:</p><pre><strong>npm i vuetify-loader — save-dev</strong></pre><p>· More info and full details:</p><p><a href="https://www.npmjs.com/package/vuetify-loader">vuetify-loader</a></p><h3><strong>Configure Webpack Options</strong></h3><p>now we have everything we need. Let’s configure the Webpack configurations in <strong>Webpack.mix.js </strong>file.</p><p>First import the 3 libraries we just installed on the top of the file.</p><pre><strong>const mix = require(‘laravel-mix’);</strong></pre><pre><strong>require(‘vuetifyjs-mix-extension’)</strong></pre><pre><strong>require(‘laravel-mix-bundle-analyzer’);</strong></pre><pre><strong>require(‘vuetify-loader’);</strong></pre><p>to only run the bundle analyzer when we do a production build, let’s add check to see if it’s a production build and run only if so. Mix API provides a way to do this easily.</p><pre><strong>if (mix.inProduction()) {</strong></pre><pre><strong>    mix.bundleAnalyzer();</strong></pre><pre><strong>}</strong></pre><p>And to inform the Laravel Mix to utilize Sass-loader and Vuetify-loader we need to add it to the default exports.</p><pre><strong>module.exports = {<br>    module: {<br>        rules: [<br>            {<br>                test: /\.s(c|a)ss$/,<br>                use: [<br>                    &#39;vue-style-loader&#39;,<br>                    &#39;css-loader&#39;,<br>                    {<br>                        loader: &#39;sass-loader&#39;,<br>                        options: {<br>                            implementation: require(&#39;sass&#39;),<br>                            sassOptions: {<br>                                indentedSyntax: true<br>                          },<br>                        },<br>                    },<br>                ],<br>            },<br>        ],<br>    },<br>    configureWebpack: {<br>        plugins: [<br>          ],<br>    },<br>}</strong></pre><p>For configuring Hot Reload feature add, (if you are using Laragon or similar, add your virtual host address to host property instead of localhost)</p><pre><strong>mix.options({<br>    hmrOptions: {<br>        host: &#39;localhost&#39;,<br>        port: 8080,<br>    },<br>});</strong></pre><p>Finally, we can configure the actual Vue and Vuetify options in Mix to allow for a tree shake. We need to tell Mix that we are using Vue and Vuetify and the Vuetify is using Vuetify Loader.</p><pre><strong>mix.js(‘resources/js/App.js’, ‘public/js’)</strong></pre><pre><strong>    .vuetify(‘vuetify-loader’)</strong></pre><pre><strong>    .vue()</strong></pre><pre><strong>    .sass(‘resources/sass/app.scss’, ‘public/css’);</strong></pre><p>And if you have more than one Vue Instances using different Vuetify imports,</p><pre><strong>mix.js(‘resources/js/AppOne.js’, ‘public/js’)</strong></pre><pre><strong>    .vuetify(‘vuetify-loader’)</strong></pre><pre><strong>    .vue()</strong></pre><pre><strong>    .js(‘resources/js/AppTwo.js’, ‘public/js’)</strong></pre><pre><strong>    .vuetify(‘vuetify-loader’)</strong></pre><pre><strong>    .vue()</strong></pre><pre><strong>    .sass(‘resources/sass/app.scss’, ‘public/css’);</strong></pre><p>Congratulations! now you have more optimized Vue/Vuetify Build! try running a production build and compare the sizes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5a031a63909" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase CRUD Operations With Flutter Part 3 (Building Queries)]]></title>
            <link>https://srilals.medium.com/firebase-crud-operations-with-flutter-part-3-building-queries-f5c6f57bcf42?source=rss-95b06d6d3ef1------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5c6f57bcf42</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[query]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[querying]]></category>
            <dc:creator><![CDATA[Srilal S. Siriwardhane]]></dc:creator>
            <pubDate>Thu, 28 May 2020 12:58:41 GMT</pubDate>
            <atom:updated>2020-05-28T12:58:41.129Z</atom:updated>
            <content:encoded><![CDATA[<p>in this tutorial set we will see how to build Firestore Queries with flutter. we will also see how to create simple queries in Firestore. this will be the 3rd Part of Firebase CRUD Operations With Flutter. Read the Previous ones from <a href="https://medium.com/@srilalsachintha/">Here</a>.</p><p><strong>Note : All the Working State Code for these tutorials can be found in : </strong><a href="https://github.com/SrilalS/Flutter-Tutorial"><strong>https://github.com/SrilalS/Flutter-Tutorial</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*IFSOYyczt8iNWx9e.png" /></figure><p>Firestore is a NoSQL Database. but it doesn’t mean we can run Queries in the Database. We can run Many Types of Queries in the Firestore.</p><p>it Supports the following Queries.</p><p><strong>isEqualTo</strong> : check if a value in the database is equal to a value we already have.</p><p><strong>isLessThan : </strong>this works for numerical values.</p><p><strong>isLessThanOrEqualTo : </strong>this works for numerical values.</p><p><strong>isGreaterThan : </strong>this works for numerical values.</p><p><strong>isGreaterThanOrEqualTo : </strong>this works for numerical values.</p><p><strong>isNull : </strong>checks if value is null or not</p><p>Lets see how to build a simple query.</p><blockquote>Firestore.instance.collection(‘TUT’).where(‘F’, isEqualTo: text).snapshots(),</blockquote><p>i’m using the same database i used previously. here is the structure,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8BI3PU-j1YvAqsBf6iHzVQ.png" /></figure><p>in the Query i made, it checks the field ‘F’ in the Documents in the TUT Collection against the local variable “text”.</p><p>here is the full example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a65034be39d2a3336966d7d956e702c/href">https://medium.com/media/7a65034be39d2a3336966d7d956e702c/href</a></iframe><p>here it only returns the ‘UNN’ ships. isEqual works for many Datatypes unlike other Queries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*DHW9XQIGIMQ0lFYEQdQNBg.png" /></figure><p>lets see a example of <strong>isGreaterThan.</strong></p><blockquote>Firestore.instance.collection(‘TUT’).where(‘C’,isGreaterThan: amount).snapshots(),</blockquote><p>the variable “amount” has the value of 1500, so It returns all the ships with crew capacity more then 1500,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*nP9AWhWf7-DXrNwwUT7zPw.png" /></figure><p>You can also combine multiple queries like below.</p><blockquote>Firestore.instance.collection(‘TUT’).where(‘F’,isEqualTo: text).where(‘C’,isGreaterThan: amount).snapshots(),</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5c6f57bcf42" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase CRUD Operations With Flutter Part 2 (Collection Reference)]]></title>
            <link>https://srilals.medium.com/firebase-crud-operations-with-flutter-part-2-collection-reference-de374fe39bf0?source=rss-95b06d6d3ef1------2</link>
            <guid isPermaLink="false">https://medium.com/p/de374fe39bf0</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[firestore]]></category>
            <dc:creator><![CDATA[Srilal S. Siriwardhane]]></dc:creator>
            <pubDate>Wed, 29 Apr 2020 09:51:01 GMT</pubDate>
            <atom:updated>2020-04-29T09:51:01.483Z</atom:updated>
            <content:encoded><![CDATA[<p>in this tutorial set we will see how to do Firestore CRUD operations with flutter. we will also see how to create simple queries in Firestore. this will be the 2nd Part of consist Firebase CRUD Operations With Flutter. Read the Previous one from <a href="https://medium.com/@srilalsachintha/firebase-crud-operations-with-flutter-part-1-document-reference-7ba44856da4c">here</a>.</p><p><strong>Note : All the Working State Code for these tutorials can be found in : </strong><a href="https://github.com/SrilalS/Flutter-Tutorial"><strong>https://github.com/SrilalS/Flutter-Tutorial</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*J60jFW4AkpiOcEfzr_MMGg.png" /></figure><p>We begin this tutorial with 2 Assumptions.</p><ol><li>You have successfully added Firebase to your project (Required)</li><li>You have read the Previous Tutorial (Optional)</li></ol><p>To Learn about how to add Firebase to flutter read the following first. (10mins)</p><p><a href="https://medium.com/@srilalsachintha/getting-started-with-firestore-flutter-android-31bee8c1412c">Getting Started with Firestore + Flutter (Android)</a></p><p>as is described in the previous tutorial there are 2 types of Firestore references available.</p><ol><li>Document Reference — in this we only refer to a single document in the database. this can be any document in our database as long as you have the path to that document. this will not retrieve the child collections inside the referred Document.</li><li>Collection Reference — here we refer to a whole collection. but similar to the document reference this will not retrieve the child Collections inside the referred Collection. <strong><em>we will discuss this in this tutorial.</em></strong></li></ol><p>Collections what holds documents. Collection can have many documents inside. these documents doesn’t have to have a same structure.</p><p><strong><em>A Single Document Can Have Many Collections. and those Collections can have many documents in them.</em></strong></p><p>So a Firestore Database has a architecture similar to Tree-Like Architecture but with Some Key Differences. Where the nodes are Documents and Siblings together is called a Collection. Consider the following graph. its the structure of one of Firestore databases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S2O3IoGgMKiz1YboPv29LQ.png" /></figure><p>The Circles are the Documents and Rectangle are Collections. this is very important when creating super complex databases with firestore. keeping you database clean is important.</p><p>Like all the other traditional databases this architecture has its ups and downs. but at the moment lets try to implement one.</p><h3>Initialization</h3><p>First initialized the Firestore above widget build method.</p><blockquote>final dbref = Firestore.instance;</blockquote><p>this database reference has no collection or document specified. because we are gonna be utilizing a root level collection we wont have to. but if you are using a deeper level database specify its path. <strong><em>(The path have to follow the patter of “Collection — Document — Collection — …” remember to end it in a Collection so otherwise you wont be able to utilize the collection)</em></strong></p><h3>Read From The Collection</h3><p>We can do this in many ways. my favorite one is Using a Stream. but in this tutorial we will do thing in a normal manner. but if you are interested in using a Stream read the following after this tutorial.</p><p><a href="https://medium.com/@srilalsachintha/using-flutter-streams-with-firestore-database-15f3b1322090">Using Flutter Streams with Firestore Database</a></p><p>First my Database looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CT4Giu7lRhgkNJn5Pf53bA.png" /></figure><p>Lets create a Function. it will get data from the Collection.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fb1244dda627328a269e364f7b77a3d/href">https://medium.com/media/0fb1244dda627328a269e364f7b77a3d/href</a></iframe><p>This will simply get all the documents from the collection ‘TUT’ and print the documents to the console. which looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*HTfmt8-RiXUATlW-eWqWMQ.png" /></figure><p>The Get-documents will return a List. which you can treat as a normal array.</p><p>to get to 0th Document you can go like,</p><blockquote>data.documents[0]</blockquote><p>to get to a special Field in one particular document lets say “N” according to my DB,</p><blockquote>data.documents[0][‘N’]</blockquote><p>See? its Easy!.</p><p>you can also get some properties of these data objects like <strong><em>documentId. this document id will come in handy in the ‘delete’ section of this tutorial</em></strong></p><h3><strong>Add/Update Data</strong></h3><p>adding data to a Collections is same as to a document. only difference is we provide the collection where it should be a child of.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/890db516431ef7d4ced3cfb3321fceee/href">https://medium.com/media/890db516431ef7d4ced3cfb3321fceee/href</a></iframe><p>In this example look at the second function. it save data in,</p><blockquote><strong>collection(‘TUT’).document(‘EOLX’).collection(‘SHIPS’)</strong></blockquote><p>But in database document ‘EOLX’ does not exists. but this will create that for you and save the data to the document under that ‘Ships’ collection.</p><h3>Delete</h3><p>here we get to the Tricky part. reason is we cant delete a collection!.</p><p>but we can delete documents in it to make up for that.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e37fc72d7ffbc97cdb50e890a70a44d2/href">https://medium.com/media/e37fc72d7ffbc97cdb50e890a70a44d2/href</a></iframe><p>what we do is we delete each document. we don’t need to know the name of the document as its provided by “documentID”.</p><h3>In the next tutorial we will discuss about Building Queries in Firestore.</h3><p>Note : All the Working State Code for these tutorials can be found in : <a href="https://github.com/SrilalS/Flutter-Tutorial">https://github.com/SrilalS/Flutter-Tutorial</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de374fe39bf0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase CRUD Operations With Flutter Part 1 (Document Reference)]]></title>
            <link>https://srilals.medium.com/firebase-crud-operations-with-flutter-part-1-document-reference-7ba44856da4c?source=rss-95b06d6d3ef1------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ba44856da4c</guid>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[databse]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[firestore]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Srilal S. Siriwardhane]]></dc:creator>
            <pubDate>Sat, 04 Apr 2020 10:04:18 GMT</pubDate>
            <atom:updated>2020-04-04T10:05:32.486Z</atom:updated>
            <content:encoded><![CDATA[<p>in this tutorial set we will see how to do Firestore CRUD operations with flutter. we will also see how to create simple queries in Firestore. this will be consist of 3 parts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4zFWh-plgr8UyM_9L4KuNg.png" /></figure><p>Note : All the Working State Code for these tutorials can be found in : <a href="https://github.com/SrilalS/Flutter-Tutorial">https://github.com/SrilalS/Flutter-Tutorial</a></p><h3>Step 1</h3><p>Add firestore to the Flutter Project. to do it please first read the following tutorial.</p><p><a href="https://medium.com/@srilalsachintha/getting-started-with-firestore-flutter-android-31bee8c1412c">Getting Started with Firestore + Flutter (Android)</a></p><h3>Step 2</h3><p>lets first create a firestore reference in our project. there are few ways to do this.</p><ol><li>Document Reference — in this we only refer to a single document in the database. this can be any document in our database as long as you have the path to that document. this will not retrieve the child collections inside the referred Document.</li><li>Collection Reference — here we refer to a whole collection. but similar to the document reference this will not retrieve the child Collections inside the referred Collection. <strong><em>we will discuss this in the next tutorial. link to that will be added after that has been published.</em></strong></li></ol><p>the reason why you will not get the sub Collection is that the queries in Firestore is shallow by default. it only look in the surface.</p><h3>First, lets explore Document Referencing.</h3><p>Take a look at my Database Structure first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KpliyhHv0wPq--WUN6c7Xw.png" /><figcaption>R-1</figcaption></figure><p>I have a Root Collection named ‘TUT’. inside it i have 4 documents. now i’m gonna refer to the first document in this collection.</p><p>create a document reference after the state creation,</p><blockquote>final docref = Firestore.instance.collection(‘TUT’).document(‘0’);</blockquote><p>note that i’m going through the collection to the specific document. this is what called document reference.</p><p><strong>now you can use ‘docref’ to do the CRUD operations. lets retrieve the data first.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2ebbfd75ecb5599daf73e10e3141a85/href">https://medium.com/media/e2ebbfd75ecb5599daf73e10e3141a85/href</a></iframe><p>in here data retrieved from the Firebase is retrieved as a data-snapshot named ‘doc’. under that we have ‘data’. it’s a String Map Data Structure. you have to go to the correct data via the correct path. doc-snapshot object named ‘doc’.</p><p>the ‘then’ operator activates after the data is fully retrieved. what happening here is that after the data is downloaded it assign the data to a doc-snapshot object.</p><p>for the sake of keeping things simple i’m assigning the ’N’ to a variable named ‘txt’. i also have ‘F’ in the Document. (Again Refer to the Screenshot of the Database.). let’s assign it to ‘faction’ variable.</p><blockquote>faction = doc.data[‘F’];</blockquote><p><strong>to Write data you can use ‘SetData’ this is the same thing used to update the document data. if you pass a field that is already there in the db it will be overwritten. if you go with the proper ways you can your ‘update’ instead of ‘SetData’.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1742ccbe03e79454587faa8c92a076c4/href">https://medium.com/media/1742ccbe03e79454587faa8c92a076c4/href</a></iframe><p>You can put Arrays in here. also you can put new data fields via this.</p><blockquote>’N’ : ‘Donnager’,</blockquote><blockquote>‘F’ : ‘MCRN’,</blockquote><blockquote>‘C’ : ‘Dreadnought’</blockquote><p>the ‘C’ will be added as a new field.</p><p><strong>if the document is missing in the database it will be created. document id is already given when we create the document reference.</strong></p><p><strong>To delete the document simply use the following. refer to the document reference and pass delete(</strong>)</p><blockquote>docref.delete();</blockquote><h3><strong>In the next tutorial we will discuss about collection reference.</strong></h3><p>Note : All the Working State Code for these tutorials can be found in : <a href="https://github.com/SrilalS/Flutter-Tutorial">https://github.com/SrilalS/Flutter-Tutorial</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ba44856da4c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Flutter Streams with Firestore Database]]></title>
            <link>https://srilals.medium.com/using-flutter-streams-with-firestore-database-15f3b1322090?source=rss-95b06d6d3ef1------2</link>
            <guid isPermaLink="false">https://medium.com/p/15f3b1322090</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[stream]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[firestore]]></category>
            <dc:creator><![CDATA[Srilal S. Siriwardhane]]></dc:creator>
            <pubDate>Mon, 30 Mar 2020 16:07:15 GMT</pubDate>
            <atom:updated>2020-03-30T18:42:52.412Z</atom:updated>
            <content:encoded><![CDATA[<p>Creating a Real time Data Stream is easy with Flutter Streams and Firestore.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gmnNgm7MfZW8Fe6j5YWspA.jpeg" /></figure><h3>Step 1 : Add Firestore to Your Flutter App</h3><p>Please read this article to see how to add Firestore to Your Flutter App</p><p><a href="https://medium.com/@srilalsachintha/getting-started-with-firestore-flutter-android-31bee8c1412c">Getting Started with Firestore + Flutter (Android)</a></p><h3>Step 2 : Coding! (yay!)</h3><p>First create a screen similar to this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ed1032379d7d80ba555624cc9681472/href">https://medium.com/media/5ed1032379d7d80ba555624cc9681472/href</a></iframe><p>Notice that its important to use either expanded widget or a container widget with defined size because we are going to build a ListView. ListViews Required to be contained in a Sized Container of some sort.</p><p>Then add a Stream builder,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecc95d06a19336f871bf91604a2e38e8/href">https://medium.com/media/ecc95d06a19336f871bf91604a2e38e8/href</a></iframe><p>Notice the ‘stream’. in here i’m referring to a collection named ‘TUT’ in my database. this will get all the documents inside that database and parse it into a snapshot. we will use this snapshot to get the data we need. in this collection i have 3 documents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zxx01DPsf1KHhLpBsuaDxg.png" /></figure><p>Now create a ListView.Builder() as below. what list view does is it will build one widget per all items in the data snapshot. for each widget it build it will assign a index. please notice that the document name and the index is totally unrelated.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7dd477eac238e34aea5e454b256781ab/href">https://medium.com/media/7dd477eac238e34aea5e454b256781ab/href</a></iframe><p>Notice the itemBuilder, inside it we have passed a parameter name index. its will be the unique id for the widgets.</p><p>also in the itemCount its important to set a limit. otherwise the list will keep building forever. so we put the limit of how many documents this snapshot has. but you are free to modify it as you want to.</p><blockquote>snapshot.data.documents[index][‘N’]</blockquote><p>to get to our data we goes in the following path,</p><p>Snapshot =&gt; Data =&gt; Documents =&gt;Document ID using Index =&gt; Specific Field of the Document we want</p><p>also if the database is empty it will return an empty snapshot. this will result in errors as the ListView needs at-least 1 items. to prevent that add a if condition to check the snapshot to the stream before returning the ListView as below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf28f60acec499bc808d6877ffcb22e2/href">https://medium.com/media/bf28f60acec499bc808d6877ffcb22e2/href</a></iframe><p>Now Run the Project on a internet enabled Phone or a Emulator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HBO_1JDByAbcuj-e0SKNmQ.png" /></figure><p>Now, if you added a another Document to the database, it will instantly show up on our list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GPaxhB_iMsnWR_qiTawykw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cvc21OKcC181kyHA7BeUJQ.png" /></figure><h3>Yay!</h3><p><a href="https://github.com/SrilalS">SrilalS - Overview</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15f3b1322090" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Firestore + Flutter (Android)]]></title>
            <link>https://srilals.medium.com/getting-started-with-firestore-flutter-android-31bee8c1412c?source=rss-95b06d6d3ef1------2</link>
            <guid isPermaLink="false">https://medium.com/p/31bee8c1412c</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[firestore]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Srilal S. Siriwardhane]]></dc:creator>
            <pubDate>Mon, 30 Mar 2020 14:52:57 GMT</pubDate>
            <atom:updated>2021-10-26T15:20:04.083Z</atom:updated>
            <content:encoded><![CDATA[<p>Firestore, the Firebase’s No-SQL Database + Flutter is a Excellent solution to bring Cloud database connected apps to life. in this tutorial we will discuss how to add Firestore to Flutter Project</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pDjpgfR8ZIvbEa-n6v2PDQ.jpeg" /></figure><h3>Adding Firebase to Flutter</h3><p>First Create a Firebase Project and Add Your App to Firebase. Change App ID to something Unique. (/android/app/build.gradle),</p><figure><img alt="for example" src="https://cdn-images-1.medium.com/max/720/1*E1psPRnwjQ6lLzPZX-hp3Q.jpeg" /><figcaption>Example App ID</figcaption></figure><p>Add it to the Firebase as follows,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*mGlSrpupZDX85GBOLB7T4w.jpeg" /><figcaption>Example</figcaption></figure><p>Download the Config file and put it in the “/android/app” folder as Follows,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/1*4YijtOY1WdO4Ynbu7onKFg.png" /></figure><p>In Your Flutter Project add the Following to the Project Level Gradle.build file. (/android/build.gradle).</p><blockquote>‘classpath ‘com.google.gms:google-services:4.3.3</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*fCvAuuyjSF8wzkCafestng.png" /></figure><p>Then Add the following to the end of the App level Build.gradle file (/android/app/build.gradle)</p><blockquote>apply plugin: ‘com.google.gms.google-services</blockquote><p>if You want to enable analytics as well, add the following to the dependencies section of this file.</p><blockquote>implementation ‘com.google.firebase:firebase-analytics:17.2.2</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*xBqBWrHWkQbUaM71OVLOgg.png" /></figure><p>Finally apply the Firestore plugin to flutter as below. (use the latest version from <a href="https://pub.dev/packages/cloud_firestore">https://pub.dev/packages/cloud_firestore</a> )</p><p>in the pubspec.yml file add the following to dependencies section.</p><blockquote><strong>cloud_firestore: ^0.13.4+2</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*-8i1MpZgzuhqq1525bKXQw.png" /></figure><p>if you are using a IDE with flutter plugin installed, once you save the changes it will automatically install the dependencies. otherwise run ‘flutter pub get’.</p><p>then in the dart file/screen you want to use Firestore, initialize the Firebase Firestore as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04b96e782edce9286843f322245be1d1/href">https://medium.com/media/04b96e782edce9286843f322245be1d1/href</a></iframe><p>Now Check back in the Firebase Console to See Your App.</p><p>Congratulation! You have added Firestore to your Flutter application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*So8y3zXoUb6ioWExVsscDA.png" /></figure><p><a href="https://github.com/SrilalS">SrilalS - Overview</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31bee8c1412c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>