<?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 Michelle Yi (Yulle) on Medium]]></title>
        <description><![CDATA[Stories by Michelle Yi (Yulle) on Medium]]></description>
        <link>https://medium.com/@yulleyi?source=rss-f10cb80e3a09------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TxgrQ2CkMxiKD33OtoUN4A.jpeg</url>
            <title>Stories by Michelle Yi (Yulle) on Medium</title>
            <link>https://medium.com/@yulleyi?source=rss-f10cb80e3a09------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 10:13:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yulleyi/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[The Ethical Challenges of Generative AI Applications]]></title>
            <link>https://yulleyi.medium.com/the-ethical-challenges-of-generative-ai-applications-8478ecdfe2a4?source=rss-f10cb80e3a09------2</link>
            <guid isPermaLink="false">https://medium.com/p/8478ecdfe2a4</guid>
            <category><![CDATA[responsible-ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[generative-ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai-ethics]]></category>
            <dc:creator><![CDATA[Michelle Yi (Yulle)]]></dc:creator>
            <pubDate>Sun, 17 Dec 2023 21:06:51 GMT</pubDate>
            <atom:updated>2023-12-17T21:06:51.384Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KEMAJMJgIc7u7u_B" /><figcaption>Photo by <a href="https://unsplash.com/@heytowner?utm_source=medium&amp;utm_medium=referral">JOHN TOWNER</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Generative AI (GenAI) techniques utilizing deep learning, neural networks, and other sophisticated machine learning have enabled tremendous advances in applications like computer vision, natural language processing, creative content generation, and more. However, the powerful capabilities of GenAI also raise critical ethical concerns regarding bias, transparency, accountability, and unintended societal consequences that must be proactively addressed as adoption continues growing rapidly.</p><p><a href="https://www.linkedin.com/pulse/ethical-conflicts-genai-world-don-depalma/">One report</a> breaks the types of ethical and moral concerns from AI into eight categories:</p><ol><li>Lack of explainability</li><li>Incorporation of human bias</li><li>Inherent English and European bias of training data</li><li>Lack and impact of regulation, now and in the future</li><li>Fear of apocalyptic outcomes</li><li>Lack of accountability by developers</li><li>Impact to the environment</li><li>Effect on labor, both in the data mines and the coming battlefield of machine versus human productivity</li></ol><p>This post provides an in-depth look at a handful of these key ethical issues posed by GenAI applications, highlighting recent problems, and analyzing potential solutions that allow the technology to be harnessed responsibly.</p><h3>Bias in GenAI Models</h3><p>One of the most pressing issues with GenAI systems is the perpetuation of unfair bias based on flaws in the training data or algorithms. Without careful consideration, models can learn and amplify existing societal biases around race, gender, age, ethnicity and more from biased data. This leads to discriminatory and prejudicial outcomes that can severely impact individuals and groups.</p><p>The below graphic from CSA Research illustrates how training data can lead to different types of bias in models. What makes this even more difficult to pin down is that most model developers never release even the metadata of the training data — if anything is open sourced, it is usually the fine-tuning data, which is highly curated and not representative of the full training set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*W7Qoaw8B9k1R_dUo" /><figcaption>CSA Research on the accidental and intentional biases in GenAI algorithms and training data.</figcaption></figure><p>How does this bias in the training data manifest in AI? <a href="https://www.nytimes.com/2019/05/14/us/facial-recognition-ban-san-francisco.html">Facial analysis models have demonstrated higher error rates for women and darker-skinned individuals</a>. <a href="https://www.reuters.com/article/us-amazon-com-jobs-automation-insight-idUSKCN1MK08G">Hiring algorithms have disadvantaged qualified candidates from minority backgrounds</a>. Predictive policing systems exhibit racial biases, leading to over-policing in marginalized communities.</p><p>If we look at generative AI in particular, <a href="https://www.bloomberg.com/graphics/2023-generative-ai-bias/">Bloomberg conducted a study</a> analyzing the outputs of Stable Diffusion text-to-image models and concluded, “The world according to Stable Diffusion is run by white male CEOs. Women are rarely doctors, lawyers or judges. Men with dark skin commit crimes, while women with dark skin flip burgers.</p><p>Stable Diffusion generates images using artificial intelligence, in response to written prompts. Like many AI models, what it creates may seem plausible on its face but is actually a distortion of reality. An analysis of more than 5,000 images created with Stable Diffusion found that it takes racial and gender disparities to extremes — worse than those found in the real world.” (<a href="https://www.bloomberg.com/graphics/2023-generative-ai-bias/">Link</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3FHP0GWfOzCTUef6CM7VrQ.png" /><figcaption><a href="https://www.bloomberg.com/graphics/2023-generative-ai-bias/">Bloomberg study</a> evaluating stable diffusion outputs based on skin color and job occupation.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wGVggpIfNRpW5MEUIBAWvQ.png" /><figcaption><a href="https://www.bloomberg.com/graphics/2023-generative-ai-bias/">Bloomberg study</a> evaluating stable diffusion outputs based on gender and job occupation.</figcaption></figure><p>Mitigating bias requires a multi-pronged approach. Some considerations include:</p><ul><li>Preparing training data: Curating data carefully, enhancing diversity, and correcting imbalances help reduce baked-in bias.</li><li>Fairness metrics: Rigorously defining, evaluating, and optimizing for fairness measures can quantify and mitigate algorithmic biases.</li><li>Techniques like adversarial debiasing explicitly optimizes models to reduce learned biases.</li><li>Inclusive design from the beginning can ensure that other use cases are considered. If data is primarily sourced from</li><li>Testing models in different environments. One framework that the <a href="https://www.weforum.org/agenda/2021/07/ai-machine-learning-bias-discrimination/">World Economic Forum offers is STEEPV</a>. “STEEPV analysis is a method of performing strategic analysis of external environments. It is an acronym for social (i.e. societal attitudes, culture and demographics), technological, economic (ie interest, growth and inflation rate), environmental, political and values. Performing a STEEPV analysis will help you detect fairness and non-discrimination risks in practice.” (<a href="https://www.weforum.org/agenda/2021/07/ai-machine-learning-bias-discrimination/">Link</a>)</li><li>Increasing diversity of data and teams building GenAI systems also helps offset biases. Many leading companies also have specific responsible AI teams or an AI ethics office that are engaged in the end-to-end process.</li></ul><p>There is no straightforward answer to solving these challenges, but a mix of these methods is starting to result in a set of best practices that work toward mitigating bias.</p><h3>Lack of Explainability and Interpretability</h3><p>With complex GenAI models like deep neural networks, it is often not possible to fully explain the rationale behind their decisions and predictions. However, understanding model behaviors, especially for sensitive applications in areas like finance, healthcare and criminal justice, is essential to ensure transparency, trace accountability, and avoid harm.</p><p>Several approaches to enhance interpretability are being explored:</p><ul><li>Local explainability focuses on explaining the reasons for specific individual predictions. This fosters user confidence in the system.</li><li>Rule-based explanations approximate the model logic through more interpretable rules and logical statements.</li><li>Highlighting influential input features helps users understand key data driving model outputs.</li><li>Model visualization techniques also provide valuable insights into model mechanics.</li></ul><h3>Legal and Regulatory Challenges</h3><p>GenAI systems must adhere to existing regulations around data privacy, consumer protections and anti-discrimination laws. However, the rapid evolution of AI capabilities presents policy challenges. Key steps needed include:</p><ul><li>Developing techniques like federated learning and differential privacy to preserve user privacy.</li><li>Establishing rigorous internal governance procedures for responsible data collection and use practices.</li><li>Advocating for regulations specific to GenAI systems, focused on transparency and accountability.</li><li>Adhering to ethical principles and frameworks on fairness and bias mitigation proposed by organizations like the EU and OECD.</li></ul><h3>Handling Hallucinations and Unintended Harmful Effects</h3><p>A known issue with large language models is the propensity to generate false information or content that promotes harmful stereotypes due to lack of real world knowledge and common sense. For instance, ChatGPT has produced toxic text, harmful misinformation and biased narratives when prompted.</p><p>Potential solutions to mitigate the risk of societal harm include:</p><ul><li>Adversarial testing to catch flaws and make models more robust.</li><li>Incorporating human feedback loops to correct bad behavior and guide the model.</li><li>Monitoring deployments and having human oversight over high-risk applications.</li></ul><h3>The Path Forward for Ethical GenAI</h3><p>Addressing the multifaceted ethical challenges posed by advancing GenAI requires sustained engagement between stakeholders from research, policy, industry and civil society. Key focal areas for enabling responsible GenAI include:</p><ul><li>Promoting participation of diverse voices in GenAI development and governance.</li><li>Supporting ongoing research to improve techniques and best practices for bias detection and mitigation, explainability, transparency, and error handling.</li><li>Advocating for regulatory policy development to ensure accountability and prevent harm from unchecked GenAI deployment.</li><li>Incentivizing ethical engineering practices focused on safety, transparency and fairness throughout the GenAI model lifecycle.</li></ul><p>With proactive efforts to put ethics at the core of the GenAI application development process, this transformative technology can uplift society in countless ways while minimizing risks from misuse and unintended consequences. All stakeholders have a shared responsibility to steer the GenAI revolution towards just and beneficial outcomes for all.</p><h3>Conclusion</h3><p>GenAI innovation carries tremendous potential for positive impact but also poses novel challenges we must thoughtfully address. This will require sustained collaboration and open dialogue between all parties to establish norms, incentives, guidelines and technical standards that enable GenAI technology to be deployed safely, ethically and for the benefit of humanity as a whole. If we make the necessary investments and tradeoffs, the GenAI applications of the future will represent the best of human values like compassion, creativity and justice.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8478ecdfe2a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[International Conference
on Computer Vision (ICCV) 2023: A retrospective]]></title>
            <link>https://yulleyi.medium.com/international-conference-on-computer-vision-iccv-2023-a-retrospective-4231a415410a?source=rss-f10cb80e3a09------2</link>
            <guid isPermaLink="false">https://medium.com/p/4231a415410a</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[foundation-models]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Michelle Yi (Yulle)]]></dc:creator>
            <pubDate>Tue, 05 Dec 2023 05:42:16 GMT</pubDate>
            <atom:updated>2023-12-05T05:42:16.558Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gWanDayvnVRxhxVT8OuRmQ.jpeg" /><figcaption>Photo of the Eiffel Tower taken by the author after the first night of ICCV 2023 in Paris.</figcaption></figure><p>Earlier this month, I had the privilege of attending the International Conference on Computer Vision (<a href="https://iccv2023.thecvf.com/">ICCV</a>) in Paris. After years of virtual research and other technology conferences, I was excited to revisit the experience of meeting those involved in the state-of-the-art in an open research-oriented forum like ICCV. It did not disappoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z7y0bCUfYcP1K4GohizdFA.jpeg" /><figcaption>General layout of ICCV 2023. Photo taken by author.</figcaption></figure><p>In this article, I share a retrospective covering:</p><ol><li>Some of the state-of-the-art research presented at the conference.</li><li>What excited me the most given other momentum in the Bay Area right now, and how this research can be incorporated into startups.</li><li>How I personally experienced the conference and what impressed me about the inclusiveness at ICCV 2023.</li><li>What we can take away from all of it to apply elsewhere.</li></ol><h3>1. A glimpse into the state-of-the-art</h3><p>It can be daunting to try to keep up with any given research area, especially the AI or machine learning space right now, when it seems like there are so many papers published to Arxiv daily. This makes it extremely difficult to either understand the macro direction of research trends or what is pertinent to the area of application an individual is working on.</p><p>Looking at the growth of submissions to ICCV alone, interest and research in the computer vision space has significantly increased since 2017.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ya_WSC3LEV_-eHVzgFHzHA.png" /><figcaption>Slide on trends in submissions from the Opening Remarks. Link <a href="https://iccv2023.thecvf.com/opening.remarks-40-7.php">here</a>.</figcaption></figure><p>Thankfully, the conference organizers and committees review a massive number of submissions and distill top papers by area into the orals presented at the event, with other relevant papers available via posters. Everyone has an opportunity to ask questions or discuss the papers with the authors.</p><p>This year, over 8,260 papers were submitted, of which 7,000~ reviewers narrowed down the pool to 2,161 accepted papers, and only 152 of them made it to orals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XiyP1CIFYDDWp5dY6hjBYQ.png" /><figcaption>Slide from the Technical Program section of the Opening Remarks. Link <a href="https://iccv2023.thecvf.com/opening.remarks-40-7.php">here</a>.</figcaption></figure><p>Taking a look at the accepted papers by the top ten topic areas, it is interesting to observe the following (<a href="https://iccv2023.thecvf.com/opening.remarks-40-7.php">from slide 21 here</a>) as we think about research trends in the computer vision:</p><ol><li><strong>3D from multiview and sensors</strong> — Includes simultaneous localization and mapping (SLAM) problems used in autonomous vehicles, robotics, 3D scene generation (neural radiance views), visual querying of video, augmented reality, and other use cases.</li><li><strong>Image and video synthesis</strong> — Generating relevant images and video.</li><li><strong>Transfer, low-shot, continual, long-tail learning</strong> — Creating performant deep models from a large number of images that follow a long-tailed class distribution. For example, these models can be easily biased towards dominant classes (e.g. cats and dogs) and perform poorly on tail classes (e.g. elephants).</li><li><strong>Low-level and physics based vision </strong>—Detailed features that are used to describe an image. Low-level vision includes considering things like corners, angles, and colors while physics based vision examines lighting, weathering, reflections, shape, etc.</li><li><strong>Vision and language</strong> — Targeting truly multimodal models where both vision augments language and language augments vision.</li><li><strong>Segmentation, grouping, and shape analysis</strong> — Grouping and segmentation processes with issues of shape perception and<br>representation that includes topics such as abstraction, interpolation between early and middle vision, ocluded figures, and contours.</li><li><strong>3D from a single image and shape-from-x</strong> —Reconstructing a 3D image from a single image or a shape using point clouds, geometry estimation, and other methods.</li><li><strong>Self-, semi-, meta-, unsupervised learning</strong> — Developing better models using self-directed (no labeled data), semi (some labeled data), or meta (changing the model based on learning) unsupervised learning.</li><li><strong>Recognition: Detection</strong> — Conducting object recognition and distinguishing subjects from the background.</li><li><strong>Adversarial attack and defense</strong> — Crafting perturbations to inputs that are difficult to perceive by humans but that cause models to product incorrect predictions (attack) and the corresponding methods to defend against this (defense).</li></ol><p>We will not delve into all of these papers, but there were a few trends and topic areas below that I wanted to highlight in more detail.</p><h4>Video and robotics as the future</h4><p>Video is really hard tech, but an area ripe for research and innovation.</p><ul><li>Used in two ways: exteroception which teaches us about the external world. We build mental models of behavior (physical, social..) and use them to interpret, predict, and control</li><li>Proprioception tells me about my current state in the world. Helps produce an episodic memory situated in space and time, and guides action in a context-specific way (ego centric views as area of research)</li></ul><p>Scaling token-based LLM-like models is not the answer, as this is not feasible in its current state. Capturing the essence of the 4D world and complexity translates to a much higher token count than text, as shown in the workshop slide example below. To address these, new methods should be developed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Hn2xB-rofv90FHlHQBKsg.jpeg" /><figcaption>Slide image on the future of computer vision workshop taken by the author at ICCV 2023.</figcaption></figure><p>Robotics is also a good focus area for further research because it combines everything that computer vision does with the difficulties of the physical world. For example, robotics must handle multiple spatiotemporal scales to even take an action where the finest scale can be understood as physical action, but the larger scales are best understood in terms of goals and intentionality. So, a single action can be thought of as a combination of movements and goals within the complex constraints of an environment.</p><h4>Data poisoning, safety, and adversarial attacks</h4><p>Foundation and deep learning models are vulnerable to multiple forms of attack, including data poisoning and adversarial attacks. While I do not see as much discourse on this subject as generative AI in practice, it is critical that we pay attention to research in this space to ensure applications built with (generative) AI are secure.</p><p>In fact, it is commonly known that CNNs are highly vulnerable to adversarial attacks and so there has been ongoing research into making CNNs more robust. <a href="https://arxiv.org/pdf/2308.10110v1.pdf">One paper proposes an adjustment to Mixture of Experts that adds adversarial training to it where the “robustness of routers<br>(i.e., gating functions to select data-specific experts) and<br>robustness of experts (i.e., the router-guided pathways defined by the subnetworks of the backbone CNN)” are alternately optimized for</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1iuGovd827D4cBuepboM_Q.png" /><figcaption>“Robust Mixture-of-Expert Training for Convolutional Neural Networks” ICCV 2023 slides on bi-level optimization. <a href="https://arxiv.org/pdf/2308.10110v1.pdf">Paper link</a>.</figcaption></figure><p>Using this framework, what the authors call “AdvMoE”, or Adversarial Mixture of Experts, <a href="https://arxiv.org/pdf/2308.10110v1.pdf">they see robustness increased up to 4% and training cost reduced by more than 50% while maintaining accuracy</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g3i7XArwpp6fh2SQIN2DLg.png" /><figcaption>“Robust Mixture-of-Expert Training for Convolutional Neural Networks” ICCV 2023 slides on performance comparisons. <a href="https://arxiv.org/pdf/2308.10110v1.pdf">Paper link</a>.</figcaption></figure><p>Vision-Language Pre-trained models (VLP) are also highly subject to adversarial attacks. As we see text-to-image models becoming more popular, it is important to recognize that now multimodal encoders can be exploited to transfer vulnerabilities across modalities.</p><p><a href="https://aps.arxiv.org/pdf/2307.14061.pdf">The paper “Set-level Guidance Attack: Boosting Adversarial Transferability of Vision-Language Pre-training Models” looks at the current state of vulnerabilities (below) and proposes a new method of attack that further exploits the multimodal nature of modern foundation models that also goes beyond white box (full access to model) settings.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1tmAaQqRagaEmLpf3aBRhQ.png" /><figcaption>“Set-level Guidance Attack: Boosting Adversarial Transferability of Vision-Language Pre-training Models” ICCV 2023 slides on the current state of adversarial attacks on VLP. <a href="https://aps.arxiv.org/pdf/2307.14061.pdf">Paper link</a>.</figcaption></figure><p>Compared to existing adversarial attacks, the proposed method, Set-level Guidance Attack (SGA), exploits the inherent need for transferability in these models by taking advantage of complex cross-modal interactions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PEg3wIeL2BMCrRqyfj5kyw.png" /><figcaption>“Set-level Guidance Attack: Boosting Adversarial Transferability of Vision-Language Pre-training Models” ICCV 2023 slides on the approach of Set-level Guidance Attacks. <a href="https://aps.arxiv.org/pdf/2307.14061.pdf">Paper link</a>.</figcaption></figure><p><a href="https://aps.arxiv.org/pdf/2307.14061.pdf">The paper cites impressive results that against fused (ALBEF) and aligned (TCL) multimodal modules can be up to 30% more effective on both white box and black box settings, and some improvement by architecture (CLIP VIT versus CLIP CNN) with CNNs performing worse.</a></p><p>On the other hand, some of these adversarial techniques are now also <a href="https://arxiv.org/abs/2310.13828">helping artists and others protect their art</a> from being wrongfully used for training.</p><p>There is also research that looks at evaluating how we assess data purification methods and how to apply more memory efficient techniques to improve adversarial purification. One paper in this space that stood out to me was “<a href="https://arxiv.org/pdf/2303.09051.pdf">Robust Evaluation of Diffusion-Based Adversarial Purification</a>”, where the authors instead of relying on the <a href="https://arxiv.org/pdf/2303.09051.pdf">adjoint method, which depends on the performance of an underlying numerical solver, the authors propose using a surrogate back propagation process to approximate gradients from iterative procedures, revealing that some recent works might be less robust than claimed</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jvn0r5U571NM7q8SPRK2mg.png" /><figcaption>Example of the full gradient calculation which can be challenging from a memory perspective. The surrogate process proposes an iterative approach. <a href="https://arxiv.org/pdf/2303.09051.pdf">Link</a>.</figcaption></figure><p>Attacks and defenses like these highlight the need to ensure models are robust to adversarial attacks as the adoption of text-to-image or other multimodal models increases and for further conversation on responsible applications of AI.</p><h4>NERF, poses, and the art of 3D</h4><p>When looking at augmented reality applications or images generated by vision models, some results can look like something straight out of a horror movie with how distorted the figures are. Humans appear in virtual reality with half of their bodies going through the bench, and generated human poses can have limbs appearing out of nowhere.</p><p>A lot of posters and papers presented made a lot of progress in this space, such as realistic reconstructions of poses like <a href="https://arxiv.org/pdf/2307.14570.pdf">here</a> incorporating actual constraints or those that incorporate real-world physics through kinematic observation, as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h--3ndmbk20NS4WJZbAnHQ.png" /><figcaption>An example of aphysically impossible generated model. Paper <a href="https://arxiv.org/pdf/2307.14570.pdf">link</a>.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U05_zkxQlC3SrmjCTOfUDQ.png" /><figcaption>Example of how taking into account knowledge of physics can product correct models. Paper <a href="https://arxiv.org/pdf/2307.14570.pdf">link</a>.</figcaption></figure><p>The progress in generating scenes (e.g., NERF), camera angles, models, and more has exciting implications for the future of video, robotics, augmented and virtual reality, and other applied areas of computer vision.</p><h3>2. Translating research into fuel for startups</h3><h4>Robotics as an allegory for teaching machines</h4><p>Networks have traditionally only been used in robotics to encode states for policy learning, but now roboticists are thinking about how to use the embedding space effectively and more creatively. That includes using LLMs to interact with the world, how to interpret the world through hierarchal representations, and how to efficiently represent image observations. Examples of compelling research include:</p><ul><li>Learning a controller in the latent space can make robot learning more data efficient e.g., learning functional distances based on goal and observation using contrastive learning: <a href="https://arxiv.org/pdf/2303.08135.pdf">https://arxiv.org/pdf/2303.08135.pdf</a></li><li>Learning to generalize grasping policies across geometry, pose, category, etc. Dynamic vision-based policy learning without knowing object state: <a href="https://arxiv.org/abs/2303.00938">https://arxiv.org/abs/2303.00938</a></li><li>Incorporating game theory for autonomous vehicle decision making: <a href="https://arxiv.org/pdf/2107.01110.pdf">https://arxiv.org/pdf/2107.01110.pdf</a></li></ul><p>Improving robotics also teaches us about teaching machines more generally — these are all things we also need if we want to apply foundation models more creatively either through reinforcement learning or other ways of automated decision-making based on observations.</p><h4>Personalization on another level</h4><p>Advancements in computer vision will also improve personalization on multiple levels. One creative way is through egocentric views from a given person’s perspective or scene. Example papers include:</p><ul><li>Egocentric video — EgoLoc: Revisiting 3D Object Localization from Egocentric Videos with Visual Queries Jinjie Mai, Abdullah Hamdi, Silvio Giancola, Chen Zhao, Bernard Ghanem</li><li>EMR-MSF: Self-Supervised Recurrent Monocular Scene Flow Exploiting Ego-Motion Rigidity Zijie Jiang, Masatoshi Okutomi</li><li>ClothPose: A Real-world Benchmark for Visual Analysis of Garment Pose via An Indirect Recording Solution Wenqiang Xu, Wenxin Du, Han Xue, Yutong Li, Ruolin Ye, Yan-Feng Wang, Cewu Lu</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bwjrcrnd8dJM48VM7yQPHQ.png" /><figcaption>Example of realistically fitted clothing based on <a href="https://openaccess.thecvf.com//content/ICCV2023/papers/Xu_ClothPose_A_Real-world_Benchmark_for_Visual_Analysis_of_Garment_Pose_ICCV_2023_paper.pdf">this paper</a>.</figcaption></figure><h4>Metadata and data management — retail analytics or what kinds of images that contain x are viewed</h4><p>With enhancements in computer vision, it also seems like there will be improved metadata and collection of metadata about how users are interacting with images or models. For example, <a href="https://arxiv.org/pdf/2304.02643.pdf">the Segment Anything paper results</a> will allow retailers and others to automatically extract and catalogue data about images that consumers are interacting with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QEL2s6NYntnKpH6FDd734w.png" /><figcaption>Illustration of how the Segment Anything model works. <a href="https://arxiv.org/pdf/2304.02643.pdf">Link</a>.</figcaption></figure><p>Other papers to look at include:</p><ul><li>Towards Open-Vocabulary Video Instance Segmentation Haochen<br>Wang, Cilin Yan, Shuai Wang, Xiaolong Jiang, Xu Tang, Yao Hu, Weidi Xie, Efstratios Gavves</li><li>Progressive Spatio-Temporal Prototype Matching for Text-Video<br>Retrieval Pandeng Li, Chen-Wei Xie, Liming Zhao, Hongtao Xie, Jiannan<br>Ge, Yun Zheng, Deli Zhao, Yongdong Zhang</li></ul><p>This is pretty exciting to consider how analytics can be improved to enhance the user experience.</p><h4>Including fairness, privacy, and explainability in vision applications</h4><p>A common approach to applying machine learning models now is to download an existing model (over 10,000 now on HuggingFace alone) and then fine-tune it. However, it is commonly recognized that there are social biases in all pre-trained models, and it is not apparent what those biases are. Nonprofits and research institutions are doing manual expert testing of some large language models (LLMs) to identify, <a href="https://hai.stanford.edu/news/assessing-political-bias-language-models">for example, political biases in some of the popular LLMs</a>. This is ultimately because we have no visibility into what data was used for training the original model (not fine-tuning data).</p><p>I found several interesting papers at ICCV related to these topics around mitigating bias, enhancing privacy, and practical methods we can apply as we implement generative AI systems to ensure fairer outcomes.</p><p>The authors of <a href="https://arxiv.org/pdf/2303.06167.pdf"><em>Overwriting Pretrained Bias with Finetuning Data</em></a><em> </em>approached the question of do the biases in pre-trained models transfer when you fine-tune them for downstream tasks, and, if so, how can people mitigate these? They specifically tackled the two most common forms of bias as defined in computer vision for the paper as seen in the image below from their presentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_wVcXKWonEr3kT34qVSbxQ.png" /><figcaption>The type of biases that are common in computer vision and that the authors try to address. <a href="https://arxiv.org/pdf/2303.06167.pdf">Link</a>.</figcaption></figure><p>This is also a useful framework for us more generally to consider, as many struggle to identify, quantify, and then create testing methods to address bias in generative AI and other types of machine learning.</p><p>What stands out in the paper is how they apply a scientific approach to setting up the experiment, testing, and then proposing a solution that can help mitigate the underlying biases of the original pre-trained model through careful fine-tuning. This type of testing is one we should rigorously do to test for bias before putting any out-of-the-box model into production.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rxZ-nb99XBp-BTUQoqYKdA.png" /><figcaption>Example of how the authors test for bias in pre-trained models and the associated metrics for measuring success: FPR (false positive rate) for spurious correlations and AUC (area under the curve) for underrepresentation. <a href="https://arxiv.org/pdf/2303.06167.pdf">Link</a>.</figcaption></figure><p>For the experiment, the study starts by analyzing bias as spurious correlations, where a sensitive attribute, like gender, might be incorrectly correlated with other attributes in a model. <a href="https://arxiv.org/pdf/2303.06167.pdf">Specifically, they look at those in the CelebA dataset labeled “male,” and that have eyebags as a spurious correlation. They also note that the image of “male” is also not gender inclusive, as this all relies on human or semi-automated (based on human input) labeling. However, by reducing the strength of the correlation with only 100 images in the eyebag example, the bias was reduced by half.</a></p><p>The key takeaway for this paper is that while pre-trained models may introduce bias into finetuned models, careful curation and manipulation of the finetuning dataset can correct for these biases, thus reconciling performance with fairness in model outcomes.</p><p>Another paper that impressed me at ICCV on this topic was <a href="https://arxiv.org/pdf/2309.05569.pdf"><em>ITI-GEN: Inclusive Text-to-Image Generation</em></a>. The authors here also target the biases in pre-trained models but from a different lens. Their goal is to align models to the human definition of inclusive, which they define as where <a href="https://arxiv.org/pdf/2309.05569.pdf">generative images are uniformly distributed across attributes of interest</a>. Below is an example the authors provide of the type of bias they then attempt to tackle:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bZujrqEi93CGJ5BwZg77jQ.png" /><figcaption>Example of poor distribution of attributes (e.g. eyeglasses, male, age, skin tone) from the authors. <a href="https://arxiv.org/pdf/2309.05569.pdf">Link</a>.</figcaption></figure><p>Many current solutions rely strictly on text-based debiasing. However, as previous research shows, there are limits to this kind of naive solution. <a href="https://arxiv.org/pdf/2309.05569.pdf">Since text-based debiasing can only convey so much information, it struggles with things like negation (not wearing glasses) or skin tone.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3SjVCCj0NFtJIxhlhIh_ng.png" /><figcaption>Example of the limitations of text-based debiasing such as negation. <a href="https://arxiv.org/pdf/2309.05569.pdf">Link</a>.</figcaption></figure><p>The novel approach from this paper is that, whereas many multimodal approaches have text augmenting images, they use images to augment text since detailed attributes (e.g., glasses) can be conveyed via information-rich images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2q07GoycVTgdFJ4uWXfh8g.png" /><figcaption>Example of the curated image datasets now available that can convey more diverse attributes to augment text-to-image instead of relying only on text to label image attributes. <a href="https://arxiv.org/pdf/2309.05569.pdf">Link</a>.</figcaption></figure><p><a href="https://arxiv.org/pdf/2309.05569.pdf">These visual differences can be translated through the method below into natural language, <strong>the output of which is actually inclusive tokens that can be used for alignment across models.</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2zLE5V2tLbN0D0EmJufWig.png" /></figure><p>Using these embeddings could help build more inclusive models in a much more scalable and generalizable way.</p><p>That being said, text-based debiasing and testing will still be a key component of any AI Safety strategy. Red teaming is still necessary to identify bias in foundation models. However, one of the hardest things to do is to actually uncover bugs. Models likely hallucinate more than we think they do, it is simply the case that we do not recognize every hallucination.</p><p>The authors of <a href="https://arxiv.org/pdf/2212.02774.pdf"><em>Adaptive Testing of Computer Vision Models</em></a><em> </em>propose a way to improve text-based testing and debiasing by using multimodal models to prompt us, the humans, with more creative and out-of-distribution (OOD) tests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E6YQvCg1SCExqJTNgaF8vw.png" /><figcaption>The authors summarize the current challenges in identifying bugs, bias, etc. in computer vision models. <a href="https://arxiv.org/pdf/2212.02774.pdf">Link</a>.</figcaption></figure><p>To address this problem, the authors propose <a href="https://arxiv.org/pdf/2212.02774.pdf">adaptive testing where the model suggests prompts using related embeddings that move toward useful (“hill climb”) tests that move closer to out-of-distribution questions as shown in the image below.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o3lSC7-UCizCANolIvtADQ.png" /><figcaption>Summary of approaches for current-state red-teaming and that which is assisted by a multimodal model. <a href="https://arxiv.org/pdf/2212.02774.pdf">Link</a>.</figcaption></figure><p>These can also be generalized to other images and models. Fine-tuning on the identified examples can also fix those bugs in the future, helping developers determine where to deploy and what is safe to implement through efficient testing.</p><p>The last paper I will mention in this section is <a href="https://arxiv.org/pdf/2212.01448.pdf"><em>PGFed: Personalize Each Client’s Global Objective for Federated Learning</em></a>. Federated learning has not been a prominent topic lately, but the authors of this paper <a href="https://arxiv.org/pdf/2212.01448.pdf">propose a more efficient and privacy-preserving method for using personalized models for federated learning with explicit knowledge transfer versus the conventional global model that is then distributed</a>. From the engineering side, I found this to make the use of federated learning more feasible for those interested in deploying in a more privacy-oriented way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fim6k9bpfj4plXUxesL6pA.png" /><figcaption>A new approach to federated learning emphasizes personalized models through explicit knowledge transfer for different clients instead of having a traditional global model dispersed to many clients. <a href="https://arxiv.org/pdf/2212.01448.pdf">Link</a>.</figcaption></figure><p>This section of papers was one of the most interesting to me and offered insights into how, on the applied side, we might translate research into better responsible AI practices.</p><h3>3. Diversity and inclusion at the conference</h3><p>Last but not least, I was personally very impressed with how the ICCV organizers supported diversity at the conference. It was significantly better than what I see at industry events run by the private sector.</p><p>Their support included everything from having an actual dedicated committee at all to travel scholarships, on-site healthcare, and even volunteer events at local high schools to teach young women about computer vision.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TPSTwLpPnIdAUpeaUnJnCQ.png" /><figcaption>Slide 8 on the diversity chairs and summary of efforts from the Opening Remarks. Link <a href="https://iccv2023.thecvf.com/opening.remarks-40-7.php">here</a>.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*puyN50UEjikn5K96ozPV8A.png" /><figcaption>Slide 14 breakdown of attendance over the years, including 18% that identify as women in 2023 from the Opening Remarks. Link <a href="https://iccv2023.thecvf.com/opening.remarks-40-7.php">here</a>.</figcaption></figure><p>Diversity efforts resulted in a better balance in gender not only because of the committee efforts for providing scholarships and support, but also through the highlighting of the actual work of underrepresented groups (not just by gender). This includes the <a href="https://sites.google.com/view/wicviccv2023/home?authuser=0">Women in Computer Vision</a> workshop, <a href="https://www.latinxinai.org/iccv-2023">LatinX in Computer Vision</a> workshop, and even an Arabic language speakers meetup.</p><p>It would be great to see big tech and others adopt similar efforts or policies to support better representation at tech conferences.</p><h3>Conclusion</h3><p>This retrospective turned out to be a lot longer than I expected, but I had so many thoughts after the conference that I wanted to capture at least some of them for future reference and to share more broadly.</p><p>I hope this provided an overview of some of the key research highlights (I intentionally spent more time on less known areas, otherwise the entire retrospective would have only been about NERFs or gaussian splats), and some of the things I’m excited about going forward.</p><h3>Reference</h3><ul><li><a href="https://sites.google.com/view/iccv-2023-outreach-event/">ICCV 2023 Outreach Event</a></li><li><a href="https://iccv2023.thecvf.com/">Accueil</a></li></ul><h4>Papers</h4><p>Gao, I., Ilharco, G., Lundberg, S., &amp; Ribeiro, M. T. (2023). Adaptive testing of computer vision models. In <em>Proceedings of the IEEE/CVF International Conference on Computer Vision</em> (pp. 4003–4014).</p><p>Kirillov, A., Mintun, E., Ravi, N., Mao, H., Rolland, C., Gustafson, L., … &amp; Girshick, R. (2023). Segment anything. <em>arXiv preprint arXiv:2304.02643</em>.</p><p>Lu, D., Wang, Z., Wang, T., Guan, W., Gao, H., &amp; Zheng, F. (2023). Set-level Guidance Attack: Boosting Adversarial Transferability of Vision-Language Pre-training Models. In <em>Proceedings of the IEEE/CVF International Conference on Computer Vision</em> (pp. 102–111). <a href="https://aps.arxiv.org/pdf/2307.14061.pdf">Link</a>.</p><p>Luo, J., Mendieta, M., Chen, C., &amp; Wu, S. (2023). PGFed: Personalize Each Client’s Global Objective for Federated Learning. In <em>Proceedings of the IEEE/CVF International Conference on Computer Vision</em> (pp. 3946–3956).</p><p>Shan, S., Ding, W., Passananti, J., Zheng, H., &amp; Zhao, B. Y. (2023). Prompt-Specific Poisoning Attacks on Text-to-Image Generative Models. <em>arXiv preprint arXiv:2310.13828</em>.</p><p>Wang, A., &amp; Russakovsky, O. (2023). Overcoming Bias in Pretrained Models by Manipulating the Finetuning Dataset. <em>arXiv preprint arXiv:2303.06167</em>.</p><p>Zhang, Y., Cai, R., Chen, T., Zhang, G., Zhang, H., Chen, P. Y., … &amp; Liu, S. (2023). Robust Mixture-of-Expert Training for Convolutional Neural Networks. In <em>Proceedings of the IEEE/CVF International Conference on Computer Vision</em> (pp. 90–101). <a href="https://arxiv.org/pdf/2308.10110v1.pdf">Link</a>.</p><p>Zhang, C., Chen, X., Chai, S., Wu, C. H., Lagun, D., Beeler, T., &amp; De la Torre, F. (2023). ITI-GEN: Inclusive Text-to-Image Generation. In <em>Proceedings of the IEEE/CVF International Conference on Computer Vision</em> (pp. 3969–3980).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4231a415410a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Small Tweaks, Big Gains: Adapting Large Language Models with LoRA]]></title>
            <link>https://yulleyi.medium.com/small-tweaks-big-gains-adapting-large-language-models-with-lora-70331064b91c?source=rss-f10cb80e3a09------2</link>
            <guid isPermaLink="false">https://medium.com/p/70331064b91c</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[adaptive-learning]]></category>
            <dc:creator><![CDATA[Michelle Yi (Yulle)]]></dc:creator>
            <pubDate>Fri, 28 Jul 2023 21:04:26 GMT</pubDate>
            <atom:updated>2023-07-28T21:04:26.620Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bxFe6JwSQxyOmz-d" /><figcaption>Photo by <a href="https://unsplash.com/@milatovar?utm_source=medium&amp;utm_medium=referral">Mila Tovar</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Imagine you have a very complex language machine. This machine has many internal pieces (called weights) that were optimized for <em>general use</em>.</p><p>Now you want to tweak this machine a bit to do a specific new task, like answering questions about a given subject area in-depth, that branches off from the main general purpose trunk. But if you try to adjust every single part of the machine separately, it will take a huge amount of effort and be really slow.</p><p>The key idea of the Low-Rank Adapter (LoRA) research is that you likely only need to tweak a few key parts of the machine to get it to do that new task well. <em>You don’t need to adjust every single part, but rather just a few in a very efficient way.</em></p><h3>Background</h3><p>In <a href="https://medium.com/@yulleyi/crunching-the-numbers-how-quantization-makes-large-models-byte-sized-73f81bc90789">my last article on quantization</a>, we discussed how low-rank adapters reduce barriers to hardware and increase performance through improved memory usage.</p><p>However, it is important to delve into the specifics of <a href="https://arxiv.org/pdf/2106.09685.pdf%C2%A0">the original Low-Rank Adaptation (LoRA) paper</a> in order to gain a deeper understanding of the overall concept that the authors are conveying, which extends beyond just performance and even beyond LLMs.</p><p>In general, it is very common for people to rely on fine-tuning to apply one large-scale model to many specific downstream tasks. You might want to apply a 40B parameter Falcon model to the domain of finance, and to do this you would go to the <a href="https://huggingface.co/tiiuae/falcon-40b">Hugging Face website</a>, take Falcon, and fine-tune it on your curated finance dataset. The problem with this, as the authors point out, is that the new model contains just as many parameters as the original model.</p><p>Said more mathematically in the paper, each fine-tuned model has “<a href="https://arxiv.org/pdf/2106.09685.pdf%C2%A0">a set of parameters ∆Φ whose dimension |∆Φ| equals |Φ0|. Thus, if the pre-trained model is large (such as GPT-3 with |Φ0| ≈ 175 Billion), storing and deploying many independent instances of fine-tuned models can be challenging, if at all feasible.</a>”</p><p>LoRA addresses this by doing the following:</p><blockquote>LoRA allows us to train some dense layers in a neural network indirectly by optimizing rank decomposition matrices of the dense layers’ change during adaptation instead, while keeping the pre-trained weights frozen…</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/165/0*xNtlFYgblYlnTN3v" /><figcaption>Small graphic from the original paper that demonstrates how LoRA works</figcaption></figure><p>Said again more mathematically:</p><blockquote>…the task-specific parameter increment ∆Φ = ∆Φ(Θ) is further encoded by a much smaller-sized set of parameters Θ with |Θ| &lt;&lt; |Φ0|. The task of finding ∆Φ thus becomes optimizing over Θ:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*SaFPvDotfMthbyEPUk6xhw.png" /><figcaption>Equation from the paper on optimizing for task-specific parameters where the number of trainable parameters |Θ| can be as small as 0.01% of |Φ0| in the case of 175B GPT-3.</figcaption></figure><blockquote>Where a pre-trained autoregressive language model PΦ(y|x) is parametrized by Φ Each downstream task is represented by a training dataset of context-target pairs: Z = {(xi , yi)}i=1,..,N , where both xi and yi are sequences of tokens.</blockquote><p>There are four major implications to this approach and research:</p><ol><li><strong>A pre-trained model can be shared and used to build many small LoRA modules for different tasks.</strong></li><li>LoRA can boost training efficiency and lower hardware requirements up to three times by using adaptive optimizers that eliminate the need to calculate gradients or maintain optimizer states for most parameters.</li><li>No inference latency.</li><li>Interoperable with other techniques. After conducting a thorough analysis of previous research in this field, the authors discovered that this approach could be integrated with other adapter or quantization methods.</li></ol><h3>Technical details and benchmarks</h3><p>The key technical idea in this research is that when you fine-tune a pre-trained model on a new task, the changes to the weights (represented by ∆W) have low intrinsic dimensionality or “rank” — you don’t need to update all the weights, just a small subset.</p><p>LoRA exploits this by parametrizing the weight updates ∆W using low-rank matrices. Concretely, they decompose ∆W = BA, where B and A are low-rank matrices that are trained on the downstream task while keeping the original pre-trained weights W frozen.</p><p>We can break this down into more detail across three components.</p><h4>1. Parametrization of ∆W:</h4><ul><li>For each weight matrix W in the model, the authors introduce two smaller matrices B and A to represent the update ∆W.</li><li>B has the same number of rows as W but much fewer columns (<em>rank r</em>).</li><li>A has r rows like B, and the same number of columns as W.</li><li>The update is computed as ∆W = BA, which is low-rank since B and A have <em>rank r.</em></li></ul><h4>2. Training:</h4><ul><li>The original weights W are frozen, and only B and A are trained.</li><li>This means the gradient is only computed for B and A, reducing memory and compute.</li><li>The forward pass computes h = Wx + ∆Wx = Wx + BAx.</li></ul><h4>3. Choice of rank r:</h4><ul><li>The authors find that a very low rank like r=1 or r=2 works surprisingly well for large models like GPT-3.</li><li>This suggests the intrinsic dimensionality needed for adaptation is very small.</li><li>They analyze the subspaces learned by different choices of r and find the top singular vectors overlap.</li></ul><p>To gauge the effectiveness of this method, the authors tested LoRA on the GLUE benchmark using RoBERTa, DeBERTa, GPT-2, and GPT-3 with other adapter methods. <em>In every instance, LoRA either matched or exceeded full fine-tuning, even with significantly fewer parameters</em>. For example, the authors were able to show a 10,000x reduction in trainable parameters for GPT-3, without any loss in performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XSAo0_CtW5QGj21c" /><figcaption>Summary table of benchmarks using different-sized LLMs and adaptation methods on the GLUE benchmark from the original paper.</figcaption></figure><p>The paper also analyzes the learned low-rank updates ∆W and shows they amplify certain directions in the original weight matrix W that are useful for the task but not emphasized during pre-training.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/0*RCkXJqW2TjhoBckc" /><figcaption>Demonstration of the amplification of certain weights in W that were not emphasized in pre-training.</figcaption></figure><blockquote><em>This suggests that the low-rank adaptation matrix potentially amplifies the important features for specific downstream tasks that were learned but not emphasized in the general pre-training model.</em></blockquote><p>In summary, by constraining the update ∆W to be low-rank, LoRA allows efficient adaptation of large pre-trained models with minimal performance loss. The key factors are the parametrization of ∆W, keeping W fixed, and finding that a very low rank (r) works well empirically.</p><h3>Conclusion</h3><p>Many people are interested in using LLMs to complete particular downstream tasks that are related to a specific field or situation. Nevertheless, fully fine-tuning an LLM is not always possible for everyone. Fortunately, LoRA provides a solution that not only offers efficient computing but also a scalable method for applications to specific new downstream tasks.</p><p>In summary, the benefits of this method include:</p><ul><li><strong>Easy to switch between tasks just by swapping the small LoRA modules.</strong></li><li>Much lower memory usage and faster training compared to full fine-tuning since we don’t need to store the optimizer state for the original parameters (frozen W).</li><li>Faster training as there are fewer gradients to compute.</li><li>No increase in inference latency or computation compared to the original model.</li></ul><p>Furthermore and worth following, this research is not just applicable to just LLMs:</p><blockquote>The principles outlined here apply to any dense layers in deep learning models, though we only focus on certain weights in Transformer language models in our experiments as the motivating use case.</blockquote><p><a href="https://arxiv.org/pdf/2106.09685.pdf%C2%A0">LoRA Paper.</a></p><p><a href="https://github.com/microsoft/LoRA">LoRA GitHub repository.</a></p><p><a href="https://huggingface.co/blog/peft">PEFT library on HuggingFace for ease of use.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70331064b91c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Crunching the Numbers: How Quantization Makes Large Models Byte-sized]]></title>
            <link>https://yulleyi.medium.com/crunching-the-numbers-how-quantization-makes-large-models-byte-sized-73f81bc90789?source=rss-f10cb80e3a09------2</link>
            <guid isPermaLink="false">https://medium.com/p/73f81bc90789</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[model-quantization]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Michelle Yi (Yulle)]]></dc:creator>
            <pubDate>Tue, 11 Jul 2023 20:15:30 GMT</pubDate>
            <atom:updated>2023-07-11T20:15:30.072Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>LLM-driven agents can help us do any number of tasks more efficiently, whether that is code review, writing emails, etc. Some tasks that we want them to do require more domain knowledge and expertise than others, so we might want to fine-tune our own model (more to come on this). There are <a href="https://huggingface.co/blog/falcon">40 billion parameter models now open-sourced</a>, so why not fine-tune these with your data and knowledge without feeding it into a third-party environment?</p><p>However, there are significant hardware (and financial) challenges to fully leveraging the power of LLMs, especially if we want to fine-tune them on our own proprietary data and expertise. Not everyone has several thousand (or tens of thousands of) dollars to invest in GPUs readily available, and they can be hard to provision on cloud service providers because of high demand.</p><p>Since we have been on the <a href="https://medium.com/@yulleyi/large-language-models-llm-with-long-term-memory-advancements-and-opportunities-in-genai-fcc3590f1c0e">topic of memory</a> lately, I want to share another area I am excited to see developments in related to a different area of memory, which is quantization. This is a very practical technique that can be used to help everyone take advantage of fine-tuning their own models and reduce barriers caused by hardware limitations.</p><h3>What is Quantization?</h3><p>In the context of machine learning, <a href="https://openaccess.thecvf.com/content_cvpr_2018/papers/Jacob_Quantization_and_Training_CVPR_2018_paper.pdf">quantization is a process that reduces the precision of the numerical weights used in a model</a>. The aim of quantization is to make the model smaller and more computationally efficient, at the cost of a slight reduction in accuracy.</p><p>In a typical neural network, the weights are represented as 32-bit floating-point numbers. However, these high-precision numbers can be memory-intensive and computationally demanding, especially for large models with billions of parameters.</p><p>Quantization tackles this problem by reducing the precision of these weights. For example, the weights might be rounded off to the nearest 16-bit, 8-bit, or even 4-bit numbers, as in the case of QLoRA, which we will explore in further detail.</p><p>This process greatly reduces the memory requirements and computational complexity of the model, which can make it possible to run large models on hardware with limited memory and computational capacity, such as mobile devices or single GPUs. Research shows that <a href="https://arxiv.org/pdf/2103.13630.pdf">“moving from floating-point representations to low-precision fixed integer values represented in four bits or less holds the potential to reduce the memory footprint and latency by a factor of 16x; and, in fact, reductions of 4x to 8x are often realized in practice in these applications.”</a></p><p>It’s important to note that while quantization can slightly degrade the performance of the model, research and engineering efforts such as QLoRA aim to mitigate this reduction in accuracy, so the quantized model performs nearly as well as the fully fine-tuned model that has no quantization. We should also note that quantization tends to work better with LLMs than it does with foundational computer vision models for various reasons, even though quantization was historically popularized more by the computer vision world.</p><h4>Historical Developments of Quantization</h4><p>Quantization in machine learning has evolved significantly over the years, driven by the need to deploy powerful deep learning models on devices with limited memory and computational power, like mobile phones or edge devices. In the early days of machine learning, models were small enough that quantization wasn’t really necessary.</p><p>However, as models started to grow, the need for more memory-efficient representations became evident. <a href="https://arxiv.org/pdf/2103.13630.pdf">Researchers started exploring lower-precision arithmetic, starting with 16-bit half-precision floating points. Below are some of the different types of quantization that can happen at different points of the model development process.</a></p><ol><li><strong>Fixed-Point Quantization</strong>: Fixed-point quantization, which involves representing weights as integers rather than floating-point numbers, was one of the earliest techniques used. <a href="http://proceedings.mlr.press/v48/linb16.pdf">One of the key papers here was the first to propose this technique to quantize deep convolutional networks (DCNs) and showed that fixed-point implementations of DCNs combined with optimization of bit-allocation across layers actually improved both memory and accuracy of them when benchmarked against CIFAR-10</a>. However, the limited dynamic range of fixed-point numbers can make this type of quantization less suitable for other networks.</li><li><strong>Floating-Point Quantization</strong>: Researchers also continued using lower-precision floating-point numbers, like the 16-bit half-precision floating points mentioned earlier. <a href="https://proceedings.neurips.cc/paper/2019/file/65fc9fb4897a89789352e211ca2d398f-Paper.pdf">One of the early publications to develop this technique was in using an 8-bit floating point representation (FP8) for training deep neural networks (DNNs), where they created a hybrid FP8 format to match different precision requirements in the model training process and a new end-to-end distributed training method</a>. This allowed for a larger dynamic range than fixed-point numbers and applicability to more DNN models.</li><li><strong>Weight Quantization</strong>: In weight quantization, weights between neurons are approximated and constrained, unlike traditional stochastic gradient descent, which evaluates the gradient on the current iterate. <a href="https://proceedings.neurips.cc/paper_files/paper/2015/file/3e15cc11f979ed25912dff5b0669f2cd-Paper.pdf">For example, BinaryConnect acknowledges that typical DNN computations involve a lot of multiplication and addition operations, also known as multiply-accumulate operations. In digital hardware, multipliers consume the most power and take up the most space. So, if the weights between neurons are binary during forward and backpropagation, these multiply-accumulate operations can be simplified into mere addition operations</a>. This results in efficient computation and improved performance.</li><li><strong>Activation Quantization</strong>: <a href="https://openaccess.thecvf.com/content_cvpr_2018/papers/Jacob_Quantization_and_Training_CVPR_2018_paper.pdf">Researchers then started quantizing not just the weights but also the activations in the network</a>. This allows for further memory savings and can also significantly speed up computation, especially on hardware designed for lower-precision arithmetic.</li><li><strong>Post-Training vs Training-Time Quantization</strong>: Initially, most quantization was done post-training, meaning the model was first trained at full precision and then quantized. However, this can lead to significant accuracy loss. <a href="https://arxiv.org/pdf/2302.04453.pdf">To address this, researchers started to use training-time quantization, where the model is trained with quantization from the start</a>. One example of this is the <a href="https://arxiv.org/pdf/2302.04453.pdf">Data Quality-aware Mixed-precision Quantization (DQMQ) framework, which adapts the quantization bit-width dynamically according to the quality of the data. This adaptation is guided by a bit-width decision policy that can be learned during training and is modeled as a hybrid reinforcement learning task</a>. This can allow the model to better adapt to the quantization, rewarding outcomes that improve performance.</li><li><strong>Advanced Techniques</strong>: More recently, researchers have been exploring more advanced quantization techniques. For example, this paper from NVIDIA on <a href="https://arxiv.org/pdf/1710.03740.pdf%EF%BC%89%E3%80%82">mixed-precision training</a> proposes using both single and half precisions. <a href="https://arxiv.org/pdf/1710.03740.pdf%EF%BC%89%E3%80%82">They keep a single-precision copy of the weights that accumulate the gradients after each optimizer step; this copy is then rounded to half-precision for the forward and backward propagation steps. Loss scaling helps ensure smaller half-precision values do not vanish</a>. <a href="https://arxiv.org/pdf/2305.14314.pdf">QLoRA</a> uses a novel double quantization technique to further reduce memory usage.</li></ol><p>It is no surprise that with the development of foundation models, such as LLMs, this area has regained much focus, and new research on these various methods continues to be published. One of the recent publications that has shown significant promise at the implementation level is QLoRa, and by proxy LoRA, which we will discuss next in the context of LLMs specifically.</p><h3>Quantizing LLMs: LoRa and QLoRa</h3><p><a href="https://arxiv.org/pdf/2305.14314.pdf">QLoRA is an efficient fine-tuning technique for machine learning models, specifically for large language models</a>. It is designed to allow LLMs to be fine-tuned on a single GPU with limited memory, even when the model itself has a huge number of parameters, up to 65 billion.</p><p>The key technique QLoRA uses is backpropagation of gradients through a 4-bit quantized version of the pre-trained model into structures called Low Rank Adapters (<a href="https://arxiv.org/pdf/2106.09685.pdf">LoRA</a>). <a href="https://arxiv.org/pdf/2106.09685.pdf">In practice, an adapter is a small module that is inserted into each layer of a pre-existing model. The adapter is trained to adapt the inputs of the layer to the specific task at hand, while the pre-existing parameters of the model are kept fixed (or “frozen”). They are referred to as “Low Rank” because of their origins in linear algebra — a matrix that can be factored into a product of two matrices with smaller dimensions. This factorization significantly reduces the number of parameters that need to be learned and stored.</a></p><p>This quantization process allows the model to drastically reduce memory usage without a significant drop in task performance. The paper cites that <a href="https://arxiv.org/pdf/2305.14314.pdf">QLoRA reduces the average memory requirements of finetuning a 65B parameter model from &gt;780GB of GPU memory to &lt;48GB without degrading the runtime or predictive performance compared to a 16-bit fully finetuned baseline.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*Fop_tGsNLQelOSzVd2aylg.png" /><figcaption>Illustration of how the QLoRA process works compared to others from the original paper <a href="https://arxiv.org/pdf/2305.14314.pdf">here</a>. The key differences include quantizing to 4-bits and adding in optimizers that reduce memory spikes.</figcaption></figure><p>The QLoRA-based model, named <em>Guanaco</em>, has performed very well on the Vicuna benchmark, which measures the performance of conversational AI models. Despite its more compact size and the reduced memory required for its fine-tuning, <a href="https://arxiv.org/pdf/2305.14314.pdf">it achieves nearly the same performance as ChatGPT.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*6GxdwL8hQQIS9FLVZAcczg.png" /><figcaption>Benchmark figures from the paper based on a tournament they conducted on best responses to a prompt with human raters and GPT-4. Full details <a href="https://arxiv.org/pdf/2305.14314.pdf">here</a>.</figcaption></figure><p>QLoRA introduces three novel techniques to save memory and achieve this performance:</p><ol><li><strong>4-bit NormalFloat (NF4)</strong>: A new data type that’s optimal for normally distributed weights. By using only 4 bits, it saves a lot of memory compared to higher precision data types.</li><li><strong>Double quantization</strong>: An extra layer of quantization on top of the 4-bit quantization. This involves quantizing the quantization constants using the LoRA method, leading to even further memory savings.</li><li><strong>Paged optimizers</strong>: These manage memory usage by handling memory spikes that might otherwise cause problems. They make sure that the memory usage stays within the limit of the GPU memory.</li></ol><p><a href="https://arxiv.org/pdf/2305.14314.pdf">QLoRA was used to fine-tune more than 1,000 models, including different types of models and models of different scales, some of which would be unmanageable using traditional fine-tuning techniques</a>. They found that QLoRA could produce state-of-the-art results even with smaller models and small high-quality datasets.</p><p>However, they also found that current chatbot benchmarks aren’t always reliable for accurately measuring chatbot performance. They provided a detailed breakdown, or “<a href="https://arxiv.org/pdf/2305.14314.pdf">lemon-picked analysis</a>”, of where <a href="https://arxiv.org/pdf/2305.14314.pdf"><em>Guanaco</em> doesn’t perform as well as ChatGPT e.g., mathematics, obscure questions, and some types of assumptions as part of the preamble</a>. The authors also recognize that there is a need for more testing at larger scales, as this is still a computationally-intensive task.</p><p>Finally, they released all of their models and the code used to implement QLoRA, including the CUDA kernels required for 4-bit training. Check out their GitHub repository <a href="https://github.com/artidoro/qlora">here</a> for details.</p><p>I personally tried implementing their code to quantize several fine-tuned LLMs in the 7B (works even on a free-tier single instance GPU in <a href="https://colab.google/">Google Colab</a> or <a href="https://www.kaggle.com/">Kaggle</a>) to the 40B parameter range (check out <a href="https://vast.ai/faq">Vast.ai</a> for cheaper GPU alternatives, or if you have some you can rent out!) with significantly reduced hardware requirements and minimal impact on performance for specific use cases. Techniques like QLoRA (and LoRA) should be further developed and can truly unlock the potential of LLMs for a larger pool of people.</p><h3>Conclusion</h3><p>With the development of increasingly larger foundation models, and LLMs in particular, the area of quantization and its role in memory-efficient processing has become critical to truly democratizing the power of LLMs to a broader audience. These techniques, developed initially to make deep learning more efficient on mobile and edge devices, are now helping to make LLMs and specifically using <em>fine-tuned</em> LLMs more accessible to all.</p><h3>References</h3><p>Courbariaux, M., Bengio, Y., &amp; David, J. P. (2015). Binaryconnect: Training deep neural networks with binary weights during propagations. <em>Advances in neural information processing systems</em>, <em>28</em>. <a href="https://proceedings.neurips.cc/paper_files/paper/2015/file/3e15cc11f979ed25912dff5b0669f2cd-Paper.pdf">Link</a>.</p><p>Dettmers, T., Pagnoni, A., Holtzman, A., &amp; Zettlemoyer, L. (2023). Qlora: Efficient finetuning of quantized llms. <em>arXiv preprint arXiv:2305.14314</em>. <a href="https://arxiv.org/pdf/2305.14314.pdf">Link</a>.</p><p>Gholami, A., Kim, S., Dong, Z., Yao, Z., Mahoney, M. W., &amp; Keutzer, K. (2021). A survey of quantization methods for efficient neural network inference. <em>arXiv preprint arXiv:2103.13630</em>. <a href="https://arxiv.org/pdf/2103.13630.pdf">Link</a>.</p><p>Hu, E. J., Shen, Y., Wallis, P., Allen-Zhu, Z., Li, Y., Wang, S., … &amp; Chen, W. (2021). Lora: Low-rank adaptation of large language models. <em>arXiv preprint arXiv:2106.09685</em>. <a href="https://arxiv.org/pdf/2106.09685.pdf%C2%A0">Link</a>.</p><p>Jacob, B., Kligys, S., Chen, B., Zhu, M., Tang, M., Howard, A., … &amp; Kalenichenko, D. (2018). Quantization and training of neural networks for efficient integer-arithmetic-only inference. In <em>Proceedings of the IEEE conference on computer vision and pattern recognition</em> (pp. 2704–2713). <a href="https://openaccess.thecvf.com/content_cvpr_2018/papers/Jacob_Quantization_and_Training_CVPR_2018_paper.pdf">Link</a>.</p><p>Lin, D., Talathi, S., &amp; Annapureddy, S. (2016, June). Fixed point quantization of deep convolutional networks. In <em>International conference on machine learning</em> (pp. 2849–2858). PMLR. <a href="http://proceedings.mlr.press/v48/linb16.pdf">Link</a>.</p><p>Micikevicius, P., Narang, S., Alben, J., Diamos, G., Elsen, E., Garcia, D., … &amp; Wu, H. (2017). Mixed precision training. <em>arXiv preprint arXiv:1710.03740</em>. <a href="https://arxiv.org/pdf/1710.03740.pdf%EF%BC%89%E3%80%82">Link</a>.</p><p>Sun, X., Choi, J., Chen, C. Y., Wang, N., Venkataramani, S., Srinivasan, V. V., … &amp; Gopalakrishnan, K. (2019). Hybrid 8-bit floating point (HFP8) training and inference for deep neural networks. <em>Advances in neural information processing systems</em>, <em>32</em>. <a href="https://proceedings.neurips.cc/paper/2019/file/65fc9fb4897a89789352e211ca2d398f-Paper.pdf">Link</a>.</p><p>Van Den Oord, A., &amp; Vinyals, O. (2017). Neural discrete representation learning. <em>Advances in neural information processing systems</em>, <em>30</em>. <a href="https://proceedings.neurips.cc/paper/2017/file/7a98af17e63a0ac09ce2e96d03992fbc-Paper.pdf">Link</a>.</p><p>Wang, Y., Guo, J., Guo, S., &amp; Zhang, W. (2023). Data Quality-aware Mixed-precision Quantization via Hybrid Reinforcement Learning. <em>arXiv preprint arXiv:2302.04453</em>. <a href="https://arxiv.org/pdf/2302.04453.pdf">Link</a>.</p><p>Zhou, C., Liu, P., Xu, P., Iyer, S., Sun, J., Mao, Y., … &amp; Levy, O. (2023). Lima: Less is more for alignment. <em>arXiv preprint arXiv:2305.11206</em>. <a href="https://arxiv.org/pdf/2305.11206.pdf">Link</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73f81bc90789" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Large Language Models (LLM) with Long-Term Memory: Advancements and Opportunities in GenAI…]]></title>
            <link>https://yulleyi.medium.com/large-language-models-llm-with-long-term-memory-advancements-and-opportunities-in-genai-fcc3590f1c0e?source=rss-f10cb80e3a09------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcc3590f1c0e</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Michelle Yi (Yulle)]]></dc:creator>
            <pubDate>Fri, 07 Jul 2023 21:26:44 GMT</pubDate>
            <atom:updated>2023-07-07T21:26:44.590Z</atom:updated>
            <content:encoded><![CDATA[<h3>Large Language Models (LLM) with Long-Term Memory: Advancements and Opportunities in GenAI Applications</h3><h3>Introduction</h3><p>Large language models (LLMs) are advanced machine learning models with many parameters trained on a massive library of text. From a technical standpoint, language modeling (LM) is a crucial technique for generating advances in machine language intelligence. The primary objective of LM is to develop models that accurately estimate the probability of generating word sequences, thereby facilitating the estimation of probabilities associated with future tokens or those that are absent.</p><p>Recent developments in natural language processing and related disciplines have been facilitated by large language models (LLMs) such as ChatGPT. Research has demonstrated that when these models reach a certain scale, they <a href="https://proceedings.neurips.cc/paper_files/paper/2022/file/9d5609613524ecf4f15af0f7b31abca4-Paper-Conference.pdf">exhibit emergent behaviors, such as the capacity to engage in “reasoning”.</a> By incorporating models with <a href="https://proceedings.neurips.cc/paper_files/paper/2022/file/9d5609613524ecf4f15af0f7b31abca4-Paper-Conference.pdf">“chain-of-thought”</a> methods, i.e. reasoning examples or a straightforward prompt such as “Let’s think step by step,” these models can respond to questions with explicit logical steps.</p><p>One example we can look at that LLMs can handle is: <a href="https://arxiv.org/abs/2002.06177">“All whales are mammals, and all mammals have kidneys; therefore, all whales have kidneys.”</a> This particular example has generated significant excitement within the research community. The reason behind this enthusiasm is that the ability to reason logically is considered a fundamental characteristic of human intelligence and is often seen as lacking in current artificial intelligence systems.</p><p>While large language models (LLMs) have demonstrated remarkable performance on specific reasoning tasks, their generalizable reasoning capabilities and the extent to which they can engage in reasoning processes remain debatable. This uncertainty has triggered ongoing debates and different perspectives among the research community. For instance, some say that LLMs are “adequate zero-shot reasoners”, whereas other authors have concluded that “<a href="https://proceedings.neurips.cc/paper_files/paper/2022/file/8bb0d291acd4acf06ef112099c16f326-Paper-Conference.pdf">LLMs are still a long way from achieving adequate results on everyday planning/reasoning tasks that pose no challenge for humans.</a>”</p><p>In this article, we begin to explore the role of memory in advancing LLMs, some emerging architectures, and opportunities for their application. Subsequent articles will cover more of the implementation details and specifics of different approaches and design patterns.</p><h3>LLMs with Long Term Memory</h3><p>LLMs are founded on an architecture for deep learning called the Transformer Model. The <a href="https://proceedings.neurips.cc/paper_files/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf">Transformer Model</a> employs self-attention mechanisms to determine the relationships between words or elements in a text sequence. This and <a href="https://arxiv.org/abs/1409.0473">related foundational developments</a> enable the model to comprehend and generate text with <a href="https://arxiv.org/pdf/2306.07174.pdf">greater context and coherence</a>.</p><p>To improve the capabilities of LLMs, researchers have considered incorporating mechanisms for long-term memory into these models. Long-term memory allows a model to store information for an extended period and utilize it when developing responses. There are currently two primary ways in which long-term memory can be incorporated.</p><p>One way that LLMs can incorporate long-term memory is by utilizing additional memory components, such as third-party databases including vector databases or (knowledge) graph databases. These components store factual data or embeddings that the model can access and use to generate text. The LLM can provide more precise and accurate responses by accessing this external memory.</p><p>Alternatively, memory can be incorporated into the model itself. For instance, the model may include an internal memory module (e.g., an index, a modified attention mechanism, etc.) that stores pertinent data during text processing. This internal memory can be modified and accessed to affect the model’s behavior. <a href="https://arxiv.org/abs/2304.10182">LLMs can demonstrate more consistent behavior and create appropriate responses for the given context by employing long-term memory in the actual model architecture.</a></p><h3>Architectural Design Considerations:</h3><p>Several architectural factors must be accounted for when developing LLMs with long-term memory. A few crucial considerations include:</p><ul><li><strong>Storage</strong>: The model’s memory should be large enough to store and retrieve pertinent information. The memory component’s size and architecture must be designed to accommodate the intended quantity of long-term data.</li><li><strong>Storage update</strong>: The model should include mechanisms for revising long-term memory in response to new input or data. This makes sure the memory is up-to-date and pertinent to the current context.</li><li><strong>Memory retrieval</strong>: The model requires efficient access and retrieval mechanisms for information stored in long-term memory. This retrieval process must be quick and precise so that the model can utilize the stored information during text generation without causing excess latency. This is especially true of methods utilizing external memory components, such as a third-party database.</li><li><strong>Incorporation with attention mechanisms</strong>: The model’s long-term memory should be incorporated with self-attention mechanisms. This enables the model to pay attention to pertinent portions of memory during text generation and make informed decisions based on the stored data.</li><li><strong>Training and Selection</strong>: Training LLMs with long-term memory demands a thorough understanding of how the memory is updated and utilized during training. To ensure efficient learning and utilization of stored data, robust selection techniques must account for the memory component.</li></ul><p>To that end, there are some new emerging architectures in the research community that try to account for these design considerations, while also improving cost and long-memory efficiency. One example, as seen in the following diagram, is adding a decoupled caching layer that stays fresh through training to supplement pre-trained models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/0*fb7O_linBXjDTysw" /></figure><p><em>Example architecture with augmented memory mechanism from </em><a href="https://arxiv.org/pdf/2306.07174.pdf"><em>Wang et al. (2023)</em></a></p><p>Another example shown below is the “Hyena Hierarchy,” which looks at breaking the quadratic barrier (causes scaling cost and compute time) of the attention mechanism by replacing the attention mechanism with subquadratic operators in a new dense, attention-free architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/0*YJ9EjdKTiBi6ox6q" /></figure><p><em>Example architecture using Hyena Hierarchy from </em><a href="https://arxiv.org/abs/2302.10866"><em>Poli et al. (2023)</em></a></p><p>These new paradigms and others coming out of the research and developer communities will be explored in further detail in future articles.</p><h3>Advancements and Opportunities in GenAI Applications</h3><p>The development of LLM-based GenAI applications has created new opportunities in numerous fields. As models become more adept at comprehending and remembering extended context, they can be utilized in increasingly complex and dynamic situations.</p><h3>Advancements in LLMs</h3><h4>Improving Context Understanding and Coherence in Text Generation</h4><p>The capability of GenAI applications to comprehend and generate text with enhanced context comprehension and coherence is one of their significant benefits. Modern LLMs, such as GPT-3.5 and above, have been trained on enormous quantities of data and may produce more appropriate and contextually appropriate responses. This enhancement enables more meaningful and precise interactions across multiple applications. This is furthered by the improvement of long-term memory mechanisms in areas such as those listed below.</p><ul><li><strong><em>Improved Accuracy and Specificity of Generated Responses:</em></strong></li></ul><p>The ability to fine-tune LLMs to acquire domain-specific expertise is one of the main benefits of GenAI applications. This goes beyond using only “preamble” or prompt engineering of an existing general LLM. By introducing the model to an enormous amount of data from a specific domain and tuning its parameters accordingly, we can train it to generate responses demonstrating a profound understanding of the topic. This specialization permits the model to provide more precise and contextually pertinent data.</p><p>On top of this, GenAI applications excel at information retrieval by employing these refined LLMs. By integrating mechanisms for long-term memory, these models may retrieve information with even better precision and relevance to the collected data, allowing the model to provide more accurate results to user queries.</p><ul><li><strong><em>Consistent Behavior and Reduction of Biases in LLMs:</em></strong></li></ul><p>Ensuring the consistency of, reducing hallucinations in, and eliminating biases within LLMs present enormous challenges. By utilizing better long-term memory mechanisms in LLMs, we can potentially improve bias in the following areas:</p><ul><li><em>Bias Reduction</em>: AI models acquire knowledge from data. The model will exhibit the same biases if the training data contains biases. Therefore, it is essential to curate a balanced and diverse training dataset. This requires precise data selection and evaluation to reduce implicit and explicit bias. Better long-term memory can improve the quality of outputs, reducing hallucinations and potentially biased outputs.</li><li><em>Fairness Evaluation</em>: Implementing and monitoring impartiality metrics can assist in quantifying bias. These metrics may serve as guidelines for the LLM’s behavior. Part of this also requires looking at the input (prompts) and outputs (responses) of the LLM at the user interaction level. This is where having an external long-term memory mechanism can be helpful as well. Conducting regular audits and evaluations throughout the entire process is essential to identify and correct any biases in the AI system.</li><li><em>Algorithmic Transparency</em>: Most LLMs are still very opaque in their decision-making. While there are explainable AI techniques that can help identify inherent biases by revealing how the model makes its decisions, there are also opportunities with emerging memory mechanisms within model architectures that could make models more transparent. For example, <a href="https://direct.mit.edu/neco/article/35/3/309/114731">techniques that can freeze or update only certain parts of a model or its running long-term memory could keep models up-to-date</a> but also make sure they adhere to regulations such as the “right to be forgotten” without requiring retraining.</li></ul><h3>Opportunities:</h3><p>Generative AI is a subfield of artificial intelligence that concentrates on developing models and systems to generate new and unique content. In contrast to traditional AI systems, intended to identify and categorize existing data, generative AI seeks to generate new data that mimics the trends and features of the training data to which it has been exposed. Having more advanced memory in LLMs powering generative AI applications can significantly impact the following areas:</p><ul><li><strong><em>Content Creation:</em></strong> AI has significantly advanced in generating written content, including poetry, news articles, and technical papers. For instance, businesses can use AI to generate marketing copy or provide content suggestions, drastically reducing the time spent creating and modifying content. In addition, Generative AI models use methods such as generative adversarial networks (GANs), variational autoencoders (VAEs), and RNN’s to generate new content such as pictures, videos, text, and music. These models discover the fundamental patterns and frameworks of the training data and then use this information to produce new samples with comparable features. Having longer-term memory can help evolve content based on a longer context and reference back key elements from previous statements or works.</li><li><strong><em>Personalized Experiences</em>:</strong> Whether it be through the generation of personalized purchasing experiences or the creation of unique learning paths in education, Generative AI has the potential to personalize numerous aspects of our everyday lives. Improved memory would provide better personalization capabilities that could account for a longer period of time of preferences.</li><li><strong><em>Drug Discovery: </em></strong>Generative AI is already used to forecast the potential properties of molecules and generate new potential drug candidates in drug discovery. <a href="https://blogs.nvidia.com/blog/2023/06/27/insilico-medicine-uses-generative-ai-to-accelerate-drug-discovery/">This already has proven to significantly accelerate the drug discovery and development process</a>. Better long-term memory could increase the potential of these applications even more by incorporating more context about each molecule or drug candidate.</li></ul><h3>Conclusion</h3><p>Despite the exciting developments and opportunities, substantial challenges lie ahead. It is computationally challenging to train these advanced LLMs, and their complexity makes them more difficult to comprehend and control. Researchers are still discovering how to manage these trade-offs effectively. A key part of this discussion is the role of long-term memory in LLMs and GenAI more broadly.</p><p>Concerns regarding the ethical implications of such advanced AI models continue to grow. There are still unresolved privacy concerns, particularly when considering models that can remember information for extended periods. Also of critical concern is whether these models will remember and perpetuate detrimental or biased behavior.</p><p>Researchers, developers, regulators, and end-users must collaborate to address these challenges. In order to responsibly uncover every potential of LLM-based GenAI applications, it is necessary to develop novel methods for model comprehension, ethical standards for AI usage, and more effective privacy protection methods.</p><p>In conclusion, the rapid development of GenAI applications based on developments in memory and context represents a significant milestone in the evolution of AI. As we continue to stretch the limits of what AI can recall, reason over, and recognize, the distinction between human and artificial intelligence tasks becomes increasingly fuzzy. The developments in LLMs offer intriguing opportunities in various industries but also present new challenges. As we continue to evolve artificial intelligence, the road ahead is stimulating and full of potential.</p><h3>References</h3><p>Bahdanau, D., Cho, K., &amp; Bengio, Y. (2014). Neural machine translation by jointly learning to align and translate. <em>arXiv preprint arXiv:1409.0473</em>. <a href="https://arxiv.org/abs/1409.0473">Link</a>.</p><p>Kojima, T., Gu, S. S., Reid, M., Matsuo, Y., &amp; Iwasawa, Y. (2022). Large language models are zero-shot reasoners. <em>Advances in neural information processing systems</em>, <em>35</em>, 22199–22213. <a href="https://proceedings.neurips.cc/paper_files/paper/2022/file/8bb0d291acd4acf06ef112099c16f326-Paper-Conference.pdf">Link</a>.</p><p>Marcus, G. 2020. The next decade in ai: four steps towards robust artificial intelligence. ArXiv preprint, abs/2002.06177. <a href="https://arxiv.org/abs/2002.06177">Link</a>.</p><p>Paananen, V., Oppenlaender, J., &amp; Visuri, A. (2023). Using Text-to-Image Generation for Architectural Design Ideation. <a href="https://arxiv.org/abs/2304.10182">Link</a>.</p><p>Terrence J. Sejnowski; Large Language Models and the Reverse Turing Test. <em>Neural Comput</em> 2023; 35 (3): 309–342. doi: <a href="https://doi.org/10.1162/neco_a_01563">https://doi.org/10.1162/neco_a_01563</a></p><p>Wang, W., Dong, L., Cheng, H., Liu, X., Yan, X., Gao, J., &amp; Wei, F. (2023). Augmenting Language Models with Long-Term Memory. <a href="https://arxiv.org/pdf/2306.07174.pdf">Link</a>.</p><p>Wei, J., Wang, X., Schuurmans, D., Bosma, M., Xia, F., Chi, E., … &amp; Zhou, D. (2022). Chain-of-thought prompting elicits reasoning in large language models. <em>Advances in Neural Information Processing Systems</em>, <em>35</em>, 24824–24837. <a href="https://proceedings.neurips.cc/paper_files/paper/2022/file/9d5609613524ecf4f15af0f7b31abca4-Paper-Conference.pdf">Link</a>.</p><p>Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., … &amp; Polosukhin, I. (2017). Attention is all you need. <em>Advances in neural information processing systems</em>, <em>30</em>. <a href="https://proceedings.neurips.cc/paper_files/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf">Link</a>.</p><p>Yosef, M. A., Bauer, S., Hoffart, J., Spaniol, M., &amp; Weikum, G. (2012, December). Hyena: Hierarchical type classification for entity names. In <em>Proceedings of COLING 2012: Posters</em> (pp. 1361–1370). <a href="https://arxiv.org/abs/2302.10866">Link</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcc3590f1c0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Moon Child]]></title>
            <link>https://yulleyi.medium.com/moon-child-3d37dab69fa5?source=rss-f10cb80e3a09------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d37dab69fa5</guid>
            <category><![CDATA[immigrant-stories]]></category>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[poverty]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[personal-growth]]></category>
            <dc:creator><![CDATA[Michelle Yi (Yulle)]]></dc:creator>
            <pubDate>Sun, 25 Jun 2023 10:01:55 GMT</pubDate>
            <atom:updated>2023-06-25T10:01:55.062Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*bT7-U6gzsQ4WR9o5V7equQ.jpeg" /><figcaption>Guryong village 2022 (from iStock)</figcaption></figure><p><em>Credit to Joss Taylor Olson (jtojoss@yahoo) for brilliant creative writing expertise.</em></p><p>I don’t have a lot of memories of my mother, but there is one evening I remember distinctly.</p><p>“You know why our little village is called a ‘Moon Village’?” she asked. The moon was full and bright in the night sky. From where we sat, I could see more of the foothills below where our encampment, Guryong Village, was located.</p><p>I couldn’t fathom why our miserable home would have such a pretty name. Looking down at the desolate lean-tos and with my stomach empty from not having been able to eat all day, I responded with a complaint as children often do: “No. I don’t care. I’m hungry. It’s cold.”</p><p>She scoffed a bit. I’m sure she was hungry and cold, too. “It’s because we have the best view of the moon!” She stood and lifted me up onto her shoulders. “See, raise your hands. We’re so high up on Mt. Guryong that you can touch the moon!”</p><p>“You’re our little Miracle on the Han River,” she’d tell me.</p><p>I raised my face up to the moonlight and lifted my hands to the night sky, feeling on top of the world.</p><p>“Why do we have to live here?” I asked my grandmother once, after my mother had passed from breast cancer. I was still perpetually hungry. I watched a few roaches scuttle around the ground in front of me. Sometimes they would run over my legs while I sat to talk with her. Sometimes I gave them names based on the bullies I despised.</p><p>She motioned for me to follow her. We started walking up the hill where my mother and I used to sit. “It’s because we’re vagrants.”</p><p>“What’s a ‘vagrant’?”</p><p>When we reached the top of the hill, she asked me to sit next to her. The sun was brutal against our skin when it wasn’t freezing. We had such extreme weather conditions in the Moon Village and no way to deal with them.</p><p>“People the government deemed bad and stopping the modernization of our country,” she explained further, “See, we wouldn’t have amazing buildings like that if we didn’t sacrifice and work hard.” She gestured to the office buildings and apartments in the distance.</p><p>“We used to live over there,” she pointed in another direction, “where the Olympic Stadium is. We used to live in an apartment there. One day, they announced that we needed to make sacrifices for our country, and forced us to get on a bus, so they could use that land for the stadium. They left us here with nothing. We did what we could to build a village.”</p><p>I didn’t understand until much later the larger truth behind such statements. That this was part of a large “social purification” campaign — taught to us today as the “modernization” campaign — to…” make Korea an ‘economically modern’ country with the intent of bidding for the Olympics. The stronger the economy, the more attractive the bid.” This era of development was in fact described in history books as, “The Miracle on the Han River”. The coup de grâce to show the world the fruits of this modernization campaign, that we had fully transformed from a ‘least developed country’ to a ‘developed country’, was the 1988 Seoul Summer Olympics.</p><p>It was in this modern Korea, no longer ravaged by the war of the 1950s and four previous decades of excruciating Japanese colonization, that there was no place for ‘vagrants’.</p><p>She switched to Japanese, which was sometimes easier for her than Korean because of her experience living through the Japanese occupation. “We couldn’t afford to show any weakness to the Westerners coming to visit us. So the government, police, and Chaebols [conglomerate companies like Samsung] — they moved everyone that didn’t fit. That included us, homeless people, children, pro-democracy protestors, students, anyone that spoke up for human rights, labor rights, or otherwise deemed as slowing down economic progress. Anyone the police didn’t like, too. You’re lucky to live here.”</p><p>I was appalled. “Lucky?”</p><p>“Some people, including your uncle, never survived police encounters. Some families were separated or sent to forced labor camps to support modernization. I bet you don’t even remember him, your uncle, do you? To think I survived Japanese occupation only to outlive my own children in the name of national greed.”</p><p>She paused. Sighed. “What place do girls have in economic development? Nobody will care about you. We will all die here.”</p><p>I stayed up that night, oscillating between believing and refusing to believe that I had no place in the universe. It’s hard to reject something you’ve been told your whole life is true.</p><p>“Why do you have that stupid thing?” my father shouted angrily, throwing a Soju bottle that shattered near me. Roaches scattered. “Get out of here.” He held his head in his hands. I think he was crying.</p><p>My grandmother was in pain from cancer, which we did not have the means to treat. Just like mom. I was still hungry. I could never escape the feeling of being hungry.</p><p>I held the object in question, a cartoony tiger pin of Hodori, close to me in a moment of stillness before fleeing over broken glass. Ignoring the cuts, I ran on bloody feet to the top of the hill and paused. Hodori was the mascot for the 1988 Seoul Summer Olympics. Mom had given me this pin because I was her Miracle on the Han River.</p><p>The irony was that all tigers in Korea had been killed during the Japanese occupation. Of this symbol of national pride, only the symbol remained.</p><p>I was Mom’s Miracle on the Han River. But the Miracle on the Han River — who was it for?</p><p>I stood pensively under the moonlight. Determination filled me as I tightened my grip on the pin. I began to make plans, to run through scenarios, to learn how to escape this system. How to make it better. I would rather die fighting than give up, as I was sure the tigers must have, and do everything in my power to build a world where nobody else had to either.</p><p>I had no idea at the time that, in just a few short years, I would attend university in the United States at the age of 13. I had no idea that the entire village would fall under the shadows of the newly built Gangnam Samsung Luxury Apartment Towers. They boasted 70 floors, fully automated apartments, and helipads on the roofs.</p><p>I didn’t care. I was hungry. I was cold. We all were.</p><p>References to learn more for people interested:</p><p>Seoul ‘moon village’ becomes a tourist trap. <a href="https://www.koreaherald.com/view.php?ud=20220926000213">https://www.koreaherald.com/view.php?ud=20220926000213</a>.</p><p>Miracle on the Han River. <a href="https://en.wikipedia.org/wiki/Miracle_on_the_Han_River">https://en.wikipedia.org/wiki/Miracle_on_the_Han_River</a>.</p><p>Park Chung Hee. <a href="https://en.wikipedia.org/wiki/Park_Chung_Hee">https://en.wikipedia.org/wiki/Park_Chung_Hee</a>.</p><p>Samsung Tower Place. <a href="https://en.wikipedia.org/wiki/Samsung_Tower_Palace">https://en.wikipedia.org/wiki/Samsung_Tower_Palace</a>.</p><p>Seoul’s last remaining slums. <a href="https://www.bloomberg.com/news/videos/2020-12-17/seoul-s-last-remaining-slum-video">https://www.bloomberg.com/news/videos/2020-12-17/seoul-s-last-remaining-slum-video</a>.</p><p>South Korea covered up mass abuse, killing of ‘vagrants’. <a href="https://apnews.com/article/south-korea-crime-2020-tokyo-olympics-busan-olympic-games-43ad81ac09564c90bc6e6b3cd005d73d">https://apnews.com/article/south-korea-crime-2020-tokyo-olympics-busan-olympic-games-43ad81ac09564c90bc6e6b3cd005d73d</a>.</p><p>Brother’s Home: South Korea’s 1980s ‘concentration camp’. <a href="https://www.bbc.com/news/world-asia-52797527">https://www.bbc.com/news/world-asia-52797527</a>.</p><p>신자유주의 시대의 무허가 정착지 경관에 대한 비판적 해석 : 강남구 개포동 구룡마을을 사례로. <a href="https://academic.naver.com/article.naver?doc_id=79758734">https://academic.naver.com/article.naver?doc_id=79758734</a>.</p><p>서울 중계동 백사마을의 건축적 특성 연구. <a href="https://academic.naver.com/article.naver?doc_id=176945228">https://academic.naver.com/article.naver?doc_id=176945228</a>.</p><p>Are large cats compatible with modern society on the Korean Peninsula? Ecological Restoration. 34 (3): 173–183. doi:10.3368/er.34.3.173. S2CID 88992035.</p><p>Hodori. <a href="https://en.wikipedia.org/wiki/Hodori">https://en.wikipedia.org/wiki/Hodori</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d37dab69fa5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Journey Through the Molecular World: Representing Molecules in Python]]></title>
            <link>https://yulleyi.medium.com/a-journey-through-the-molecular-world-representing-molecules-in-python-53f362b8b107?source=rss-f10cb80e3a09------2</link>
            <guid isPermaLink="false">https://medium.com/p/53f362b8b107</guid>
            <category><![CDATA[knowledge-graph]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[biology]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[graph-algorithms]]></category>
            <dc:creator><![CDATA[Michelle Yi (Yulle)]]></dc:creator>
            <pubDate>Wed, 26 Apr 2023 01:13:30 GMT</pubDate>
            <atom:updated>2023-04-26T01:13:30.857Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*91z-Y36XlC0FEqL8" /><figcaption>Photo by <a href="https://unsplash.com/@vlisidis?utm_source=medium&amp;utm_medium=referral">Terry Vlisidis</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>Ever wondered how you could represent molecules in Python?</p><p>In this post, we’ll take a journey through the molecular world and explore five oxygen-containing molecules: water, carbon dioxide, ozone, hydrogen peroxide, and glucose.</p><p>We’ll learn how to represent them using Python data structures and also create a molecular graph using the networkx package.</p><h3>Meet the Molecules</h3><p>Here are the five Oxygen-containing molecules we will look at, their structures, and their overall role in the ecosystem:</p><ol><li><strong>Water (H2O)</strong>: Water is a simple molecule composed of two hydrogen atoms and one oxygen atom. It is essential for life on Earth and is involved in many biological and chemical processes.</li><li><strong>Carbon dioxide (CO2)</strong>: Carbon dioxide consists of one carbon atom and two oxygen atoms. It is produced as a byproduct of cellular respiration in living organisms and is also a greenhouse gas that plays a significant role in Earth’s climate.</li><li><strong>Ozone (O3)</strong>: Ozone is a molecule made up of three oxygen atoms. It is found in Earth’s atmosphere, primarily in the stratosphere, where it forms the ozone layer that protects life on Earth from harmful ultraviolet radiation.</li><li><strong>Hydrogen peroxide (H2O2)</strong>: Hydrogen peroxide is a chemical compound with two hydrogen atoms and two oxygen atoms. It is a powerful oxidizer and is used as a disinfectant, bleaching agent, and antiseptic.</li><li><strong>Glucose (C6H12O6)</strong>: Glucose is a simple sugar and an essential energy source for living organisms. It is a carbohydrate that consists of six carbon atoms, twelve hydrogen atoms, and six oxygen atoms. During cellular respiration, glucose is broken down to produce energy in the form of ATP and releases carbon dioxide and water as byproducts.</li></ol><p>Now, let’s compare both a traditional Python and graph approach to representing these molecules.</p><h3>Representing Molecules in Python</h3><p>In this section, we will explore how to represent the five molecules and their bonds using Python data structures like dictionaries and lists. Our goal is to create a simple and intuitive representation of these molecules, making it easy to understand their composition and structure.</p><h4>Using Dictionaries and Lists</h4><p>Python dictionaries and lists provide a convenient way to represent molecules and their bonds. We can create a dictionary where the keys represent the molecule names, and the values are lists of dictionaries describing the bonds between atoms within the molecule.</p><p>Here’s a code snippet illustrating how to represent the five molecules using dictionaries and lists:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3192060567e37f4b78a87bf4b493229c/href">https://medium.com/media/3192060567e37f4b78a87bf4b493229c/href</a></iframe><p>The dictionary called molecules contains the names of the molecules as keys and lists of dictionaries describing their bonds as values. The dictionaries representing bonds contain keys for the bonded atoms and the number of bonds.</p><h4>Displaying Molecules and Their Bonds</h4><p>Now that we have represented the molecules and their bonds in a Python dictionary, we can display this information in a user-friendly format. The following code snippet prints the molecules and their bonds:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e870e668e807aca5b82d5cabed1bab8/href">https://medium.com/media/2e870e668e807aca5b82d5cabed1bab8/href</a></iframe><p>The output of this code will be:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/217c48a292aa994242cb35c449773557/href">https://medium.com/media/217c48a292aa994242cb35c449773557/href</a></iframe><p>This representation allows us to easily visualize the molecules and their bonds, but it lacks the graphical representation that the networkx package provides, which we will explore in the next section.</p><h3>Visualizing Molecules as a Graph with NetworkX</h3><p>In this section, we’ll learn how to represent the five molecules as a graph using the networkx package. This powerful Python library allows us to create, manipulate, and study the structure, dynamics, and functions of complex networks. We&#39;ll start by installing the package and then create a molecular graph to visualize the relationships between atoms in our molecules.</p><h4>Installing the NetworkX Package</h4><p>To install the networkx package, simply run the following command:</p><pre>pip install networkx</pre><h4>Creating a Molecular Graph</h4><p>With the networkx package installed, we can now create a graph to represent our molecules. A graph consists of nodes (atoms, in our case) and edges (bonds between atoms). We&#39;ll also include edge attributes to store the molecule name for each bond.</p><p>Here’s a code snippet that demonstrates how to create a molecular graph using networkx:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9f401af9d8e868ac97c5c68766a36f3/href">https://medium.com/media/a9f401af9d8e868ac97c5c68766a36f3/href</a></iframe><p>This script creates a networkx graph with nodes for the different atoms (H, O, C, and N) and adds edges representing the bonds between these atoms in each molecule. The graph is then visualized using matplotlib, with the molecule name labeled on each edge representing a bond in the respective molecule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*1TcxQeX3WHx8WO_jCEyxag.png" /><figcaption>Sample visualization of graph output using networkx. This is over-simplified and only meant to be illustrative.</figcaption></figure><p>Please note that this representation is highly simplified and doesn’t take into account the detailed molecular structure or the specific locations of atoms and bonds within the molecules. We also intentionally duplicate molecule representations (not necessary in the graph) for the purpose of visualizing it here.</p><p>For an example of how to represent the graph with molecule logic consolidated in a single place but not optimized for visualization, see below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e73f99f9664ac9ca989bcceaf767d2e/href">https://medium.com/media/7e73f99f9664ac9ca989bcceaf767d2e/href</a></iframe><h4>Interpreting the Molecular Graph</h4><p>The molecular graph allows us to visualize the relationships between the atoms in our molecules. In the graph, each node represents an atom, and each edge represents a bond between two atoms. The edge labels indicate which molecule the bond belongs to.</p><p>By visualizing the molecules as a graph, we gain a better understanding of the relationships between atoms and the overall structure of each molecule. However, it’s important to remember that this representation is a simplification and may not accurately depict the 3D structure of the molecules.</p><h3>Conclusion</h3><p>In this Medium post, we explored different approaches to represent and visualize oxygen-containing molecules using Python.</p><p>We started by discussing five molecules that use oxygen: water, carbon dioxide, ozone, hydrogen peroxide, and glucose. Then, we demonstrated how to represent these molecules using both traditional methods in Python and the networkx library. Although this approach provided a simple visualization of the atomic relationships, it may not be the most accurate way to depict molecular structures.</p><p>When representing and visualizing molecules in Python, it’s essential to choose the appropriate tools based on the specific requirements of your project. For simple graph-based representations, networkx can provide a quick and straightforward solution. However, for more accurate and detailed molecular visualizations, specialized libraries like RDKit are recommended.</p><p>By understanding the various tools and techniques available for molecular visualization in Python, you’ll be better equipped to tackle projects involving chemistry, biology, and other fields where molecular structures play a critical role.</p><p>Happy coding!</p><h3>References</h3><p><strong>NetworkX:</strong></p><ul><li>Documentation: <a href="https://networkx.org/documentation/stable/index.html">https://networkx.org/documentation/stable/index.html</a></li><li>Tutorial: <a href="https://networkx.org/documentation/stable/tutorial.html">https://networkx.org/documentation/stable/tutorial.html</a></li></ul><p><strong>RDKit:</strong></p><ul><li>Homepage: <a href="https://www.rdkit.org/">https://www.rdkit.org/</a></li><li>Documentation: <a href="https://www.rdkit.org/docs/index.html">https://www.rdkit.org/docs/index.html</a></li><li>Getting Started: <a href="https://www.rdkit.org/docs/GettingStartedInPython.html">https://www.rdkit.org/docs/GettingStartedInPython.html</a></li></ul><p><strong>Cheminformatics and Computational Chemistry:</strong></p><ul><li>Cheminformatics in Python: <a href="https://chem.libretexts.org/@go/page/1796">https://chem.libretexts.org/@go/page/1796</a></li><li>Computational Chemistry: <a href="https://en.wikipedia.org/wiki/Computational_chemistry">https://en.wikipedia.org/wiki/Computational_chemistry</a></li><li>Cheminformatics Tools: <a href="https://en.wikipedia.org/wiki/List_of_cheminformatics_software">https://en.wikipedia.org/wiki/List_of_cheminformatics_software</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53f362b8b107" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Art of Strategy: Life Lessons from a Famous “Go” Game]]></title>
            <link>https://yulleyi.medium.com/the-art-of-strategy-life-lessons-from-a-famous-go-game-1c00baf17bc4?source=rss-f10cb80e3a09------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c00baf17bc4</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[life-lessons]]></category>
            <dc:creator><![CDATA[Michelle Yi (Yulle)]]></dc:creator>
            <pubDate>Sun, 16 Apr 2023 08:00:18 GMT</pubDate>
            <atom:updated>2023-04-17T17:58:52.163Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eASAK4bbQ35fzbmF" /><figcaption>Photo by <a href="https://unsplash.com/de/@elenapopova?utm_source=medium&amp;utm_medium=referral">Elena Popova</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Background</h3><p>I grew up playing the game of Go and currently work in the field of applied machine learning. As advances in reinforcement learning eventually led to <a href="https://www.deepmind.com/research/highlighted-research/alphago"><em>AlphaGo</em></a> and the Netflix documentary on its development, I began to think of the game differently.</p><p>Is it really “solved” for?</p><p>Many Go engines utilize Monte Carlo Tree Search (MCTS) combined with other CNNs or deep learning algorithms. MCTS is a search algorithm that consists of four main steps: Selection, Expansion, Simulation, and Backpropagation. The algorithm iteratively performs these steps to build a search tree and determines the best move based on the tree’s structure.</p><p>Here’s a high-level example of how it works:</p><ol><li><strong>Selection</strong>: Starting from the root node (the current game state), traverse the tree by selecting the child node with the highest Upper Confidence Bound applied to Trees (UCT) value, which balances exploration and exploitation. The traversal continues until a leaf node is reached.</li><li><strong>Expansion</strong>: If the leaf node represents a non-terminal game state, expand the node by generating all possible moves and adding them as child nodes.</li><li><strong>Simulation</strong>: Run a random playout (simulation) from the newly-expanded node’s game state until a terminal game state (win, loss, or draw) is reached. In Go, this involves randomly placing stones on the board while following the game’s rules until the game ends.</li><li><strong>Backpropagation</strong>: Update the nodes in the path from the leaf node to the root node based on the simulation’s result. Each node keeps track of the number of simulations that have passed through it (visits) and the total score obtained from those simulations.</li></ol><p>The algorithm repeats these steps until a predefined time limit or a maximum number of iterations is reached. The move corresponding to the child node of the root with the most visits is chosen as the best move.</p><p><strong>But does the way a Go engine interprets the game really convey the depth behind the game? Is there still value in playing such a complicated game?</strong></p><p>Let’s explore a bit further by understanding a bit of the history behind the game and then a specific game example.</p><h3>What is Go?</h3><p>Go is an ancient board game that originated in China over 2,500 years ago, and it is known as “Weiqi” in Chinese, “Baduk” in Korean, and “Igo” in Japanese. It is a strategic two-player game played on a grid of 19x19 lines, although smaller boards (such as 9x9 or 13x13) are also used for faster games or educational purposes.</p><p>The objective of the game is to surround and capture more territory than your opponent. The game is played with two sets of stones, one black and one white. Players take turns placing their stones on the intersections of the grid, with black going first. Once placed, a stone cannot be moved unless it is captured by the opponent.</p><p>Capturing occurs when a group of stones is completely surrounded by the opponent’s stones, causing them to be removed from the board. Additionally, the concept of “liberties” is important in Go, which refers to the empty points directly adjacent to a stone or group of stones. <strong>When a group of stones has no more liberties, it is captured.</strong></p><p>Go is a game of immense strategic depth, with a large number of potential moves and complex interactions between groups of stones. As a result, this is what makes it a popular subject for artificial intelligence research.</p><h3>A famous game &amp; move example</h3><p>One of the most famous series of moves in Go history is the “ear-reddening move” (耳赤の一手), which occurred during a game between two legendary Japanese Go players, Honinbo Shusaku (本因坊秀策) and Gennan Inseki (厳然因碩), in 1846. Shusaku was just a teenager at the time, while Gennan was a top player in his 50s and considered one of the strongest of his era.</p><p>The ear-reddening move is a single move (move 127) played by Shusaku during this game. It was a surprising and deep move that demonstrated Shusaku’s exceptional reading ability and strategic insight. <a href="https://senseis.xmp.net/?EarReddeningGame">Legend has it</a> that Gennan’s ears turned red with embarrassment upon realizing the implications of Shusaku’s move, hence the name “ear-reddening move.”</p><p>This move eventually led to Shusaku’s victory and further solidified his reputation as one of the greatest Go players of all time. The game itself is also famous and is known as the “ear-reddening game” (耳赤の一局). It is still studied by Go players today for its high level of play and the insights it offers into the game’s strategic depth.</p><h4>A more detailed analysis</h4><ol><li><strong>Opening (Fuseki)</strong>: Shusaku, playing as Black, opens with a diagonal move in the lower right corner (4–4 point, position D16). White’s response is the 3–4 point in the upper left corner (C4). Shusaku’s opening strategy is known as the “Shusaku Fuseki,” which focuses on rapid development and strong positions.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*MSx1TaMw924gsdZ895ReYg.jpeg" /><figcaption>Shusaku Fuseki</figcaption></figure><p><strong>2. Moves 31–60</strong>: The players work on expanding their frameworks while keeping an eye on their opponents’ weaknesses. Shusaku’s moves during this phase, such as move 35 at R9, R10, aim to reinforce his territorial claims and secure groups. White, on the other hand, looks for ways to invade or reduce Black’s potential territory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*sKPp_kp7DkMSLKpHvYWWuw.jpeg" /><figcaption>Framework expansion</figcaption></figure><p><strong>3. Move 70</strong>: White invades Black’s moyo (a large framework with the potential to become territory) at position O10. This move is critical because it challenges Black’s territorial claims in the center and the left side of the board.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*yP3saCpQXcVOJDtwu5DaYA.jpeg" /><figcaption>White challenges Black’s framework</figcaption></figure><p><strong>4. Moves to 90</strong>: In response to White’s invasion, Black tries to surround and attack White’s group, aiming to strengthen his own position while putting pressure on White. A key move to note is Black’s move at position O5 earlier, which challenges White’s attempts to secure his invaded group.</p><p><strong>5. Moves 91–126</strong>: White manages to create a living group on the left side of the board, reducing Black’s potential territory. However, Black’s moves, such as move 119, continue to pressure White’s groups and create opportunities for future attacks.</p><p><strong>6. Move 127 (Ear Reddening Move)</strong>: Shusaku plays at K11, a subtle move that threatens to connect his stones on the left side while also reducing White’s influence in the center. This move shifts the balance of power in the game and marks the beginning of the end for White. Experts have praised this move as a brilliant example of Shusaku’s deep understanding of the game, as it creates multiple threats and opportunities without directly engaging the opponent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*zjC7Y-vaf7MCdpHa1rENhA.jpeg" /><figcaption>The famous ear reddening move at move 127</figcaption></figure><ol><li><strong>Moves 128-End</strong>: As the game progresses, Shusaku manages to exploit the weaknesses exposed by move 127, leading to a decisive advantage. White is unable to recover from the position created by the Ear Reddening Move, and Black eventually secures the victory.</li></ol><p>An analysis like this highlights the strategic planning and fighting spirit displayed by both players, particularly Shusaku’s ability to identify and exploit opportunities.</p><p>A modern Go engine might be able to provide a similar recommendation on this series of moves, but what other lessons can we learn from this game?</p><h3>Lessons beyond the game</h3><p>The Ear Reddening Game, like many other classic Go games, offers valuable lessons that can be applied to life more generally.</p><p>Here are seven things we can learn from the game:</p><ol><li><strong>Patience and foresight</strong>: Shusaku’s Ear Reddening Move (move 127) demonstrates the importance of patience and the ability to see long-term consequences of one’s actions. In life, being patient and considering the long-term effects of our decisions can lead to better outcomes.</li><li><strong>Balance</strong>: In Go, players must balance attack and defense, territorial gains, and influence. Similarly, in life, it’s essential to maintain a balance between different aspects, such as work and personal life, short-term and long-term goals, and risk and reward.</li><li><strong>Adaptability</strong>: Throughout the game, both players had to adapt their strategies in response to their opponent’s moves. In life, being adaptable and flexible in the face of changing circumstances can help us navigate challenges more effectively.</li><li><strong>The importance of small moves</strong>: In the Ear Reddening Game, seemingly small moves had a significant impact on the final outcome. In life, small actions can sometimes have far-reaching consequences, so it’s essential to pay attention to details and not underestimate the value of small efforts.</li><li><strong>Learning from others</strong>: The game offers an opportunity to learn from the strategies and tactics of two great Go players. In life, we can grow by learning from the experiences, knowledge, and wisdom of others.</li><li><strong>Resilience and perseverance</strong>: The players in this game faced setbacks and challenges but continued to play until the end. In life, resilience and perseverance are crucial qualities that enable us to overcome obstacles and achieve our goals.</li><li><strong>Appreciating the beauty in complexity</strong>: The Ear Reddening Game is a beautiful example of the depth and complexity of Go. In life, we can learn to appreciate the beauty and intricacies of complex systems, relationships, and situations.</li></ol><p>Even if Go engines can get to an advanced level of gameplay, studying and learning from classic Go games like the Ear Reddening Game can offer valuable insights and teach us important life lessons that extend beyond the game board.</p><h3>Reference</h3><p>GoKifu replay. <a href="http://gokifu.com/s/rxj">Link</a>.</p><p>Sensei’s Library. <a href="https://senseis.xmp.net/?EarReddeningGame">Link</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c00baf17bc4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring the Shruti System: A Visual Journey through Indian Classical Scales using Python and…]]></title>
            <link>https://yulleyi.medium.com/exploring-the-shruti-system-a-visual-journey-through-indian-classical-scales-using-python-and-3d4a57992dcb?source=rss-f10cb80e3a09------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d4a57992dcb</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[networkx]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[music]]></category>
            <category><![CDATA[knowledge-graph]]></category>
            <dc:creator><![CDATA[Michelle Yi (Yulle)]]></dc:creator>
            <pubDate>Wed, 12 Apr 2023 01:45:52 GMT</pubDate>
            <atom:updated>2023-04-12T01:45:52.712Z</atom:updated>
            <content:encoded><![CDATA[<h3>Exploring the Shruti System: A Visual Journey through Indian Classical Scales using Python and NetworkX</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1rPDOsBaX62gyN3H" /><figcaption>Photo by <a href="https://unsplash.com/@manishvyas?utm_source=medium&amp;utm_medium=referral">Manish Vyas</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Background</h3><p>In our last article, <a href="https://yulleyi.medium.com/algorithmic-approaches-to-music-theory-4dec4f70d77c">Algorithmic Approaches to Music Theory: Conventional and Graph-Based Methods</a>, we used conventional Python and graph-based approaches to explore the foundations of music theory, starting with the Western major and minor scales.</p><p>Today, let’s take a look at the Indian Shruti system, which is based on 22 Shruti and not 12 notes from an equal temperament system. We will take the same approach and better understand the music theory behind the Shruti system through the implementation of basic scales using both a conventional Python method and a graph-based approach. Then, we can analyze the learnings from an implementation and from a topic perspective.</p><h3>Shruti major scale: Shruti Shuddha Saptak</h3><p>The Indian Shruti major scale, also known as the “Shruti Shuddha Saptak,” is a scale in Indian classical music derived from the 22-Shruti system. The term “shruti” refers to the smallest musical interval in Indian classical music. The Indian Shruti major scale is analogous to the Western major scale.</p><p>Here is the algorithm to define the Indian Shruti major scale:</p><ol><li>Start with the fundamental frequency (tonic), called “Sa” or “Shadja” in Indian music. This is the first note of the scale.</li><li>Calculate the following frequency ratios for the subsequent notes:</li></ol><ul><li>Sa (Shadja): 1/1</li><li>Re (Rishabh): 9/8</li><li>Ga (Gandhar): 5/4</li><li>Ma (Madhyam): 4/3</li><li>Pa (Pancham): 3/2</li><li>Dha (Dhaivat): 27/16</li><li>Ni (Nishad): 15/8</li></ul><p>3. Multiply the fundamental frequency by each of these ratios to get the frequencies of the corresponding notes in the Indian Shruti major scale.</p><p>4. The final note, “Sa” (Shadja) in the upper octave, has a ratio of 2/1, which means it’s exactly double the frequency of the starting note.</p><p>For example, if the starting note (Sa) has a frequency of 240 Hz:</p><ol><li>Sa (Shadja): 240 * (1/1) = 240 Hz</li><li>Re (Rishabh): 240 * (9/8) = 270 Hz</li><li>Ga (Gandhar): 240 * (5/4) = 300 Hz</li><li>Ma (Madhyam): 240 * (4/3) = 320 Hz</li><li>Pa (Pancham): 240 * (3/2) = 360 Hz</li><li>Dha (Dhaivat): 240 * (27/16) = 405 Hz</li><li>Ni (Nishad): 240 * (15/8) = 450 Hz</li><li>Sa (Shadja) upper octave: 240 * (2/1) = 480 Hz</li></ol><p>Keep in mind that these are only approximate values for the Indian Shruti major scale. In actual performance, musicians may make small adjustments to these frequencies based on the specific raga being performed or the melodic context.</p><h4>Python implementation</h4><p>Below is the conventional way to code the algorithm for the Shruti Suddha Saptak using Python.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45419cf42ef10f3c2057bc88e13f48f2/href">https://medium.com/media/45419cf42ef10f3c2057bc88e13f48f2/href</a></iframe><p>When you run this code, it will output the frequencies of the Indian Shruti major scale based on the provided tonic frequency:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b085831228bf46f06a16e98ac572806d/href">https://medium.com/media/b085831228bf46f06a16e98ac572806d/href</a></iframe><h4>Graph (networkx) implementation</h4><p>Now, here’s the Python code to represent the Indian Shruti major scale as a NetworkX graph:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bb38b4d8316a3c9dac1e7019bf5fd11/href">https://medium.com/media/7bb38b4d8316a3c9dac1e7019bf5fd11/href</a></iframe><p>This code creates a directed graph with nodes representing the notes of the Indian Shruti major scale and edges representing the frequency ratios between the notes.</p><p>We can also visualize the graph with the code below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9bccfb4455447fb598925726a6c9f88/href">https://medium.com/media/d9bccfb4455447fb598925726a6c9f88/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*ug7KX3FGzDRF7HxFwspYwQ.png" /><figcaption>Sample image of the directed graph for the Shruti major scale</figcaption></figure><p>The draw_graph function uses NetworkX and matplotlib to visualize the graph with a circular layout. The graph shows the notes with their names and the edges with the frequency ratios.</p><p>Now, what if we try to add the minor scale equivalent to both implementations?</p><h3>Shruti Minor Scale: Asavari Thaat</h3><p>In the Indian Shruti system, there isn’t a direct equivalent of the Western minor scale. However, you can create a scale with a similar mood or tonality by selecting different swaras (notes) from the 22-shruti system. One possible example is the Asavari Thaat, which is a scale used in Hindustani music and has a somewhat similar tonality to the natural minor scale.</p><p>Here’s the algorithm for the Asavari Thaat scale:</p><ol><li>Start with the fundamental frequency (tonic), called “Sa” or “Shadja” in Indian music. This is the first note of the scale.</li><li>Calculate the following frequency ratios for the subsequent notes:</li></ol><ul><li>Sa (Shadja): 1/1</li><li>Re (Rishabh): 9/8</li><li>Ga (Gandhar): 32/27</li><li>Ma (Madhyam): 4/3</li><li>Pa (Pancham): 3/2</li><li>Dha (Dhaivat): 8/5</li><li>Ni (Nishad): 16/9</li></ul><p>3. Multiply the fundamental frequency by each of these ratios to get the frequencies of the corresponding notes in the Asavari Thaat scale.</p><p>4. The final note, “Sa” (Shadja) in the upper octave, has a ratio of 2/1, which means it’s exactly double the frequency of the starting note.</p><p>For example, if the starting note (Sa) has a frequency of 240 Hz:</p><ol><li>Sa (Shadja): 240 * (1/1) = 240 Hz</li><li>Re (Rishabh): 240 * (9/8) = 270 Hz</li><li>Ga (Gandhar): 240 * (32/27) = 284.44 Hz</li><li>Ma (Madhyam): 240 * (4/3) = 320 Hz</li><li>Pa (Pancham): 240 * (3/2) = 360 Hz</li><li>Dha (Dhaivat): 240 * (8/5) = 384 Hz</li><li>Ni (Nishad): 240 * (16/9) = 426.67 Hz</li><li>Sa (Shadja) upper octave: 240 * (2/1) = 480 Hz</li></ol><p>Keep in mind that Indian classical music is based on ragas, which have more intricate melodic structures and phrasings than the scales found in Western music. This is just an example of how to create a scale similar to the Western minor scale within the 22-shruti system.</p><h4>Python implementation</h4><p>Here is the conventional Python implementation of the Asavari Thaat scale.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce3a21f06793b5730b6af8f3b04dd50b/href">https://medium.com/media/ce3a21f06793b5730b6af8f3b04dd50b/href</a></iframe><p>When you run this code, it will output the frequencies of the Asavari Thaat scale based on the provided tonic frequency:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e527759e59836282e3de3af56b14242/href">https://medium.com/media/0e527759e59836282e3de3af56b14242/href</a></iframe><p>We can change the tonic_frequency variable to generate the scale based on a different starting frequency.</p><h4>Graph (networkx) implementation</h4><p>Here’s how we can add the Asavari Thaat scale to the existing major scale NetworkX graph:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2403236760df8bddd96ac8fb8cee0fe4/href">https://medium.com/media/2403236760df8bddd96ac8fb8cee0fe4/href</a></iframe><p>Let’s clean up the graph to make it more readable and at scale:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e1997226abf47ca6f7da0614723510e/href">https://medium.com/media/4e1997226abf47ca6f7da0614723510e/href</a></iframe><p>This outputs a graph like below, although it can also be represented in a single directed graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IMOLcd6o9Kp2KiMp6ueAIA.png" /><figcaption>Larger scale spring graph image of the Shruti scales</figcaption></figure><h3>Analysis</h3><h4>Learnings on the two implementation approaches</h4><p>When comparing the implementation of the Indian Shruti major scale and Asavari Thaat scale using Python code versus a NetworkX graph representation, we can observe several differences:</p><ol><li>Representation:</li></ol><ul><li>In the Python implementation, scales are represented as lists of frequency values. This approach focuses on the numeric values of the frequencies.</li><li>In the NetworkX graph representation, the scales are represented as graphs with nodes and edges. This approach emphasizes the relationships between the notes, making it easier to visualize and understand the structure of the scales.</li></ul><p>2. Visualization:</p><ul><li>The Python implementation does not inherently provide a visual representation of the scales. If you want to visualize the relationships between the notes, you would need to use additional libraries or tools.</li><li>With the NetworkX graph approach, you can easily create a visual representation of the scales, clearly showing the relationships between the notes and their frequencies. This can be beneficial for understanding the overall structure of the scales and their connections.</li></ul><p>3. Scalability:</p><ul><li>In the Python implementation, adding more scales or modifying the existing scales requires changes to the code itself, potentially making it more complex as new scales are added.</li><li>In the NetworkX graph representation, adding more scales or modifying the existing scales can be done by simply adding nodes and edges to the graph. This allows for easier scaling and modification of the representation as new scales are added or existing ones are updated.</li></ul><p>4. Flexibility:</p><ul><li>The Python implementation is more focused on the specific calculations of frequencies and may not easily support additional information or properties related to the scales.</li><li>The NetworkX graph representation can store additional information and properties related to the notes, such as names or other attributes, making it a more flexible representation that can be extended to include more information as needed.</li></ul><p>While the Python implementation is more focused on the numeric calculations of frequencies, the NetworkX graph approach provides a more visually appealing and flexible representation that emphasizes the relationships between the notes. Depending on the requirements of your specific use case, you may choose one approach over the other based on the advantages and disadvantages of each method.</p><h4>Learnings on the Shruti method</h4><p>From the two implementations (Python code and NetworkX graph), we can also learn various aspects of the two scales (Indian Shruti major scale and Asavari Thaat scale) and the Shruti system:</p><ol><li>Frequency Ratios:</li></ol><ul><li>Both implementations allow us to calculate the frequency ratios between the consecutive notes of the scales. These ratios are essential in understanding the intervals between notes, which define the unique characteristics of each scale.</li></ul><p>2. Scale Structure:</p><ul><li>The NetworkX graph implementation helps us visualize the structure of the scales and their connections. This visualization makes it easier to understand the relationships between notes in each scale and compare the two scales.</li></ul><p>3. Scale Differences:</p><ul><li>Comparing the Python implementations or the NetworkX graph representation, we can observe differences in the frequency ratios between the two scales. For example, the Indian Shruti major scale has a major third (Ga), while the Asavari Thaat scale has a minor third (Ga). This difference in intervals leads to the distinct sound of each scale.</li></ul><p>4. Shruti System:</p><ul><li>The Python implementations illustrate the algorithmic approach to generating the scales in the Shruti system, highlighting the importance of frequency ratios in defining the scales. By comparing the two scales, we can see how the Shruti system can generate different scales by modifying the intervals between notes.</li></ul><p>5. Flexibility and Extensibility:</p><ul><li>The NetworkX graph representation shows the potential for easily adding more scales or modifying the existing scales, allowing us to analyze a broader range of scales within the Shruti system. This flexibility can help us better understand the relationships between various scales in the system and their properties.</li></ul><h3>Conclusion</h3><p>In conclusion, the Python code and NetworkX graph implementations provide different perspectives on the Indian Shruti major scale, the Asavari Thaat scale, and the Shruti system. By examining these implementations, we can gain insights into the structure, relationships, and unique characteristics of the scales and better understand the principles underlying the Shruti system.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d4a57992dcb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Algorithmic Approaches to Music Theory]]></title>
            <link>https://yulleyi.medium.com/algorithmic-approaches-to-music-theory-4dec4f70d77c?source=rss-f10cb80e3a09------2</link>
            <guid isPermaLink="false">https://medium.com/p/4dec4f70d77c</guid>
            <category><![CDATA[music-theory]]></category>
            <category><![CDATA[networkx]]></category>
            <category><![CDATA[knowledge-graph]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Michelle Yi (Yulle)]]></dc:creator>
            <pubDate>Thu, 06 Apr 2023 15:02:13 GMT</pubDate>
            <atom:updated>2023-04-06T15:02:13.162Z</atom:updated>
            <content:encoded><![CDATA[<h3>Algorithmic Approaches to Music Theory: Conventional and Graph-Based Methods</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w6RwXHgPphsLHZO-" /><figcaption>Photo by <a href="https://unsplash.com/@marius?utm_source=medium&amp;utm_medium=referral">Marius Masalar</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Background</h3><p>As an experienced engineer with a past life in professional music, I have always been fascinated by the convergence of music and technology. Both domains share commonalities, such as mathematical underpinnings and logical structures.</p><p>In this article, my objective is to explore and compare conventional and graph-based techniques for developing algorithms that encapsulate music theory concepts. By investigating these methodologies, it is interesting to understand how the basis for modern music theory works.</p><h3>Approach</h3><h4>Step 1: Establishing the algorithm for a major scale</h4><p>A major scale in music can be defined by its pattern of whole and half steps. In Western music, the major scale consists of seven notes, following the pattern: whole, whole, half, whole, whole, whole, half.</p><p>Here’s an algorithmic representation of generating a major scale for a given root note (assuming a 12-tone equal temperament tuning system):</p><ol><li>Define the pattern of whole and half steps for a major scale: [2, 2, 1, 2, 2, 2, 1].</li><li>Define the list of note names in chromatic order: [“C”, “C#”, “D”, “D#”, “E”, “F”, “F#”, “G”, “G#”, “A”, “A#”, “B”].</li><li>Determine the index of the root note in the chromatic list (e.g., “C” would be 0, “C#” would be 1, “D” would be 2, and so on).</li><li>Initialize an empty list to store the major scale notes.</li><li>Iterate through the pattern of whole and half steps, adding the current step value to the index of the root note, and modulo 12 to wrap around the chromatic list if necessary.</li><li>For each resulting index, append the corresponding note from the chromatic list to the major scale notes list.</li><li>Return the list of major scale notes.</li></ol><h4>Step 2: Comparing the conventional and graph approaches to representing the major scale algorithm</h4><p>The conventional approach for this would be to implement the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd36ed9e5a78e674505a520ef79264cb/href">https://medium.com/media/bd36ed9e5a78e674505a520ef79264cb/href</a></iframe><p>Testing this out by printing the C and D major scales provides the following outputs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c54b1b4e25ae49cfc48734f452b83fd/href">https://medium.com/media/0c54b1b4e25ae49cfc48734f452b83fd/href</a></iframe><p>Now, we can build a graph version of the major scale algorithm with the following implementation done in networkx (Python):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a87536777251ff160aa6ba252d524e39/href">https://medium.com/media/a87536777251ff160aa6ba252d524e39/href</a></iframe><p>When we output the C and D major scales, we receive the same result as with the conventional method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af1d00a0a890495c76875aaa1b432a11/href">https://medium.com/media/af1d00a0a890495c76875aaa1b432a11/href</a></iframe><p>The elements of the graph can also be visualized in various ways that can be intuitive to a broader audience of users. It is also interesting to note in the visual below the recursive nature of the root notes (tonic).</p><p>Here is one mechanism for implementing the visualization so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04fb1e87da523a7eaa0e9d6bdf410d4f/href">https://medium.com/media/04fb1e87da523a7eaa0e9d6bdf410d4f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*_NhdPOAPW2T6hIsRc8fE3A.png" /><figcaption>Visualization of the graph-based approach to the major scale algorithm</figcaption></figure><p>While there is more overhead in building the graph initially, the logic can be incrementally built upon in an intuitive way. We can observe this by adding the logic for a minor scale.</p><p>Let’s compare the two approaches again.</p><h4>Step 3: Adding the minor scale</h4><p>The natural minor scale has the following pattern: whole, half, whole, whole, half, whole, whole.</p><p>In the conventional approach, we create a separate function for the minor scale. This is in no way connected to the original snippet for the major scale.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ed036e89f56765db1065231352b4e0b/href">https://medium.com/media/1ed036e89f56765db1065231352b4e0b/href</a></iframe><p>We can test this with the below code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfce2b0753f99b36622660bedb855739/href">https://medium.com/media/dfce2b0753f99b36622660bedb855739/href</a></iframe><p>The composable nature of the graph allows users to see a major scale in relation to a minor scale while also having a single place for the logic. We see this when we layer in the minor scale algorithm on top of the existing foundation of the major scale code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40841ab4fc8a131b0efe0cc2182d6757/href">https://medium.com/media/40841ab4fc8a131b0efe0cc2182d6757/href</a></iframe><p>Let’s try outputting C and D major and minor scales. We can query a single graph for both.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eafc6a5d24d8735b7189bd10de613e1c/href">https://medium.com/media/eafc6a5d24d8735b7189bd10de613e1c/href</a></iframe><p>Similar to the major scale graph, this combined graph with both major and minor scales can also be visualized. This graph can be customized and made much more interactive if written in D3, but for this exercise, we will leave it in matplotlib.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70778cca6bf3df16d3d6bf109d1bf761/href">https://medium.com/media/70778cca6bf3df16d3d6bf109d1bf761/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQ0aTbcF7PaWrxK3i3JqiA.png" /><figcaption>Sample visualization of the final graph with both major and minor scales</figcaption></figure><h3>Conclusion</h3><p>In this article, we explored music theory algorithms through two approaches — a conventional python implementation and a graph-based approach. From this exercise, we can see how to construct the algorithms for major and minor scales and start to visualize how they relate to each other.</p><p>Check out the repo <a href="https://github.com/yulleyi/music-theory-algorithms">here</a> for a notebook with all of the code in one place.</p><p>What other music theory algorithms should we include next?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4dec4f70d77c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>