8. Iterator Problem: It is difficult to change how you traverse a collection or the type of collection you use in a specific scenario. Some collections are based on stacks, trees, graphs, and other complex data structures. You need a unified way to traverse a collection without knowing its structure. This may sound like an easy job if you have a collection based on a list. You just loop over all of the elements. But how do you sequentially traverse elements of a complex data structure, such as a tree? Solution: The Iterator pattern's main idea is to extract a collection's traversal behavior into a separate object called an iterator. Usually, iterators provide one primary method for fetching elements of the collection. The client can keep running this method until it doesn't return anything, which means that the iterator has traversed all of the elements. All iterators must implement the same interface. This makes the client code compatible with any collection type or traversal algorithm as long as there's a proper iterator. If you need a unique way to traverse a collection, you just create a new iterator class without changing the collection or the client. ML use case: The world of ML is extremely rich in data structures, which is no secret. Therefore, you often realize that your current data structure needs to be faster or use less memory. In the end, you must change the data structure or the way you parse your data structure. Using the Iterator pattern, you can easily decouple the collection and the client. Thus, in the end, you can quickly swap between different data structures without touching the client's code. Python uses iterators heavily. You can easily consume them with a for loop or implement custom iterators overriding the __iter__ and __next__ magic methods.


10 Underrated Software Patterns Every ML Engineer Should Know

#9. Adapter Problem: You want to integrate a new shiny package into your code. But its interface isn't matching with your current codebase. So you decide to adapt all your code to work with this package. What? NO. Solution: Instead of changing your implementation, you can wrap the classes/functions you need from the new class with a class matching your desired interface. You adapt your new package to your current implementation. That's it. Simple, yet effective. ML use case: If you are doing ML, you are likely using Python. Python's ecosystem provides many valuable packages. Therefore, you will probably start adding extra dependencies along the way. Using this pattern, you can nicely adapt your new package to your language without breaking anything else. Also, it is often good practice to wrap a package from the beginning to your own interface for future flexibility.


#10. Facade Problem: Finally, you finished your cool application and want to share it with your friends. But after you asked them to try it, you discovered they didn't understand how to use it. They told you they found it too complicated. Solution: Using the Facade pattern, you can wrap your "complicated" interface with an easier one, which is much simpler. Duh... Usually, the constructors and methods have predefined configurations that let the user use your classes/functions outside the box. Everything in the real world uses this pattern: cars, telephones, computers, etc. You want the end results that the user will use to be as intuitive as possible. ML use case: We all know how complicated ML algorithms can get. You just downloaded that cool algorithm which has only 500 hyper-parameters. When you have to use it, you feel overwhelmed. Using Facade, you will wrap up that complicated configuration with another class and hide all that away. Think about HuggingFace or Pytorch and how nicely they offer you different model architectures. You just instantiate the class, and that's it. It is up to you if you want to customize it or not.


Conclusion Thank you for reading my article! As machine learning is just a branch of software engineering, it is valuable to master various SWE techniques. When becoming an ML engineer, we tend to focus only on the latest models, feature engineering, and data-centric stuff. I am not saying these are not essential aspects, but we must remember the roots of writing clean, maintainable, and scalable software. Thus, I wrote this article as an inspiration to apply various software patterns in ML. Note that this is just a brief introduction to these design patterns, but if you are interested in the details, you can read more here. The good news is that it is quite intuitive to use these patterns after you get used to them. All of them use two main OOP principles: inheritance and composition. Sometimes, if you look only at their diagram, you can easily mix them up. Hence, the difference comes from the problem you want to solve. Every pattern solves a different issue. The article was inspired by Refactoring Guru. I recommend checking them out if you want to learn more about this topic.


Discover 3 Vital Signs Your Business is Ready for AI and Explosive Growth

Introduction Here we look at the signs that your business is ready for AI solutions, including data collection and storage requirements, staff training needs, and cost implications.


Defining Artificial Intelligence Artificial Intelligence (AI) is a term used to describe the development of robust computer systems that can think and react like a human, possessing the ability to learn, analyze, adapt and make decisions based on the available data. AI is one of the most critical technologies of the 21st century, affecting various aspects of the modern world. AI uses machine learning algorithms to classify objects and identify patterns from a vast amount of data collected. These AI systems can then use this data to make decisions quickly, reducing the need for human input.


Benefits of Implementing AI AI-based solutions are rapidly being adopted across various industries, from retail and agriculture to healthcare and automotive. AI systems can automate mundane tasks, increase customer satisfaction, improve safety, decrease costs and unlock growth opportunities. By leveraging the power of AI, businesses can get ahead of the competition, increase customer loyalty and agility, and gain access to vast amounts of customer data. AI solutions enable firms to access massive amounts of customer data in real time, helping them to focus on the customers they need to reach and prioritize their activities and operations.


What Signs Show That Your Business is Ready for AI? There is no one-size-fits-all answer when it comes to determining if a business should implement an AI solution. However, several indicators indicate that your business is ready for AI. One meaningful sign is a comprehensive data-collection process in place that produces high-quality customer data that can be used to inform decisions.Additionally, the organization's current infrastructure should be compatible with AI-based solutions and require minimal changes.Finally, the employees should be trained on how to use and benefit from AI technology. If a business can confirm these three points, then it is ready for AI solutions.


Preparing Your Business for AI The importance of data collection cannot be overstated for businesses looking to leverage the power of artificial intelligence (AI). Data is the fuel that powers machine learning algorithms, enabling them to generate insights that can revolutionize operations and bolster performance. However, it's important to note that the quality of data collected will directly impact the accuracy and effectiveness of the AI applications. When it comes to collecting data, most businesses already have some data on hand. Even without advanced technology that can crunch large data sets, it's possible to improve by honing in on what data matters most. To know what data to focus on, you'll need to consider the expected outcomes of the AI-enabled applications. Leveraging a range of data - such as customer survey responses, user behavior, sales records, and pricing data - is the primary input source for successful AI applications. The second part of preparing your business for AI is structuring and analyzing the data. To make this easier, businesses must create an organized data storage and retrieval system. Storage tools like data warehouses and data lakes will help efficiently store the data, streamlining both retrieval and analysis. With the data organized, AI applications use big data analytics to quickly process and interpret the data. The analysis helps to identify patterns and trends that can provide actionable insights. In conclusion, the data in your business is the foundation for successful AI applications. When preparing your business for AI, focus first on the quality of data collected and ensure the data is structured and analyzed for more efficient processing. With the correct data, AI can be a powerful tool for streamlining processes, optimizing operations, and boosting performance.


What New Knowledge Do Your Staff Need? When implementing artificial intelligence (AI) into a business, the staff is an important part of the equation. As AI grows in prevalence, it's essential to understand the new skills and knowledge your team needs to implement AI into existing processes. In reality, these are far more than just technical skills - they're a combination of digital and soft skills. To start, you must determine what new knowledge your staff needs to use AI successfully. Often, staff with expertise in digital and analytics are ideal candidates, as they are highly proficient users of technology. Alternatively, staff with solid project management or organization abilities are also highly suited for AI implementation. These don't have to be staff who are already familiar with AI - simply staff who have a general curiosity and understand the importance of data and how to interpret it. When launching a new AI-based task, businesses should also consider the implications of new job roles created by the implementation of AI. Some positions may require filling, such as managing new AI technologies, a data scientist to interpret data, or a Solution Architect to design and develop AI systems. These roles are necessary to successfully implement AI technologies into existing processes. Overall, staff training and knowledge will play a vital role in the success of AI implementation. To ensure that staff can use AI technologies comfortably, it is crucial to determine what skills and knowledge employees need and the job roles that need to be filled to effectively integrate AI technologies into existing processes. By understanding the training and skills required, businesses can ensure their staff is ready and knowledgeable enough to begin using AI.


New Job Roles In No-Code Machine Learning When implementing a no-code machine learning solution, the project's success largely depends on the staff involved and their ability to adjust and adapt to the new technology. With AI, in particular, technology is quickly evolving, and the latest developments come with unique job roles to match. Businesses need to identify the staff with the required skills to take on these roles, which range from data analysts to software engineers. The introduction of no-code machine learning solutions has completely revolutionized how the staff interacts with these systems. The 'no-code' approach simplifies the development process, allowing even those with a minimal technical background to be actively involved in customizing and adapting the machine learning model. Anyone can add machine learning capabilities to their existing projects with a guided step-by-step process. On top of that, no-code tools can auto-generate machine learning models easily, meaning businesses can get cutting-edge solutions up and running quickly and with minimal effort. However, it's important to remember that this doesn't mean that AI/ML-specific staff are entirely unnecessary. These no-code solutions are perfect for those with a non-technical background, but it's true to say that someone with the appropriate technical background is needed to make the most of ML models.


Infrastructure and Costs Before investing in AI, a business must consider infrastructure needs and potential costs. Artificial Intelligence needs more than just data; it requires proper infrastructure. Frankly, this is the most critical process to ensure the success of an AI project for your company. When it comes to AI, there are different models depending on what your business needs. Such models include hardware, software, servers, and data storage. Some of these tools will vary in cost and required resources, so it is important to correctly figure out how much will be needed and how to use them efficiently. In addition, it is important to consider the implications these investments may have on overall costs and whether there is a budget allocated for such investments. Fortunately, technological advancements have led to significant developments in no-code machine learning platforms. This means that those unfamiliar with technical aspects can still develop AI applications. Businesses can use the said platforms to create and deploy AI models and applications with no coding required. As a result, companies can save on development costs in implementing AI, bringing down overall costs and enabling them to access and benefit from the AI revolution with minimal investment. Such no-code machine learning platforms are great for businesses of any size. Furthermore, with no-code ML platforms, companies can avoid lengthy coding processes, take advantage of prebuilt training models, and deploy AI applications faster.


Why SaaS Industry Needs AI Software-as-a-Service (SaaS) is a popular deployment model for businesses. With its subscription fees and cloud-based architecture, many companies are turning to SaaS services to outsource their technology needs. But as the market grows, SaaS businesses and their users have increasingly relied on Artificial Intelligence (AI) technologies to remain competitive. AI has become a staple in the SaaS market, used to improve customer segmentation and provide personalized experiences. AI works hand-in-hand with SaaS companies to make their processes faster, more accurate, and more reliable than ever before. AI enables SaaS applications to offer users a more personalized experience, provide insights into customer behavior and user engagement, optimize personalized marketing, automate manual processes, and provide users with a unique and valuable experience. In other words, AI can help SaaS companies stay one step ahead of the competition and provide their users with the best possible experience. AI can be used in various ways by SaaS companies. For instance, AI can be used for customer segmentation and machine-learning-based predictions like predictive lead scoring. AI can also provide recommendations, such as the most suitable product for the customer or upcoming product updates. Finally, it can be used for automated customer onboarding, reducing the risk of customer attrition and saving valuable time and resources. AI can provide SaaS companies with invaluable insights into user behavior, revenue forecasts, enabling them to make intelligent decisions that benefit both the company and its users.


Benefits of AI for E-Commerce As e-commerce becomes an ever-increasingly profitable channel for businesses, so does the appeal of utilizing AI to propel the shopping experience. By leveraging AI and its many capabilities, online businesses can improve their marketing, automation, and customer service approach. In doing so, customers become more engaged with the brand, resulting in a higher ROI. To understand the full scope of what AI can do for a business, it's important to identify some benefits. AI-enhanced e-commerce applications can provide personalized recommendations to customers, making the overall shopping experience faster and more tailored to their individual needs. Additionally, AI can optimize product search, resulting in fewer clicks and time wasted finding items within an online store. Predictive analytics allows businesses to anticipate customers' needs and provide the best possible experience. To get the most out of AI, there are several specific areas of e-commerce where it could be implemented. For example, AI can be used to enable automated product recommendations based on past purchases and user behavior, detect fraud or identity theft, enable dynamic pricing, and create natural language-based chatbots. Personalization of the website and its content are also aided by AI, as well as tracking logistics, managing order processes, and analyzing customer sentiment by utilizing sentiment analysis. All of these tasks can enhance the overall experience of the user. The implementation of artificial intelligence in e-commerce is invaluable for businesses today. With the ability to drive customer engagement, increase sales, improve the customer journey, and reduce costs, it's no wonder that more and more businesses are turning to AI for their e-commerce needs. By taking advantage of these benefits, companies can find themselves in a position to increase their ROI, outshine their competitors and stay ahead of the curve.


How AI Improves Insurance Efficiency Insurance companies have begun to embrace AI and Machine Learning technologies to provide customers with more seamless and efficient services. AI can help insurance companies to automate various processes, including customer service, claims processing, and underwriting. AI also produces insights from large datasets, which can be utilized to reduce mortality rates, detect fraud and optimize pricing models. AI technology is transforming the insurance industry because it allows companies to personalize services and automate processes. By leveraging AI, companies are developing automated tools to aid customers in the policy purchase process, gather data to assist the underwriting process, and offer insights to create policies tailored to potential customers. Through AI-driven automation, insurance companies can streamline processes, reduce paperwork, and enhance accuracy. Additionally, AI technology can analyze customer data, such as medical records, to reduce mortality rates and detect fraud while improving the customer experience. Finally, companies can utilize AI-powered insights to optimize their pricing models. Companies can analyze data to identify trends, such as which customers are more likely not to renew their policies and why. These are just a few of the many ways AI helps insurance companies to improve their services and enhance their bottom line. It's no surprise that the use of AI in the insurance industry is continuing to gain traction, and the number of companies utilizing AI solutions is projected to triple by 2025!


Conclusion The potential benefits of implementing AI are vast and varied, providing businesses with the means to gain competitive advantage, improve efficiency and provide superior customer service. But before taking the plunge, ensure you're up to speed on the data collection and storage needs, staff training requirements, and infrastructure costs. By following these prerequisites, you can ensure that your business is well-prepared to make the most of its imminent AI technological advances. Be sure to consider no-code machine learning platforms in 2023 to make the most of the cutting-edge AI technologies and do more for less.


Like the content? Let's connect. If you believe this article is worth sharing, spread the word and help others discover its value. Fun tip: Try clicking the clap button for the magic to happen!  You can get in touch with me on LinkedIn.


This AI newsletter is all you need #28

Hottest News AI-assisted code can be inherently insecure, study findsAccording to a new study involving several developers, code-generating algorithms were found to be more prone to being insecure compared to the "handmade" solutions created by the control group. Neil Perry, a Ph.D. candidate at Stanford and the lead co-author of the study, also advises developers to double-check generated code. Here's why:What we learned about AI and deep learning in 2022As deep learning and generative models continue to make progress, the scientific community is divided on how to interpret these advances. To move forward, it is necessary to understand what is currently missing from AI systems and the architecture for the next generation of AI systems.Machines that think like humans: Everything to know about AGI and AI Debate 3The online AGI Debate #3, hosted by Vincent Boucher, the president of Montreal AI, and AI researcher Gary Marcus, discussed the lessons from cognitive science and neuroscience and the path toward achieving commonsense reasoning in AI. Here is a summary of the key points covered during the debate:


This AI newsletter is all you need #28

Three 5-minute reads/videos to keep you learning Here's a no-code tutorial on how you can create 3D assets using Generative AI technologyIn this Twitter thread, @angrypenguinPNG shares a step-by-step tutorial on how to create 3D assets using generative AI technology. The tutorial covers all the prerequisites, essential tools, and the complete process for creating 3D models.How to do video scripts on ChatGPTChatGPT's advanced conversational capabilities are making quite the buzz, but for it to produce accurate results, it needs precise and clear instructions. In this Twitter thread, @scottcmillard explains how to do it right and what factors to consider, including the inputs, variables, and more.The Brief History of Artificial Intelligence: The World Has Changed Fast - What Might Be Next?In this article, Dr. Max Roser traces the brief history of AI systems' language and image recognition capabilities and uses long-term trends to predict the future of AI. The article also discusses an important aspect of AI: creating a public resource to facilitate necessary public conversation. Enjoy these papers and news summaries? Get a daily recap in your inbox!


This AI newsletter is all you need #28

Featured Community post from the Discord DrDub#0108, an independent researcher, has just achieved over 2000 citations in the fields of natural language processing, AI, ML, and information retrieval. A big shoutout to Pablo! You can find a list of all the papers here and join in on the conversation here.


This AI newsletter is all you need #28

Article of the week The Ever-evolving Pre-training Tasks for Language Models by Harshit Sharma Self-Supervised Learning (SSL) is the backbone of transformer-based pre-trained language models. This paradigm involves solving pre-training tasks (PT) that help model the natural language. The author has made an effort to put all the popular pre-training tasks at a glance.


This AI newsletter is all you need #28

Our must-read articles Lazypredict: Run All Sklearn Algorithms With a Line Of Code by Travis Tang Markov Algorithm For Time Series by Ashutosh Malgaonkar If you are interested in publishing with Towards AI, check our guidelines and sign up. We will publish your work to our network if it meets our editorial policies and standards.


This AI newsletter is all you need #28

Job offers Senior Data Scientist @BluesInc (Remote) Senior Machine Learning Scientist @Overjet (Boston, MA/Remote) Senior Machine Learning Engineer @FarmWise (Paris, France/Hybrid) Senior Machine Learning Engineer, Applied Computer Vision @Recursion (Toronto, Canada/Remote) Cloud Machine Learning Engineer @HuggingFace (US/Remote) Climate Modeling ML Internship @The Allen Institute for AI (Seattle/Remote Hybrid)


A Comprehensive Guide to Building Multi-lingual Neural Machine Translation using Keras.

An overview of MNMT: Before diving into the implementation, let's take a step back and understand what Multi-lingual Neural Machine Translation (MNMT) models mean. Surprisingly, there are around 7,100 languages that exist in the whole world [https://www.ethnologue.com/guides/how-many-languages]. For several reasons, there is a need to translate one language into another language. Although people used to translate languages manually, the recent advancement of deep learning has enabled the automatic translation of texts. The translation of one language into another is called Neural Machine Translation (NMT). For example, given an English text, the model can translate it into Spanish. Now, what if there is a need to translate more languages? Then, we must build several NMT models that support different language translations. However, recently, research has shown that training a single model that supports multiple language translation is beneficial for several reasons. It is referred to as Multi-lingual Neural Machine Translation (MNMT). For example, some contexts from the available languages are applied to another language. Especially this use case is beneficial for low-resource languages. To illustrate MNMT, the picture below.


Data collection and preprocessing: Step 1: Collecting and clean the dataset To train an MNTM model, a parallel corpus (text) should exist within the languages. That is, in the above picture, a sentence in Japanese must have a translated sentence into English and Korean. A suitable dataset for this purpose is Tatoeba. This dataset contains sentences in over 400 languages. The sentence pair supported by this dataset can be downloaded here. Step 2: Extracting Parallel Sentence As explained above, we need parallel text between each language. Thus, we must filter out the sentences that need to be translated. For this blog, we only use English-to-{Japanese, and Korean}, as illustrated in the picture above. To find similar sentences, we can filter out the intersection between each language using the Pandas library. The code to implement this is available here. The Tatoeba dataset contains an id for each sentence. Since we downloaded "English to Japanese" and "English to Korean" paired sentences, we can find the intersection of English id's between both pairs. Thus, we can find the same English sentence and translation into {Japanese and Korean}. Now, the extracted sentences can be used to train our model. Step 3: Preprocessing the dataset Now, we can prepare the training and testing set for the model. We load the downloaded and cleaned dataset in the code below and put a starting and ending tag.


Building the model: Step 5: LSTM-based Encoder-Decoder Model In this article, we only used a different way to preprocess the dataset for the model. However, there are several approaches to building MNTM. For example, by adding additional output to the model, we could implement an MNTM. Each output layer will be responsible for predicting a single language. The model is built based on [1] But with minor changes. We chose to use LSTM instead of GRU from the original code for this example. Moreover, since we have multiple languages, we pass the input as the source language and the others as the target language. Step 6: Training the model We are using a simple LSTM model as an example so that the performance might be lower than other models. However, it is easy to build a different model and feed the same datasets as the technique mostly relies on preprocessing rather than building the model. Step 7: Checking the model's translation


References: https://github.com/fchollet/deep-learning-with-python-notebooks/blob/master/chapter11_part04_sequence-to-sequence-learning.ipynbDabre, Raj, Chenhui Chu, and Anoop Kunchukuttan. "A survey of multilingual neural machine translation." ACM Computing Surveys (CSUR) 53.5 (2020): 138.https://tatoeba.org/en/downloadshttps://ai.googleblog.com/2016/11/zero-shot-translation-with-googles.html


How To Create an End-2-End Text Paraphrase App

Paraphrasing models In order to proceed with paraphrasing algorithms, a dedicated AI model is mandatory. Hugging Face offers a wide variety of versions to accommodate a diverse range of scopes. The use of a model obtained through Hugging Face is made simple by the creation of an account and a token. In addition to that, in order to put the paraphrase feature into action for this project, I made use of the Parrot Paraphraser package. Even though the pre-trained model this package uses is called "prithivida/parrot_paraphraser_on_T5", other pre-trained or custom models can be used instead. You may use the following code to log in to Hugging Face, which will also give you access to the model:


Paraphrasing pipeline It is needed to provide the requisite functionality to generate paraphrased text from a source text. The following parameters (also sourced from the Parrot library) are utilized as a baseline by the vast majority of paraphrase products on the market today: adequacy threshold: How much of the meaning is preserved adequately. fluency threshold: How much of the paraphrased text will be fluent in the specific language. diversity ranker: Based on the different diversity rankers, how much has the paraphrase changed the original sentence (lexical, / phrasal / syntactical). The diversity ranker may take on values like "levenhstein", "eyclidean", and "diff" based on the algorithm used to determine the similarity distance between texts, while the adequacy and fluency thresholds can take on values between 0 and 1. The class Parrot has a function labeled "augment" that may be used to generate potential paraphrases of text. It requires a distinct invocation for each phrase since it operates at the sentence level. It produces a list of tuples as output. An additional set of paraphrased text is represented by each tuple as the first value. As for the second value, it's the diversity score comparing the paraphrased text to the original. For example, we have the following original text: And the output is: Since I don't always like the provided diversity score when picking a fresh, original phrase, I'll be making use of a new function made from the fuzz partial ratio from the fuzzywuzzy library: And the function that should be used for all the new sentences that are being compared to the original is: The main paraphrase function is:


Creation of the FastAPI app The answers vary, but one that is consistent is that once you have the paraphrase pipeline, the next question is how someone or something can make use of it. Perhaps there is another service or more than one service that needs to send text requests and get back the paraphrased text. If you are thinking of scalability, you are right! It plays an important role in this situation, and given the amount of time required to run the entire pipeline, it is unable to support a large number of requests with the current implementation, but this code is only the basis.


What is FastAPI? Built on top of the standard Python type hints, the contemporary web framework known as FastAPI is designed to facilitate the creation of application programming interfaces (APIs) using Python versions 3.7 and above. Here, the fundamental components will be outlined, however further information may be discovered inside the repository.


Implementation So, firstly, let's define the two basic schemas, which are the input and output classes, using the most common "pydantic" library: In order to receive the input data and have it in the suitable format, it is further essential to utilize an encoder and to develop the transformation function: Create the API's endpoint: CLI part: By running the serve command, we can have our app running at http://0.0.0.0:8000. If you are directly using the code inside the repository, please refer to the README.md file in order to follow the instructions. The endpoint can be found at http://0.0.0.0:8000/docs By pressing "Try it out" you can give your own text and parameters and check it out.


What is Streamlit? Streamlit is a free and open-source framework that enables developers to easily construct and distribute online applications for machine learning and data science. It is a library written in Python that was developed with the machine learning developers' needs in mind. In my opinion, Streamlit is a very good tool for rapid prototyping, and it may also be helpful when someone wants their analytics, etc. to be turned into a UI form.


Implementation In order to visualize the results in a nice way, let's create a basic card: Let's create the basic part of the dashboard (the config readme file and the util function can be found inside the repository): CLI part: By running the "deploy_streamlit" command, we can have our app running at http://0.0.0.0:8060. If you are directly using the code inside the repository, please refer to the README.md file in order to follow the instructions. And our app in the browser is as follows:


What is Docker? Docker is a platform that is available for free that may be used to build, deploy, and manage containerized applications. Applications are referred to be containerized when they operate in what are known as containers and are isolated runtime environments. An application and all of its dependent components, such as system libraries, binaries, and configuration files, are encased inside a container together.


Implementation The two above apps, FastAPI and Streamlit, are completely independent services. We can have two different dockerfiles, one for each service. Python 3.9 will be used as the base images. For more information, you can read the compose specification. The chosen structure is the following: For FastAPI we have the Dockerfile.api: For Streamlit we have the Dockerfile.streamlit: In order to build the images a "docker-compose.yaml" file is needed: In order to create the two above docker images, just need to run "docker-compose up".


Conclusion This article demonstrated how to develop a tool for paraphrasing text using either the FastAPI or the Streamlit programming interfaces, as well as how to generate the relevant Docker images. The pipeline for generating paraphrases is based on a pretrained model that was obtained from Hugging Face; however, other variants may be utilized in its place. You can get the code you need to follow along with the instructions at this link: https://github.com/stavrostheocharis/quotera If you have any questions, you are more than welcome to post a comment or create an issue on Github.


This AI newsletter is all you need #27

What happened this week in AI by Louis We hope you had an amazing Christmas for those of you celebrating it, else, we hope it was a fantastic week full of great challenges and success, just like 2023 will be! We are excited about many new announcements with Towards AI and the Learn AI Together community, such as podcasts, competitions, more resources to help the Learn AI community, new learning resources and tons of other open-source exciting stuff we are working on for the AI community. We will announce everything in this newsletter and on Discord. Stay tuned! As you know, this week was the week of the year with all the predictions for 2023 and recaps for 2022, which we share below as some of the coolest along the article by our head of community sharing and explaining his favorite papers of 2022 with dedicated articles for each of them. We hope you enjoy this last iteration of the year, and the Towards AI team wish you an amazing week and year ahead, which we hope to share with you on Discord. Talk with you soon! Louis


This AI newsletter is all you need #27

Hottest News 2022: A Year Full of Amazing AI papers - A Review Towards AI has compiled an in-depth list of the latest breakthroughs in AI and the key aspects of AI that were highlighted this year. The list includes developments such as ChatGPT, Galactica, DALL-E 2, and Stable Diffusion, and provides a clear video explanation, a link to a more detailed article, and access to the code (if applicable).OpenAI releases Point-E, an AI that generates 3D modelsOpenAI has open-sourced Point-E, a machine learning system that generates a 3D object from a text prompt. Point-E creates point clouds, which are sets of data points that represent a 3D shape. These point clouds can be used to fabricate real-world objects. This is a major breakthrough in the field of AI and is likely to have a significant impact on the industry.A thread on prediction for GPT-4 in 2023Open AI's GPT4 is set to be one of the first big AI things in 2023. In this Twitter thread, @RamaswmySridhar shares his predictions about the future of GPT-4, including the largest model size, pre-trained models, user-facing changes, and more.


This AI newsletter is all you need #27

Three 5-minute reads/videos to keep you learning How to spot AI-generated textThe internet is increasingly flooded with text written by AI. This article provides insight into the current tools for detecting it and explores new ways to train the human eye to spot the signs of AI-written sentences.What Building "Copilot for X" Really TakesCopilot is the start of many potential models for productionized artificial intelligence. This guide highlights the importance of estimating inference scale, determining real-time infrastructure, optimizing prompts, and integrating model outputs & UX.ChatBot PromptsThe ChatGPT prompts dataset is a valuable resource that includes prompts for a variety of action strings, such as travel guides and translations. It is a useful tool for those looking to utilize ChatGPT in a production environment. Enjoy these papers and news summaries? Get a daily recap in your inbox!


This AI newsletter is all you need #27

Featured Community post from the Discord roycoding#2504 published a new book, "Zef's Guide to Deep Learning," which provides a conceptual overview of ML and DL. In addition to the basics, the book discusses the technical concepts behind Transformers and stable diffusion. Check it out here and support a fellow community member. Drop your questions and feedback in the thread here.


This AI newsletter is all you need #27

Article of the week 10 Essential Skills for AI Leaders by Dr. Mandar Karhade, MD. Ph.D. As the field of data science and artificial intelligence (AI) continues to grow and evolve, it is important for leaders to consider whether they are equipped to navigate this complex and rapidly-changing landscape effectively. The author provides a few key considerations for determining whether your leadership is fit for data science and AI.


This AI newsletter is all you need #27

Our must-read articles Text Recognition With TensorFlow and CTC Network by Rokas Liuberskis Paper Review: Summarization using Reinforcement Learning From Human Feedback by Building Blocks If you are interested in publishing with Towards AI, check our guidelines and sign up. We will publish your work to our network if it meets our editorial policies and standards.


This AI newsletter is all you need #27

Job offers Machine Learning Engineer @ Covariant (Berkeley, CA) AI Delivery Manager (Healthcare) @ ClosedLoop (Remote) Senior/Staff Machine Learning Engineer, Infrastructure at Earnin (USA, Remote) Interested in sharing a job opportunity here? Contact sponsors@towardsai.net. If you are preparing your next machine learning interview, don't hesitate to check out our leading interview preparation website, confetti!


Choosing a Learning Rate for DNNs

WHAT IS LEARNING RATE IN DNN? The learning rate is a hyperparameter that controls the step size at which a model updates its weights during training. It determines how fast or slow the model learns, and it's an important factor in the model's overall performance. Furthermore, the learning rate determines how much the model's weights are adjusted in response to the error it receives from the loss function. If the learning rate is too small, the model will take a long time to converge to a good solution, but it will be more stable. On the other hand, if the learning rate is too large, the model may never converge or may even diverge, resulting in poor performance. It's important to find a good balance between these two extremes.


Choosing a Learning Rate for DNNs

EXTERNAL FACTORS THAT COULD AFFECT LEARNING RATE There are several factors that can affect the learning rate, including the complexity of the dataset, the type of model being used, the amount of data available for training, and the optimization algorithm being employed. For example, complex datasets may require larger learning rates to make sufficient progress, while simpler datasets may require smaller learning rates to prevent overfitting. The type of model being used can also influence the learning rate. Some models, such as neural networks, may require larger learning rates to learn effectively, while other models, such as linear regression, may be more sensitive to the learning rate. The amount of data available for training can also influence the learning rate. If the model has a large amount of data to work with, it may be able to afford larger learning rates without overfitting. On the other hand, if the model has a small amount of data, it may be more prone to overfitting, in which case a smaller learning rate may be necessary. The optimization algorithm is used can also affect the learning rate. Some algorithms, such as gradient descent, are sensitive to the learning rate and may require careful tuning to find the best value. Others, such as stochastic gradient descent, are less sensitive to the learning rate and may be able to use larger values without issue.


Choosing a Learning Rate for DNNs

TECHNIQUES TO USE FOR OPTIMAL LEARNING RATE SELECTION It's usually necessary to experiment with different learning rates and carefully monitor the model's performance to find the best value. However, a manual iteration of these values is time-inefficient and it is better to leverage more automated techniques. There are several strategies for selecting an optimal learning rate for a machine learning model. Some common approaches include: Grid search: This involves defining a range of possible learning rates and training the model with each value, evaluating the model's performance on a validation set for each value. The learning rate that results in the best performance is then chosen as the optimal value. Grid search is a straightforward and reliable method, but it can be computationally expensive, as it requires training the model multiple times.Random search: This involves randomly sampling learning rates from a defined range and training the model with each value, evaluating the model's performance on a validation set for each value. The learning rate that results in the best performance is then chosen as the optimal value. Random search is generally faster than grid search, as it requires fewer model training runs. A drawback is that it may be less reliable, as it relies on random sampling and may not thoroughly explore the range of learning rates.Adaptive learning rate methods: These methods adjust the learning rate during training based on the gradient of the loss function. Examples include Adam and RMSProp. These methods can often find good learning rate values without the need for explicit tuning. With this advantage over other optimizers, initiating with a poor choice of learning rate could lead to them never converging. They may not always find the absolute optimal value, and they may require more computational resources than other methods.Learning rate schedulers: One strategy for selecting an optimal learning rate is to use a learning rate schedule, which starts with a high learning rate and gradually decreases it over time. This allows the model to make rapid progress at the beginning of training while still fine-tuning its weights as training continues. I personally find this approach to be effective. There are several types of learning rate schedulers available in PyTorch that I have used during experimentation. While learning rate schedules can be useful in cases where the model's performance plateaus or starts to decline after a certain number of training epochs, they may require careful tuning to find the optimal schedule and may not always produce the best possible results. As stated above, the optimal learning rate can depend on the complexity of the dataset, the type of model being used, the amount of data available for training, and the optimization algorithm being employed. As such, it may be necessary to experiment with different learning rates and carefully monitor the model's performance to find the best value. Using the techniques listed above would help in the optimal learning rate selection and make training easier. If you enjoyed reading this article, please give it a like and follow. For questions, please use the comment section. If you want to chat, reach out to me on LinkedIn or Twitter.


A Visual Journey in What Vision-Transformers See

Visualize the vision transformers Since convolution neural networks (CNN) have emerged as a winning model in computer vision, different research groups have focused on understanding what these models learn. On the one hand, neural networks have emerged in several fields (from language analysis to computer vision) but have been considered "black boxes." In contrast to many other algorithms, they are much more difficult to interpret. In fact, the more capable the models become (growth in the number of parameters), the more difficult it becomes to be able to understand what is going on inside. Therefore, several methods have been developed to visualize what a convolutional neural network learns. Some of the most used: Visualize the filters (or visualize the weights).Visualize layer activationTo retrieve an image that maximally activates a neuronEmbedding the feature vectors with t-SNE.GradCAM, saliency maps. In 2016, transformers appeared on the scene. These wide models based on self-attention have been shown to achieve much superior performance in NLP (machine translation, language classification, and so on). Soon, they became the standard for NLP, and with the introduction of vision transformers, they were also applied to computer vision. Therefore different researchers have tried to visualize what vision transformers (ViTs) learn. ViTs have proven to be much more difficult to analyze, and so far, the methods used have shown limitations. Understanding the inner workings of these models could be helpful in explaining their success and potential corner cases. Previous work had focused on observing the activation of keys, queries, and values from the self-attention layer, but the result was unsuccessful. A paper has recently been published by researchers at New York University and the University of Maryland that provides a better understanding of what happens inside the model (whether they are vision transformers or models such as CLIP). In the article, the researchers summarize their contribution: While standard methods lead to uninterpretable results (especially when applied to keys, queries, and values), it is possible to obtain informative visualizations by applying the same techniques to the next feed-forward layer of the same transformer block (and they demonstrated this using different models: ViTs, DeiT, CoaT, ConViT, PiT, Swin, and Twin transformers).Patch-wise image activation patterns for ViT features behave like saliency maps demonstrating that the model preserves positional relationships between patches (and learns this during training).CNN's and ViTs construct a complex and progressive representation (in CNNs, the first layers represent edges and textures, while later layers learn more complex patterns, and the authors show that the same happens in ViTs). ViTs, in contrast to CNN's are better able to use background information.The authors also applied their method to models using language supervision (such as CLIP) and showed that features could be extracted from these models that are associable with caption text (such as prepositions, adjectives, and conceptual categories). The authors compared ViTs to convolutional networks and noted that the representation increases in complexity along the pattern (earlier layers learn simpler structures while more sophisticated patterns are learned by more advanced layers). In practice, both CNN and ViTs share what is called progressive specialization. There are also differences. The authors investigated the reliance of ViTs and CNNs on background and foreground image features (using bounding boxes on ImageNet). ViTs are able to detect background information present in the image (in the image, for example, grass and snow). In addition, by masking the background or foreground in the image the researchers showed that ViTs not only use the background information better but are also less affected by its removal. In other words, during training, the model learns how to preserve spatial information. In addition, the last layer instead has a uniform activation pattern and learns how to classify the image (according to the authors, the last layer has the function of globalizing information). In recent years, vision transformer models have been trained with language supervision and contrastive learning techniques. One example of all is CLIP. Because these models are increasingly used and increasingly competitive, the authors also analyzed CLIP. The model shows that there are features related to conjectures, such as "before and after" or "from above." In other words, there are features that represent conceptual categories and are clearly discernible:


Conclusions To understand, seeing is always better. In recent years there has been an increasing emphasis on the need for the interpretability of models. While there are many worked methods on CNNs, being able to visualize the features of ViTs was not possible. The authors not only identified a method to be able to do this (they showed that one had to use the feed-forward layer and not the self-attention layer) but also analyzed the properties of these features. They showed how the model is capable of learning spatial relationships during training and how, on the other hand, the last layer does not participate in this spatial representation. Furthermore, although ViTs are similar to convolutional networks, part of their success for the authors is derived from how they make better use of background-related information. They also show that when ViTs are trained with d with language model supervision, they learn more semantic and conceptual features rather than object-specific visual features. Code: here, article: here


if you have found it interesting: You can look for my other articles, you can also subscribe to get notified when I publish articles, and you can also connect or reach me on LinkedIn. Thanks for your support! Here is the link to my GitHub repository, where I am planning to collect code and many resources related to machine learning, artificial intelligence, and more. Or feel free to check out some of my other articles on Medium:


Paper Review: Summarization using Reinforcement Learning From Human Feedback

Introduction OpenAI's ChatGPT is the new cool AI in town and has taken the world by storm. We've all seen countless Twitter threads, medium articles, etc., that highlight the different ways ChatGPT can be used. Some developers have already started to build applications, plugins, services, etc., that leverage ChatGPT. While the exact workings of ChatGPT aren't yet known since OpenAI hasn't released a paper or open-sourced their code yet. We do know that they leverage the idea of Reinforcement Learning from Human Feedback (RLHF) In today's article, we'll dive into a prior work of OpenAI where they used RLHF to learn to summarize documents. This article will consist of the following sections. Dataset CreationSupervised Fine TuningTraining a Reward ModelReinforcement LearningPartial Policy Optimization


What are the datasets? OpenAI creates a dataset by sampling from the Reddit TL;DR dataset. This dataset consists of posts followed by a TL;DR written by the creator of the post. The TL;DR is treated as the summary of the original post. The original TL;DR dataset consists of 3 million posts. However, OpenAI runs a few filters for quality and also filter summaries that are between 24 to 48 tokens long. The reason for the length filter is to limit the influence of the length of a summary in determining its quality. Post filtering, their dataset contains 123,169 posts, out of which 5% is used as a validation set. In the image above, you can see the distribution of posts and the subreddits that they are from. OpenAI has also made the dataset publicly available here.


Methodology At a high level, the methodology consists of the following three primary steps: Supervised Finetuning (SFT)Creating a Reward ModelTrain a Reinforcement Learning Model that leverages the Reward Model.


Supervised Finetuning (SFT) This step is similar to the fine-tuning step of any pre-trained transformer model so that it can make task-specific predictions. In this particular case, the authors train the model to predict/generate the summary given the post. Instead of using an out-of-box pre-trained transformer model, they reproduce the standard transformer architecture and pre-train it to predict the next token. They use the following corpora for pre-training: CommonCrawlWebTextBooksWikipedia The input sent to the transformer model for predicting the summaries follows the template shown below:


Fundamentals of Reinforcement Learning The idea behind Reinforcement learning (RL) is that an agent learns from the interactions it has with the environment/world that it is acting in. An example of an agent that learns from RL is a game like Pacman. The agent can choose to move in certain directions with every action it takes. The agent may receive some feedback from the environment as it makes certain actions. The feedback could be an increasing number of points, being killed, etc. The feedback received is termed a reward, and all the information that the agent can perceive and utilize to decide on what action to take next is referred to as the observed state. In RL, the goal of an agent is to maximize the reward it can receive. A single action taken by an agent is referred to as a step, and a series of steps that lead to the end of a game is referred to as an episode. In the context of summarization, the observed state is the textual content of a post, and the actions that the agent can take are to output a token one by one (per step) and generate a summary per episode. However, we need to find a way of rewarding the agent at the end of an episode. The reward needs to be a scalar value. In RLHF, we train a reward model that judges the output of our agent and provides a score that is used as the reward.


Collecting data for a Reward Model To train a reward model, the authors sample a post from their dataset and then obtain a bunch of summaries. Some of the ways they obtain summaries for a given post are: Sample from the SFT modelSample from the Pre-trained model without SFT by passing in some in-context examples of summarization.Use the ground truth summary written by the creator of the post. A new task is created by taking pairs of summaries for a given post and asking contracted labelers to choose which summary they prefer between the two.


Training a Reward Model To obtain a reward model, the model resulting from SFT is used as a starting point, and the layer used to predict the tokens is replaced with a new head (linear layer) to obtain a scalar score for a post + summary document sent to the reward model. Keeping with our dataset created above, both of the candidate summaries for a given post are individually passed to the reward model to obtain a score for each summary. The model is trained to maximize the difference in scores between the preferred summary and the other candidate summary or, in other words, minimize the negative difference in scores. This can be observed in the loss function shown below where y_i corresponds to the preferred human summary, y_(1-i) corresponds to the other candidate summary and, x corresponds to a post, r corresponds to our reward model, D corresponds to our dataset from which samples are drawn. Great now we have a reward model that should produce high scores for good summaries and low ones for bad summaries! The next step is to leverage the reward model in an RL environment.


Fundamentals of Proximal Policy Optimization A policy in RL determines what action(a) an agent should take given a state(s). A policy is often represented by the symbol π. In the context of this paper, our initial policy is our transformer model that generates a summary. In RL, we're trying to learn the best possible policy so that our agent can get the highest reward possible. We update our policy by updating the weights of our summarization model at the end of each episode. An episode in the context of this paper would be a batch of posts for which our policy generates summaries. PPO is an algorithm that focuses on how to update the parameters corresponding to our policy. The loss for the policy model can be represented by the following three equations : Based on equation 1 we want to find the ratio between the probability of taking some action a for a given state s based on our current policy and the probability of taking the same action a, for the same state s according to our previous/old policy. The idea behind Proximal Policy Optimization (PPO) is that we want to avoid changing the policy drastically in a single step. The perils of changing the policy too drastically are that the agent might forget what it learned so far and end up in a space where performance is very low, and re-learning what it forgot could take a lot of time. The ratio computed from equation 1 gives us an idea of the magnitude of the change in the policy. The Advantage function depicted in equation 2 is a measure of how much better or worse taking action a at state s is compared to the average reward expected at that state. Essentially it is a way of telling whether we are taking a good action or not. If you're unfamiliar with Q-values and the Value function, I'd recommend diving into the RL course created by Huggingface, linked in the reference section. In equation 3, the clip function binds the values of the ratio between the range of 1-epsilon and 1+epsilon, epsilon is usually a constant value in the range of [0.10.2]. The Loss function L_ppo ensures that the gradient is 0 when: Ratio < 1-epsilon and Advantage < 0Ratio > 1+epsilon and Advantage > 0 To sum up those two cases up, we don't want to update our policy any further if we are already aware that the action we are taking is pretty good or pretty bad and update it in all other cases. If you're unclear on why the gradients would be zero for the above two cases, please refer to this article.


Updated Reward Equation The authors of the paper also add a KL divergence penalty to ensure that the updated policy doesn't diverge too far from the original SFT model. This is to ensure that the model doesn't find a way of maximizing the reward function by cheating and producing an incoherent summary. It also ensures that the output summaries generated by the new policies aren't too dissimilar from what the reward model was trained on. The final equation for the Reward is The PPO-Clip algorithm can follow an Actor-Critic based training paradigm. The Critic is responsible for giving us the Q-values (Q(s, a)) also referred to as a Value function. The value function is represented by another Transformer model initialized with the same weights as the reward model. Since the authors don't mention any other information regarding the Value function, we assume that they optimize it by minimizing the difference between the Value function's predicted reward and the actual reward provided by the Reward function. To summarize, we have three different models: Policy ModelReward ModelValue Function Model All three models are based on the transformer architecture.


Conclusion The authors of the paper make the following conclusions based on their experiments: "Training with human feedback significantly outperforms very strong baselines on English summarization." : This was based on the evaluations run by the labelers."Human feedback models generalize much better to new domains than supervised models": This is based on the performance of the model trained on the TL;DR dataset against the CNN/DailyMail dataset. In today's article, we discussed how Reinforcement Learning from Human Feedback could be used in an NLP setting to summarize documents. If you have any queries or thoughts on the paper, please do drop a comment.


This AI newsletter is all you need #26

What happened this week in AI We were interested to see two new models out this week which we think can increase the flexibility and capabilities of ML towards search, document and data processing. OpenAI released its new and improved embedding model which outperforms Davinci at most tasks at a 99.8% lower price. The new model replaces five separate models for text search, text similarity, and code search, while increasing context length 4x and reducing embedding size. The model is a more powerful tool for natural language processing and code tasks and we think it has lots of interesting applications including for semantic search. While not related, we were also interested to see Microsoft release its new Universal Document Processing (UDOP) model. It is a foundation Document AI model for document understanding and generation tasks, where text is structurally embedded in documents, together with other information like symbols, figures, and style. It sets the state-of-the-art on nine Document AI tasks across various domains and ranks first on the Document Understanding Benchmark leaderboard. We think these models are both potentially parts of a toolset for building AI applications where accuracy, relevancy and reliability of data recall and understanding are important.


This AI newsletter is all you need #26

Towards AI and Learn Prompting competition collaboration We are also organizing a fun competition around prompting in collaboration with our friend Sander and the open-source course Learn Prompting! We will be kicking off the competition this week on the Learn AI Together Discord server (with a fun live stream!) and will announce it in next week's newsletter too. Stay tuned - the competition (accessible for all) will hold until December 31st! Join us on Discord and enter our competition to have the chance to win cool prizes!


This AI newsletter is all you need #26

Towards AI Job offer We are continuing to look for contractors to join Towards AI (~10 hours per month) to work on building learning resources (mostly open-source) for our community. We are looking for experience in one or both of the following: NLP (LLMs implementation & prompting).Image generation models (implemented stable diffusion or other image synthesis model and experience prompting (or fine-tuning) with them). Message me @Louis B on Discord or by email for more information!


This AI newsletter is all you need #26

Hottest News Stanford CRFM's PubMedGPT 2.7BA new 2.7 billion parameter language model trained on biomedical abstracts and papers. The GPT-style model is capable of strong performance on a range of biomedical natural language processing tasks, including a new state of the art performance on the MedQA biomedical question answering task.The state of AI in 2022 - and a half decade in reviewThis report offers an in-depth look at the past five years in the field of artificial intelligence, including statistics on AI adoption by companies, the most popular use cases for AI, and the level of investment in the technology and development in AI, and more...DeepMind's AlphaCode Conquers Coding, Performing as Well as HumansDeepMind's AI system has demonstrated impressive results in coding tasks, performing as well as humans on tests with 5,000 participants. This article explains the unique features of this AI and how it is able to achieve such high levels of performance. Is the future of coding already here?Geoffrey Hinton proposes an alternative to backpropagation: the Forward-Forward AlgorithmIn a new paper, Geoffrey Hinton introduces the Forward-Forward (FF) algorithm as an alternative to backpropagation. @martin_gorner has summarized the key points of the paper in a Twitter thread. Hinton argues that, while it is unlikely that the human brain uses backpropagation to learn, FF is a possible alternative, can be very power efficient and is well suited for self-supervised learning.


This AI newsletter is all you need #26

Three 5-minute reads/videos to keep you learning Understanding Convolutions in Probability: A Mad-Science PerspectiveThis article explores the concept of convolutions from a probability perspective, including how to use them, how to compute them, and their mathematical definition. It provides clear examples and a visual map to help simplify the learning process.Some Basic Image Preprocessing Operations for Beginners in PythonIn this article, Rashida discusses some essential image preprocessing operations using OpenCV in Python, including translation, resizing, and cropping. If you are new to image processing and want to learn about these basic techniques for tasks such as image classification, object detection, or optical character recognition, this article is a great resource.This Year's Most Thought-Provoking Brain DiscoveriesThis article highlights the standout brain discoveries from the Society for Neuroscience meeting in 2022, providing insights into the latest breakthroughs in neural circuits. It's an interesting read for anyone looking to learn more about the latest developments in the field of neuroscience. Want more? Dive deeper into one of them with the What's AI weekly!


This AI newsletter is all you need #26

Meme of the week! Meme shared by friedliver#0614


This AI newsletter is all you need #26

Featured Community post from the Discord altryne#7376 submitted a fun project for the assemblyAI hackathon.ChatGP-T1000 is an AI shape-shifter bot, that assumes identities understands your natural language, and replies with chatGPT responses, in character with deepfaked audio and lipsync. Check it out here and support a fellow community member! You can leave your feedback in the thread here.


This AI newsletter is all you need #26

AI poll of the week! Join the discussion on Discord.


This AI newsletter is all you need #26

Article of the week Grid Search in Python A-Z: Searching for Perfection by Gencay I. Among many performance-boosting techniques in Machine Learning, the author explains Grid Search & Random Search. In grid search, the algorithm searches the best set of hyperparameters for a machine-learning model over a predefined grid of hyperparameter values. In contrast, random search involves selecting random combinations of hyperparameters and evaluating the model's performance for each combination.


This AI newsletter is all you need #26

Our must-read articles Support Vector Machines by Data Science meets Cyber Security ChatGPT: How Does It Work Internally? by Patrick Meyer If you are interested in publishing with Towards AI, check our guidelines and sign up. We will publish your work to our network if it meets our editorial policies and standards.


This AI newsletter is all you need #26

Job offers Product Lead, AI/ML @ Inworld.AI (USA, Remote) Data Engineer @ Sword (USA, Remote) Machine Learning Engineer @ Covariant (Berkeley, CA) AI Delivery Manager (Healthcare) @ ClosedLoop (Remote) Senior/Staff Machine Learning Engineer, Infrastructure at Earnin (USA, Remote) Interested in sharing a job opportunity here? Contact sponsors@towardsai.net.


Perplexity Ask: A Game-Changing Search Tool Powered by AI

Introduction to Perplexity Ask Perplexity Ask is a new search interface that uses advanced artificial intelligence technologies, such as OpenAI's GPT-3 model, to provide direct answers to questions and summaries and citations for search results. This is a major departure from traditional search engines that simply provide a list of links, and allows users to quickly and easily find the information they need without having to click through multiple pages or search through irrelevant results. One of the standout features of Perplexity Ask is the inclusion of citations for the search results. This is a valuable tool for verifying the accuracy of the information provided and helps to ensure that users are not misled by incorrect or misleading information. In this way, Perplexity Ask is similar to the Google PageRank algorithm, which uses citations as a way to determine the quality and relevance of a webpage.


Examples of Perplexity Ask in Action But Perplexity Ask is not just a useful tool for finding information - it can also provide insights and reveal interesting or unexpected results. For example, when I searched for "twitter files, all parts" Perplexity Ask provided a summary of the internal documents shared by Twitter owner Elon Musk with independent journalists in December 2022, as well as citations for further information. The summary revealed details about Twitter's operations, including how it deplatformed President Trump and how the FBI reimbursed Twitter over $3 million for work done regarding legal process. Another interesting search I conducted was "what does Elon Musk say about OpenAI ChatGPT" Perplexity Ask provided a summary of the chatbot created by OpenAI, which was founded by Musk, and its relationship to the GPT-2 algorithm. The summary also mentioned that Musk put a stop to the chatbot accessing Twitter's database to train itself and that he has previously called it "scary good" and warned that we are not far from dangerously strong AI. Perplexity Ask can also be useful for finding practical solutions to problems, such as when I searched for "access private S3 buckets securely" Perplexity Ask provided a summary of different methods for accessing private S3 buckets securely, including pre-signed URLs, VPC endpoints, IAM user policies, and configuring S3 bucket access parameters.


The Future of Search In addition to its valuable search capabilities, Perplexity Ask has a few other notable features. It does not include distracting ads and does not require a sign-up or login to use. It also does not collect personal information, making it a secure and private way to search for information. As AI continues to advance and more powerful language models become available, it is likely that we will see even more innovative search tools like Perplexity Ask. These technologies have the potential to greatly enhance our ability to find and verify information online and will likely play a major role in shaping the future of search.


Conclusion In conclusion, Perplexity Ask is a game-changing tool that has the potential to revolutionize the way we access and evaluate information online. Its use of advanced artificial intelligence technologies and the inclusion of citations for search results make it a valuable resource for quickly and accurately finding the information you need. With the potential to reshape the future of search, Perplexity Ask is definitely worth checking out. I encourage readers to try out Perplexity Ask for themselves and see how it can improve their information search process. Remember to not enter personal information and be aware of the possibility of offensive or dangerous content. Perplexity is not liable for any content generated. So if you're looking for a new and improved way to search for information, give Perplexity Ask a try and see how it can transform your information search process.


Diffusion Models - my "second?" artist.

The two processes are in detail If you are not familiar with the Stochastic processes, the following may give you a headache. To the best of my knowledge, I will explain it intuitively.


Diffusion Models - my "second?" artist.

The forward process The process is a fixed Markov Chain with Gaussian transition with a variance schedule β1, ..., βT. At each time step, the process will add a Gaussian noise with a given variance to the image.


Diffusion Models - my "second?" artist.

Intuitive explanation Say each image is a data point, then your entire dataset will form a distribution. The transition q(x_t  x_t-1) tells us the distribution of the next state x_t given the current state x_t-1. Then, the forward process can be done by recursive sample data from a given distribution. Or, mathematically, we have the closed form: Where α_t:= 1 − βt and α¯t is the cumulative product of a_0 to a_t. Then we can sample directly x_t from x_0 given the scheduled variance. And when the time step T is large enough, note that (1-βt) < 1, α¯t will reach to 0. This means the distribution of x_T will be approximate, a standard multivariate Gaussian.


Diffusion Models - my "second?" artist.

The reverse process This process is our deep learning model, where you sample some random noise and get an image. BUT how does it work? As above I mentioned that, we could treat our dataset as a distribution. Hence, if we find some way to sample a data point from it, we'll get a real-looking image. Then the task for our model is to learn to sample the data distribution by trying to reverse the forward process. Particularly, in generating, the inputs of model, x_T, will be in standard Gaussian, then it reverses the process with learned Gaussian transition: > Training Given an input image, the forward process will sample x_tthe sampled x_t will then feed into the model and try to predict the image The loss is then computed by: This can be explained as the KL divergence between the distribution of the transition of the two processes. In practice, this formula is simplified to: There is quite a lot of math and other parameterizations to get to this, so I left it for you who are interested in reading the paper.


Diffusion Models - my "second?" artist.

Why is KL Divergence? KL Divergence tells us the long distance between the two distributions. What we want is to make the distribution of the generated images will be similar to the distribution of the images in the dataset. Then by minimizing the KL Divergence, the distribution of generated images will be pushed close the real distribution. Pondering: This is not the only function that can tell how far the 2 distributions are. Indeed, in training GAN for a similar task, sometimes we use "earth-mover-distance" (Wasserstein Loss). But why is the KLD chosen?


Diffusion Models - my "second?" artist.

Train a model to generate a celeb face. I used the excellent work from lucidrains/denoising-diffusion-pytorch to train on the CelebA dataset on Kaggle. My notebook THANK YOU This is my first article to share the knowledge I gain during my internship. I hope what I share here can help others. If you found this helpful but there is something missing, please share your thought in the comment. I will very much appreciate it.


Java Transfer Learning for Image Classification with Small Dataset

1. The data set and the problem formulation In this blog post, we demonstrate with the fruit fresh and rotten dataset, which is publicly available from the Kaggle contest. This dataset is composed of pictures with one fruit in it, either fresh or rotten. So, the task of detecting the rotten fruit can be formulated as a 2-class classification problem. This task has a potential application in a grocery stores in building automatic rotten fruit detection. Here are some examples of the image data. Fresh/rotten banana dataset: Fresh/rotten apple dataset: It is then clear that the fruit images indeed have enough visual variation distinguishable for a classifier model.


2. The transfer learning model Based on transfer learning, the model is built on top of a large pre-trained model, which is used to get an embedding vector. Then the embedding vector is fed into the subsequent fully connected layer, followed by a SoftMax activation function. Thus, through transfer learning, users can benefit from the large pre-trained model and solve their own customized problems. The pretrained model used in this demonstration is ResNet18. You can obtain an embedding model made of it from ATLearn, or manually from PyTorch. Here we show the method using ATLearn, where the embedding model can be directly exported. At this step, what ATLearn does is remove the last layer of ResNet18 to get the intermediate vector and then trace and export the model as a TorchScript file resnet18_embedding.pt, which can then be directly loaded in DJL. This part will be introduced in the next section.


3. The demonstration of transfer learning in Java Overall, this transfer learning feature is a training feature, so its API shares similarities to other DJL training examples. It mainly contains model structure, data loading, training configuration, and metrics. 3. 1 Setup To get started with DJL transfer learning feature, add the following code snippet to the build.gradle file, which defines the necessary dependencies. 3.2 Model building 3.2.1 Load the embedding in DJL and build the model. As mentioned before, we have generated an embedding layer from ATLearn. Now we can load it into DJL. This embedding layer is also available at modelUrl = "djl://ai.djl.pytorch/resnet18_embedding". In DJL, the model loading is implemented with the criteria API, which serves as the criteria for to search for models. It offers several options to configure the model. Among them trainParam is an option specific for transfer learning (or model retraining). Setting it "false" will freeze the parameter in the loaded embedding layer (or model), and "true" will be the other way around. On top of the embedding model, we further add a fully connected (FC) layer (also denoted as MLP layer), the output dimension of which is the number of classes, i.e., 2, in this task. We use a sequential block model to contain the embedding and fully connected layer. The final output is a SoftMax function to get class probability, as shown below. 3.2.2. Trainer configuration. The configuration of the trainer mainly contains the settings of the loss function (SoftmaxCrossEntropy in this case), the evaluation metric (Accuracy in this case), training listener which is used to fetch the training monitoring data, and so on. In our task, they are specified as shown below. At this step, we will assign different learning rates on these two layers: the learning rate of the embedding layer is 10 times smaller than that of the FC layer. Thus, the pretrained parameters in the embedding layer is not changed too much. This assignment of learning rate is specified with learningRateTracker, which is then fed into the learningRateTracker option in Optimizer, as shown below. After this step, a training configuration is returned by setupTrainingConfig the function. It is then used to set the trainer. Next, the trainer is initialized by the following code, where the parameters' shape and initial value in each block will be specified. The inputShape has to be known beforehand. 3.2.3 Data loading. The data is loaded and preprocessed with the following function. Here, the data are preprocessed with the normalization and randomization functions, which are commonly used for image classification (see this tutorial). The randomizations are for training only. 3.2.4 Model training and export. Finally, we can run the model training with Easytrain.fit, and save the model for prediction. In the end, the model.close() and embedding.close() are called. In DJL, during the creation of Model and ZooModel<NDList, NDList>, the native resources (e.g., memories in the assigned in PyTorch) are allocated. These resources are managed by NDManager which inherits AutoCloseable class. When running the training code, the VM option needs to be set -Dai.djl.default_engine=PyTorch to specify the engine. The generic output of the training process will be the following: Here, you can monitor the training and validation accuracy and loss descent.


4. Experiment with the reduction of the training data size The key advantage of transfer learning is that it leverages the pretrained model, and thus it can be trained on a relatively small dataset. This will save the cost of data collection and annotation. In this section, we measure the validation accuracy vs. training data size on the FreshFruit dataset. The full experiment code is available here. In this experiment, the training dataset size needs to be controlled and randomly chosen. This part is implemented as below, where cut is the size of the training data. The result of validation accuracy v.s. training data size is below. Fresh/rotten banana classification: Fresh/rotten apple classification: Here, we have tested two scenarios: freeze ResNet layers and update only MLP and update all layers. As expected, the stable accuracy of the latter is slightly better than that of the former, since the ResNet parameter is also fine-tuned by the data. We can also see that the accuracy of the banana data reaches stable 0.95 with 30 samples, and the accuracy of the apple data reaches stable 0.95 with around 70 samples. They are both relatively smaller than the provided training data size by Kaggle, which is over 1000. This verifies that indeed the required training dataset is small. When people need to collect and annotate data, this offers a reference on the minimum required data size.


5. Summary In this blog post, we demonstrate how to build a transfer learning model in DJL for an image classification task. This process is also applicable in model retraining. Finally, we also present the experiment on how much the training data set can be reduced. The direct benefit of the reduction is that it helps to save the expensive data collection and annotation costs. This makes it much easier to leverage the large pretrained models to solve other various tasks with small datasets. This demonstration is similarly applied to other tasks and data, like mask-wearing detection and fruit freshness regression. See examples in ATLearn for their implementation in python, as well as other examples of object detection.


A Journey into the Fabulous Applications of Transformers - Part 2

6. Translation An interesting and useful application with transformers is the ability to translate text between languages. Several models are available for the translation task, depending on the languages being used in the training phase. In our example, we are going to translate an English language text into Italian language. To know what model can perform the translation, we have to explore the Hugging Face library. The model named Helsinki-NLP/opus-mt-en-it performs this translation, and we will use that for our demo. The first step is to instantiate the pipeline with the task translation.The task name varies according to the languages being dealt with. More information on the translation of the text in different languages, the corresponding models, and the datasets can be found in this link. In our case, the task is translation_en_to_it and is given along with the model name as follows. input_text is stored with the English sentence that we wish to translate. In the following line, we load the input to our model and store the output in italian_text. On printing the same, we get the translated version of our input.


7. Token Classification Token classification is the task of assigning a tag/label to words present in the text. An individual word in the sentence is called a token. Examples of token classification are Named Entity Recognition(NER) and Part-of-Speech(PoS) tagging. We have covered NER in the first part of our article, and so here we will look at the second task, PoS tagging. Part-of-Speech tagging is the process of identifying the corresponding part of speech of a word and labeling it with tags like nouns, pronouns, adjectives, adverbs etc, in a sentence. We begin by importing pipeline and instantiating it with the task token-classification. As given above, the model we have used is vblagoje/bert-english-uncased-finetuned-pos. Now we shall classify the tokens and display them. To see the output clearly, we shall import pandas and create a dataframe of the result and see the output as shown below.


8. Sentence Similarity An interesting application with transformers is the ability to extract sentence embeddings that captures semantic information. A sentence embedding is the numerical representation of a whole sentence and is used as input to the model. In our example, we will use a sentence transformer to generate sentence embeddings and use it to identify the similarity between two sentences. For this example, we have to install sentence-transformers library from hugging face, unlike the other applications where we will install transformers library. There are many models available for the task of sentence similarity, and we are going to use the model sentence-transformers/all-MiniLM-L6-v2 in our example. The first step is to import SentenceTransformer and util as shown below. The util package is needed to use the cosine similarity function to measure the distance between the two embeddings. Next step, we load the input_sentences with sentences that we would like to try our model with. We give the specific model name to be used to the SentenceTransformer. In the next step, we extract the embedding for both sentences. The embeddings for both sentences are stored in separate variables. In the last step, we utilize the cos_sim function from util to calculate the distance between two vectors (embeddings) The more the value closer to 1, the more the similarity between the sentences. If the value is closer to 0, we can understand that the sentences are not similar.


9. Zero-shot classification Zero-shot classification has its root in Zero-shot learning which basically means a classifier is trained with one set of labels and tested with a different set of labels. The evaluating set of labels is not seen by the model at all. This means we can take a zero-shot classification model, give input and also give labels of our own. The model will classify the text according to the labels given by us, even though the model was not trained by any of these labels. Now we will try out the same in our demo. Let us start by instantiating the pipeline with the task zero-shot-classification. As we have not given a specific model, the model facebook/bart-large-mnli is selected by the library, and the model weights are downloaded and referred with zero_shot_classifier. The next step is to define the input text and the labels with which we need the classification. Using the zero_shot_classifier, we pass the input text and labels to be classified. To see the output clearly, we shall import pandas library and see the result in a data frame. As shown in the below data frame, the score for the labels food and sad are more than the other labels. We can see that the sentence given, relates to the label food more than all the other labels. So we get the highest score in that.


10. Fill Mask The concept of Masked Language Modeling (MLM) deals with predicting words to replace the purposefully masked words in the data. This helps in improving the statistical understanding of the language with which the model is trained and leads to better text representations. The merit of MLM is the self-supervised pretraining that does not need labeled data for training. The task Fill Mask, thus dealing with masking random words in the given sentence and exploring the various suggestions given by the model for replacing the mask. Let us start with instantiating pipeline with the fill-mask task as shown below. Since we have not given a specific model, the default model (distilroberta-base) is downloaded. Now we give a sentence to the model by masking a word in it with the <mask> token. On printing the output, we see five different possible words for the masked word, the corresponding score, the token representation, and the complete sentence with the predicted word.


Summary In these two parts of the article, we went through the most important 10 applications that are achievable with the transformers. The takeaway is that, with the rise of transformers and large language models, complex tasks that would have needed heavy cost and time are now available to use at ease. It also has to be noted that the same model can be used for different tasks. The idea is to understand the possibilities of a model and fine-tune it for your own purpose. The more we try, the more we learn. Proceed and Succeed!!!


The Rise of AI: A Look at the 2022 Landscape

Generative AI In early 2022, DALL-E stunned the world with its ability to create images with a simple text prompt. It looked like it would be state-of-the-art for a long time instead, in a short time, Google released two new models (Imagen, Parti). Today we can say that the real game-changer was Stable Diffusion. In fact, as the source code has been released, it has been integrated into several applications (even Photoshop has created its own plugin on it). It was not long after the release of DALL-E that META, Google, and other companies released templates that turned text prompts into videos. In addition, research also continues on generative music. We can say that 2022 was an explosive year for generative AI, and we can expect new models (especially in improving text-to-video and generative music).


AI and science In 2022, Google released Minerva, a model capable of solving scientific problems. The model was capable of answering various math, science, engineering, and machine-learning questions. Meta has also invested in the field, both with Galactica, and we are likely to see more such models. These models are capable of solving problems that have already been solved. Suggesting new hypotheses is something much more difficult. Therefore, DeepMind's AlphaTensor has attracted the attention of researchers. DeepMind's model succeeded through reinforcement learning to suggest for the first time in fifty years a new (and faster) way to multiply matrices. The research does not stop at mathematics, DeepMind has teamed up with the University of Lausanne to design a model to help stabilize plasma in nuclear fusion. This shows how AI will help in solving complex problems, and we will probably have an AI research assistant soon.


AI and biological science In 2021, scientists were surprised by AlphaFold2's ability to predict protein structure from its sequence. This was an extremely complex problem with important practical implications (medicine, drug discovery, agriculture, pollution control, and so on). AlphaFold2 is a sophisticated model that requires large computational resources. META ESMfold and Salesforce (ProGen2) showed that even using language models, one can obtain predictions with fewer computational resources and in a short time. This year and in the coming years, we will see how these models will advance research. In fact, many start-ups have sprung up this year that are intent on designing proteins from scratch, using these models to improve drug discovery, and so on (even large pharmaceutical companies are investing in the field). In addition, OpenCell has shown how AI enables a better understanding of protein localization. Another interesting work used machine learning to identify new anti-bacterial molecules (however, as demonstrated by King College researchers, the same techniques can be used to generate biochemical weapons). All these articles show an increase in the usage of AI in biomedical science (as a word of caution, not always machine learning is used properly).


A new phase in the use of AI in video games. In recent years DeepMind has shown how an agent can easily win against humans (GO, chess, and so on). This is not research for its own sake; video games provide a playground for various tasks that can then be translated into the real world. For example, OpenAI used Minecraft as a kind of testbed for computer-using agents. In addition, META's CICERO has not only demonstrated that it could play a game but also that it is capable of collaborating with humans in a strategy game. This work demonstrates a new phase of research, more oriented toward practical applications and the possibility of the future of these models being used to interact with people (customer service, non-playable characters in video games). On the other hand, CICERO also opens up disturbing ethical issues: in order to win the game, the agent had to convince other players to take action at the expense of their chance of winning. Similar models could be developed for scamming and other dangerous applications.


Code research, a new frontier This year we saw the release of GitHub Copilot (based on OpenAI Codex). On the same front, DeepMind AlphaCode has shown human-like performance in competitive programming. Other companies are also pointing in the same direction (Salesforce's CodeGen, Huawei's PanGu-Coder), showing that the trend is growing. In addition, the recent ChatGPT is also capable of producing code on demand. As some experiments show, this code is not always reliable. On the other hand, the programming community has not received well the arrival of these models that have been trained using code on GitHub. In fact, two lawsuits are pending against GitHub Copilot and whose outcome could have a disruptive effect (after all, even AI art models have been trained using the work of artists scraped from the internet). In any case, we can expect more such models in the future. Probably, we will not see AI as data scientists for a few more years, but data scientists in the coming years will be writing code together with AI assistants.


Institutions are waking up: AI regulations are coming In both the United States and the European Union, lawmakers are moving toward regulating AI. The new EU law is expected to arrive next year (although there are drafts today, and you can see the direction). On the other hand, institutions have realized that research is in the hands of industries and a few big players. It seems expected in the near future that, institutions in both Europe and the States will invest in university research in AI. Not to mention that there will be new investments and regulations on semiconductors, chips, and other strategic materials. In addition, the current geopolitical situation suggests that there will be investments in AI and defense. For example, NATO has announced that it will invest in companies working in the field.


Safety has been at the center of the debate As the report 'UK's national strategy for AI' showed in late 2021, safety would be at the center of the debate in 2022 and the years to come. Most researchers in a 2022 survey said they considered AI safety a serious concern (69 percent of respondents). In addition, the number of researchers working in the field has also grown, even though it is currently neglected by investments. The debate also touched several companies. DeepMind has built a model that tests other models to check whether they exhibit unsafe behavior. HuggingFace, on the other hand, has invested in federated learning, a system that protects data privacy. Other notable works have focused on agent behavior in reinforcement learning (here, here, and here). therefore, the explicability of AI models has become increasingly relevant and has also been an active field of research.


Other emerging trends Briefly, here are other interesting trends and considerations about last year: This year is five years of Transformers, and it is also the year in which Transformers have been shown to replace RNNs and LSTMs in most articles and applications. Transformers are now used in many different. However, the challenge between convolutional neural networks and vision transformers is still open.Diffusion models are shown to be interesting models not only for text-to-image generation but also for other applications.Multimodal models are the new scene: Google, META, and other companies are trying to build that can work in different domains. The question is if we will use a transformer for all the tasks: DeepMind with GATO believe so.Language models (LLM) are empowering robots to execute instructions. Google used PALM to show how LLM can produce detailed instructions for robots and increase the likelihood that these actions are successfully executed.OpenAI scaling law is outdated or "not always bigger is better." DeepMind Chichilla shows that data quality is perhaps more important than the number of parameters. Moreover, with increasing parameters, there are emerging properties that are not fully understood and raise concerns (here and here to deepen).The rest of the community is more active than ever: cloning or even improving models that are produced by DeepMind or OpenAI. An example is BLOOM which is an institutional effort.Other interesting lectures of the year: the three eras of computing in machine learning, Bootstrapped Meta-learning, A Commonsense Knowledge Enhanced Network, LaMDA: Language Models for Dialog Applications, A Path Towards Autonomous Machine Intelligence, Self-Supervision for Learning from the Bottom Up, Why do tree-based models still outperform deep learning on tabular data?


Conclusions In this article, I have tried to condense some of the most interesting trends that have emerged this year. Of course, for the sake of brevity, I have not cited other interesting articles. What do you think? Are any other works that deserve mention? Have you noticed any other trends? Let me know in the comments.


if you have found it interesting: You can look for my other articles, you can also subscribe to get notified when I publish articles, and you can also connect or reach me on LinkedIn. Thanks for your support! Here is the link to my GitHub repository, where I am planning to collect code and many resources related to machine learning, artificial intelligence, and more.


This AI newsletter is all you need #25

What happened this week in AI by Louis Exciting news today! We are partnering with Learn Prompting in order to help build and spread how to do prompting and become better prompt engineers, which we believe will become more and more popular, and people will even be hired for this role in the near future (do you think prompt engineering will be a real job? Join the discussion!). We plan on covering the A to Z of prompting, including great applied and comprehensive tutorials for all the large and *hot* models, as well as a fun competition coming up towards the end of the year. Learn more about this new course and stay tuned for the fun competition with prizes - including money - in our new #learn-prompting channel on Discord! We will use this new channel to share announcements and answer questions related to Learn Prompting. You can also reach out to @Trigaten and me at any time. This news also comes with a new job opportunity!We are looking for people willing to do some contract work for building learning resources with experience in one or both of the following: NLP (LLMs implementation & prompting).Image generation models (implemented stable diffusion or other image synthesis model and experience prompting (or fine-tuning) with them). This would be a contractor role with approximately 10 hours per month of work with different fun and game-changing (mostly open-source) projects for the "learning AI" community, just like Learn Prompting. Message me @Louis B on Discord or by email for more information!