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

7009 Articles
article-image-create-an-ai-powered-coding-project-generator
Luis Sobrecueva
22 Jun 2023
8 min read
Save for later

Create an AI-Powered Coding Project Generator.

Luis Sobrecueva
22 Jun 2023
8 min read
OverviewMaking a smart coding project generator can be a game-changer for developers. With the help of large language models (LLM), we can generate entire code projects from a user-provided prompt.In this article, we are developing a Python program that utilizes OpenAI's GPT-3.5 to generate code projects and slide presentations based on user-provided prompts. The program is designed as a command-line interface (CLI) tool, which makes it easy to use and integrate into various workflows. Image 1: Weather App Features Our project generator will have the following features:Generates entire code projects based on user-provided promptsGenerates entire slide presentations based on user-provided prompts (watch a demo here)Uses OpenAI's GPT-3.5 for code generationOutputs to a local project directoryExample Usage Our tool will be able to generate a code project from a user-provided prompt, for example, this line will create a snake game:maiker "a snake game using just html and js"; We can then open the generated project in our browser: open maiker-generated-project/index.htmlImage 2: Generated ProjectImplementation To ensure a comprehensive understanding of the project, let's break down the process of creating the AI-powered coding project generator step by step: 1. Load environment variables: We use the `dotenv` package to load environment variables from a `.env` file. This file should contain your OpenAI API key.from dotenv import load_dotenv load_dotenv()2. Set up OpenAI API client: We set up the OpenAI API client using the API key loaded from the environment variables.import openai openai.api_key = os.getenv("OPENAI_API_KEY")3. Define the `generate_project` function: This function is responsible for generating code projects or slide presentations based on the user-provided prompt. Let's break down the function in more detail.def generate_project(prompt: str, previous_response: str = "", type: str = "code") -> Dict[str, str]: The function takes three arguments:prompt: The user-provided prompt describing the project to be generated.previous_response: A string containing the previously generated files, if any. This is used to avoid generating the same files again if it does more than one loop.type: The type of project to generate, either "code" or "presentation". Inside the function, we first create the system and user prompts based on the input type (code or presentation). if type == "presentation":      # ... (presentation-related prompts) else:      # ... (code-related prompts) For code projects, we create a system prompt that describes the role of the API as a code generator and a user prompt that includes the project description and any previously generated files. For presentations, we create a system prompt that describes the role of the API as a reveal.js presentation generator and a user prompt that includes the presentation description. Next, we call the OpenAI API to generate the code or presentation using the created system and user prompts. completion = openai.ChatCompletion.create(      model="gpt-3.5-turbo",      messages=[    {           "role": "system",           "content": system_prompt,    },    {           "role": "user",           "content": user_prompt,    },      ],      temperature=0, ) We use the openai.ChatCompletion.create method to send a request to the GPT-3.5 model. The `messages` parameter contains an array of two messages: the system message and the user message. The `temperature` parameter is set to 0 to encourage deterministic output. Once we receive the response from the API, we extract the generated code from the response. generated_code = completion.choices[0].message.contentGenerating the files to disk: We then attempt to parse the generated code as a JSON object. If the parsing is successful, we return the parsed JSON object, which is a dictionary containing the generated files and their content. If the parsing fails, we raise an exception with an error message.try:      if generated_code:    generated_code = json.loads(generated_code) except json.JSONDecodeError as e:      raise click.ClickException(    f"Code generation failed. Please check your prompt and try again. Error: {str(e)}, generated_code: {generated_code}"      ) return generated_code This dictionary is then used by the `main` function to save the generated files to the specified output directory.```4. Define the `main` function: This function is the entry point of our CLI tool. It takes a project prompt, an output directory, and the type of project (code or presentation) as input. It then calls the `generate_project` function to generate the project and saves the generated files to the specified output directory.def main(prompt: str, output_dir: str, type: str):      # ... (rest of the code) Inside the main function, we ensure the output directory exists, generate the project, and save the generated files.# ... (inside main function) os.makedirs(output_dir, exist_ok=True) for _loop in range(max_loops):      generated_code = generate_project(prompt, ",".join(generated_files), type)      for filename, contents in generated_code.items():    # ... (rest of the code) 5. **Create a Click command**: We use the `click` package to create a command-line interface for our tool. We define the command, its arguments, and options using the `click.command`, `click.argument`, and `click.option` decorators.import click @click.command() @click.argument("prompt") @click.option(      "--output-dir",      "-o",      default="./maiker-generated-project",      help="The directory where the generated code files will be saved.", ) @click.option('-t', '--type', required=False, type=click.Choice(['code', 'presentation']), default='code') def main(prompt: str, output_dir: str, type: str):      # ... (rest of the code) 6. Run the CLI tool: Finally, we run the CLI tool by calling the `main` function when the script is executed.if __name__ == "__main__":      main() In this article, we have used the`... (rest of the code)` as a placeholder to keep the explanations concise and focused on specific parts of the code. The complete code for the AI-powered coding project generator can be found in the GitHub repository at the following link: https://github.com/lusob/maiker-cliBy visiting the repository, you can access the full source code, which includes all the necessary components and functions to create the CLI tool. You can clone or download the repository to your local machine, install the required dependencies, and start using the tool to generate code projects and slide presentations based on user-provided prompts.   ConclusionWith the current AI-powered coding project generator, you can quickly generate code projects and slide presentations based on user-provided prompts. By leveraging the power of OpenAI's GPT-3.5, you can save time and effort in creating projects and focus on other important aspects of your work. However, it is important to note that the complexity of the generated projects is currently limited due to the model's token limitations. GPT-3.5 has a maximum token limit, which restricts the amount of information it can process and generate in a single API call. As a result, the generated projects might not be as comprehensive or sophisticated as desired for more complex applications. The good news is that with the continuous advancements in AI research and the development of new models with larger context windows (e.g., models with more than 100k context tokens), we can expect significant improvements in the capabilities of AI-powered code generators. These advancements will enable the generation of more complex and sophisticated projects, opening up new possibilities for developers and businesses alike.Author BioLuis Sobrecueva is a software engineer with many years of experience working with a wide range of different technologies in various operating systems, databases, and frameworks. He began his professional career developing software as a research fellow in the engineering projects area at the University of Oviedo. He continued in a private company developing low-level (C / C ++) database engines and visual development environments to later jump into the world of web development where he met Python and discovered his passion for Machine Learning, applying it to various large-scale projects, such as creating and deploying a recommender for a job board with several million users. It was also at that time when he began to contribute to open source deep learning projects and to participate in machine learning competitions and when he took several ML courses obtaining various certifications highlighting a MicroMasters Program in Statistics and Data Science at MIT and a Udacity Deep Learning nano degree. He currently works as a Data Engineer at a ride-hailing company called Cabify, but continues to develop his career as an ML engineer by consulting and contributing to open-source projects such as OpenAI and Autokeras.Author of the book: Automated Machine Learning with AutoKeras
Read more
  • 0
  • 0
  • 10175

article-image-creating-stunning-images-from-text-prompt-using-craiyon
Julian Melanson
21 Jun 2023
6 min read
Save for later

Creating Stunning Images from Text Prompt using Craiyon

Julian Melanson
21 Jun 2023
6 min read
In an era marked by rapid technological progress, Artificial Intelligence continues to permeate various fields, fostering innovation and transforming paradigms. One area that has notably experienced a surge of AI integration is the world of digital art. A range of AI-powered websites and services have emerged, enabling users to transform text descriptions into images, artwork, and drawings. Among these innovative platforms, Craiyon, formerly known as DALL-E mini, stands out as a compelling tool that transforms the artistic process through its unique text-to-image generation capabilities.Developed by Boris Dayma, Craiyon was born out of an aspiration to create a free, accessible AI tool that could convert textual descriptions into corresponding visuals. The concept of Craiyon was not conceived in isolation; rather, it emerged as a collaborative effort, with contributions from the expansive open-source community playing a significant role in the evolution of its capabilities.The AI behind Craiyon leverages the computing power of Google's PU Research Cloud (TRC). It undergoes rigorous training that imbues it with the ability to generate novel images based on user-provided textual inputs. In addition, Craiyon houses an expansive library of existing images that can further assist users in refining their queries.While the abilities of such an image generation model are undeniably impressive, certain limitations do exist. For instance, the model sometimes generates unexpected or stereotypical imagery, reflecting inherent biases in the datasets it was trained on. Notwithstanding these constraints, Craiyon's innovative technology holds substantial promise for the future of digital art.Image 1: Craiyon home page Getting Started with CraiyonIf you wish to test the waters with Craiyon's AI, the following steps can guide you through the process:Accessing Craiyon: First, navigate to the Craiyon website: https://www.craiyon.com. While you have the option to create a free account, you might want to familiarize yourself with the platform before doing so.Describing Your Image: Upon landing on the site, you will find a space where you can type a description of the image you wish to generate. To refine your request, consider specifying elements you want to be excluded from the image. Additionally, decide whether you want your image to resemble a piece of art, a drawing, or a photo.Initiating the Generation Process: Once you are satisfied with your description, click the "Draw" button. The generation process might take a moment, but it will eventually yield multiple images that match your description.Selecting and Improving Your Image: Choose an image that catches your eye. For a better viewing experience, you can upscale the resolution and quality of the image. If you wish to save the image, use the "Screenshot" button.Revising Your Prompt: If you are not satisfied with the generated images, consider revising your prompt. Craiyon might suggest alternative prompts to help you obtain improved results.Viewing and Saving Your Images: If you have created a free account, you can save the images you like by clicking the heart icon. You can subsequently access these saved images through the "My Collection" option under the "Account" button.Use CasesCreating art and illustrations: Craiyon can be used to create realistic and creative illustrations, paintings, and other artworks. This can be a great way for artists to explore new ideas and techniques, or to create digital artworks that would be difficult or time-consuming to create by hand.Generating marketing materials: Craiyon can be used to create eye-catching images and graphics for marketing campaigns. This could include social media posts, website banners, or product illustrations.Designing products: Craiyon can be used to generate designs for products, such as clothing, furniture, or toys. This can be a great way to get feedback on new product ideas, or to create prototypes of products before they are manufactured.Educating and communicating: Craiyon can be used to create educational and informative images. This could include diagrams, charts, or infographics. Craiyon can also be used to create images that communicate complex ideas in a more accessible way.Personalizing experiences: Craiyon can be used to personalize experiences, such as creating custom wallpapers, avatars, or greeting cards. This can be a great way to add a touch of individuality to your devices or communicationCraiyon is still under development, but it has the potential to be a powerful tool for a variety of uses. As the technology continues to improve, we can expect to see even more creative and innovative use cases for Craiyon in the future.Here are some additional use cases for Craiyon:Generating memes: Craiyon can be used to generate memes, which are humorous images that are often shared online. This can be a fun way to express yourself or to join in on a current meme trend.Creating custom content: Craiyon can be used to create custom content for your website, blog, or social media channels. This could include images, graphics, or even videos.Experimenting with creative ideas: Craiyon can be used to experiment with creative ideas. If you have an idea for an image or illustration, you can use Craiyon to see how it would look. This can be a great way to get feedback on your ideas or to explore new ways of thinking about art. SummaryThe emergence of AI tools like Craiyon marks a pivotal moment in the intersection of art and technology. While it's crucial to acknowledge the limitations of such tools, their potential to democratize artistic expression and generate creative inspiration is indeed remarkable. As Craiyon and similar platforms continue to evolve, we can look forward to a future where the barriers between language and visual expression are further blurred, opening up new avenues for creativity and innovation.Author BioJulian Melanson is one of the founders of Leap Year Learning. Leap Year Learning is a cutting-edge online school that specializes in teaching creative disciplines and integrating AI tools. We believe that creativity and AI are the keys to a successful future and our courses help equip students with the skills they need to succeed in a continuously evolving world. Our seasoned instructors bring real-world experience to the virtual classroom and our interactive lessons help students reinforce their learning with hands-on activities.No matter your background, from beginners to experts, hobbyists to professionals, Leap Year Learning is here to bring in the future of creativity, productivity, and learning!
Read more
  • 0
  • 0
  • 7569

article-image-chatgpt-on-your-hardware-gpt4all
Valentina Alto
20 Jun 2023
7 min read
Save for later

ChatGPT on Your Hardware: GPT4All

Valentina Alto
20 Jun 2023
7 min read
We all got familiar with conversational UI powered by Large Language Models: ChatGPT has been the first and most powerful example of how LLMs can boost our productivity daily. To be so accurate, LLMs are, by design, “large”, meaning that they are made of billions of parameters, hence they are hosted in powerful infrastructure, typically in the public cloud (namely, OpenAI’s models including ChatGPT are hosted in Microsoft Azure). As such, those models are accessible with an internet connection.But what if you could run those powerful models on your local PC, having a ChatGPT-like experience?Introducing GPT4AllGTP4All is an ecosystem to train and deploy powerful and customized large language models that run locally on consumer-grade CPUs – no GPU is required. A GPT4All model is a 3GB - 8GB file that you can download and plug into the GPT4All open-source ecosystem software, which is optimized to host models of size between 7 and 13 billion of parameters.To start working with the GPT4All Desktop app, you can download it from the official website hereàhttps://gpt4all.io/index.html.At the moment, there are 3 main LLMs families you can use within GPT4All:LlaMa - a collection of foundation language models ranging from 7B to 65B parameters. They were developed by Meta AI, Facebook’s parent company, and trained on trillions of tokens from 20 languages that use Latin or Cyrillic scripts. LLaMA can generate human-like conversations and outperforms GPT-3 on most benchmarks despite being 10x smaller. LLaMA is designed to run on less computing power and to be versatile and adaptable to many different use cases. However, LLaMA also faces challenges such as bias, toxicity, and hallucinations in large language models. Meta AI has released all the LLaMA models to the research community for open science.GPT-J- An open-source artificial intelligence language model developed by EleutherAI. It is a GPT-2-like causal language model trained on the Pile dataset, which is an open-source 825-gigabyte language modeling data set that is split into 22 smaller datasets. GPT-J comes in sizes ranging from 7B to 65B parameters and can generate creative text, solve mathematical theorems, predict protein structures, answer reading comprehension questions, and more. GPT-J performs very similarly to similarly-sized OpenAI’s GPT-3 versions on various zero-shot down-streaming tasks and can even outperform it on code generation tasks. GPT-J is designed to run on less computing power and to be versatile and adaptable to many different use cases. MPT - series of open source, commercially usable large language models developed by MosaicML. MPT-7B is a decoder-style transformer pretrained from scratch on 1T tokens of English text and code. MPT-7B is part of the family of MosaicPretrainedTransformer (MPT) models, which use a modified transformer architecture optimized for efficient training and inference. These architectural changes include performance-optimized layer implementations and the elimination of context length limits by replacing positional embeddings with Attention to Linear Biases (ALiBi). MPT-7B can handle highly long inputs thanks to ALiBi (up to 84k tokens vs. 2k-4k for other open-source models). MPT-7B also has several finetuned variants for different tasks, such as story writing, instruction following, and dialogue generation.You can download various versions of these models’ families directly within the GPT4All app:Image 1: Download section in GPT 4Image 2: Download PathIn my case, I downloaded a GPT-J with 6 billion parameters. You can select the model you want to use in the upper menu list in your application. Once selected the model, you can use it via the well-known ChatGPT UI, with the difference that it is now running on your local PC:Image 3: GPT4All responseAs you can see, the user experience is almost identical to the well-known ChatGPT, with the difference that we are running it locally and with different underlying LLMs.Chatting with your own dataAnother great thing about GPT4All is its integration with your local docs via plugins (currently in beta). To do so, you can go to settings (in the upper bar menu) and select LocalDocs Plugin. Here, you can browse the folder path you want to connect to and then “attach” it to the model knowledge base via the database icon in the upper right. In this example, I used the SQL licensing documentation in PDF format. Image 4: SQL documentationIn this case, the model is going to answer taking into consideration also (but not only) the attached documentation, which will be quoted in case the answer is based on it:Image 5: Automatically generated computer descriptionImage 6: Computer description with medium confidenceThe technique used to store and index the knowledge provided by our document is called Retrieval Augmented Generation (RAG), a type of language generation model that combines two types of memories:Pre-trained parametric memoryàthe one stored in the model’s parameters, derived from the training dataset;Non-parametric memoryàthe one derived from the attached knowledge provided, which is in the form of a vector database where the documents’ embeddings are stored.Finally, the LocalDocs plugin supports a variety of data formats including txt, docx, pdf, html and xlsx. For a comprehensive list of the supported formats, you can visit the page https://docs.gpt4all.io/gpt4all_chat.html#localdocs-capabilities.Using GPT4All with APIIn addition to the Desktop app mode, GPT4All comes with two additional ways of consumption, which are: Server mode- once enabled the server mode in the settings of the Desktop app, you can start using the API key of GPT4All at localhost 4891, embedding in your app the following code:import openai openai.api_base = "http://localhost:4891/v1" openai.api_key = "not needed for a local LLM" prompt = "What is AI?" # model = "gpt-3.5-turbo" #model = "mpt-7b-chat" model = "gpt4all-j-v1.3-groovy" # Make the API request response = openai.Completion.create(    model=model,    prompt=prompt,    max_tokens=50,    temperature=0.28,    top_p=0.95,    n=1,    echo=True,    stream=False )Python API-It comes with a lightweight SDK of GPT4All which you can easily install via pip install gpt4all. Here you can find a sample notebook on how to use this SDK: https://colab.research.google.com/drive/1QRFHV5lj1Kb7_tGZZGZ-E6BfX6izpeMI?usp=sharingConclusionsRunning LLMs on local hardware opens a new spectrum of possibilities, especially when we think about disconnected scenarios. Plus, having the possibility to chat with local documents with an easy-to-use interface adds the custom non-parametric memory to the model in such a way that we can use it already as a sort of copilot.Henceforth, even though it is in an initial phase, this ecosystem is paving the way for new interesting scenarios.Referenceshttps://docs.gpt4all.io/GPT4All Chat UI - GPT4All Documentation[2005.11401] Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (arxiv.org)Author BioValentina Alto graduated in 2021 in Data Science. Since 2020 she has been working in Microsoft as Azure Solution Specialist and, since 2022, she focused on Data&AI workloads within the Manufacturing and Pharmaceutical industry. She has been working on customers’ projects closely with system integrators to deploy cloud architecture with a focus on datalake house and DWH, data integration and engineering, IoT and real-time analytics, Azure Machine Learning, Azure cognitive services (including Azure OpenAI Service), and PowerBI for dashboarding. She holds a BSc in Finance and an MSc degree in Data Science from Bocconi University, Milan, Italy. Since her academic journey, she has been writing Tech articles about Statistics, Machine Learning, Deep Learning, and AI in various publications. She has also written a book about the fundamentals of Machine Learning with Python. LinkedIn  Medium
Read more
  • 0
  • 0
  • 30009

article-image-the-transformative-potential-of-google-bard-in-healthcare
Julian Melanson
20 Jun 2023
6 min read
Save for later

The Transformative Potential of Google Bard in Healthcare

Julian Melanson
20 Jun 2023
6 min read
The integration of artificial intelligence and cloud computing in healthcare has revolutionized various aspects of patient care. Telemedicine, in particular, has emerged as a valuable resource for remote care, and the Google Bard platform is at the forefront of making telemedicine more accessible and efficient. With its comprehensive suite of services, secure connections, and advanced AI capabilities, Google Bard is transforming healthcare delivery. This article explores the applications of AI in healthcare, the benefits of Google Bard in expanding telemedicine, its potential to reduce costs and improve access to care, and its impact on clinical decision-making and healthcare quality.AI in HealthcareArtificial intelligence has made significant strides in revolutionizing healthcare. It has proven to be instrumental in disease diagnosis, treatment protocol development, new drug discovery, personalized medicine, and healthcare analytics. AI algorithms can analyze vast amounts of medical data, detect patterns, and identify potential risks or effective treatments that may go unnoticed by human experts. This technology holds immense promise for improving patient outcomes and enhancing healthcare delivery.Understanding Google BardGoogle's AI chat service, Google Bard, now employs its latest large language model, PaLM 2, launched at Google I/O 2023. As a progression from the original PaLM released in April 2022, it elevates Bard's efficacy and performance. Initially, Bard operated on a scaled-down version of LaMDA for broader user accessibility with minimal computational needs. Leveraging Google's extensive database, Bard aims to provide precise text responses to a variety of inquiries, poised to become a dominant player in the AI chatbot arena. Despite its later launch than ChatGPT, Google's broader data access and Bard's lower computational requirements potentially position it as a more efficient and user-friendly contender.Expanding Telemedicine with Google Bard:Google Bard has the ability to play a pivotal role in expanding telemedicine and remote care. Its secure connections enable doctors to diagnose and treat patients without being physically present. Additionally, it provides easy access to patient records, and medical history, and facilitates seamless communication through appointment scheduling, messaging, and sharing medical images. These features empower doctors to provide better-informed care and enhance patient engagement.The Impact on Healthcare Efficiency and Patient Outcomes:Google Bard's integration of AI and machine learning capabilities elevate healthcare efficiency and patient outcomes. The platform's AI system quickly and accurately analyzes patient records, identifies patterns and trends, and aids medical professionals in developing effective treatment plans.For example, here is a prompt based on a sample HPI text:Image 1: Diagnosis from this clinical HPIHere is Google Bard’s response:Image 2: main problems of the Clinical HPIGoogle Bard effectively identified key diagnoses and the primary issue from the HPI sample text. Beyond simply listing diagnoses, it provided comprehensive details on the patient's primary concerns, aiding healthcare professionals in grasping the depth and complexity of the condition.When prompted further, Google Bard also suggested a treatment strategy:Image 3: Suggesting treatment planThis can ultimately assist medical practitioners in developing fitting interventions.Google Bard also serves as a safety net by detecting potential medical errors and alerting healthcare providers. Furthermore, Google Bard's user-friendly interface expedites access to patient records, enabling faster and more effective care delivery. The platform also grants medical professionals access to the latest medical research and clinical trials, ensuring they stay updated with advancements in healthcare. Ultimately, Google Bard's secure platform and powerful analytics tools contribute to better patient outcomes and informed decision-making.Reducing Healthcare Costs and Improving Access to CareOne of the key advantages of Google Bard lies in its potential to reduce healthcare costs and improve access to care. The platform's AI-based technology identifies cost-efficient treatment options, optimizes resource allocation, and enhances care coordination. By reducing wait times and unnecessary visits, Google Bard minimizes missed appointments, repeat visits, and missed diagnoses, resulting in lower costs and improved access to care. Additionally, the platform's comprehensive view of patient health, derived from aggregated data, enables more informed treatment decisions and fewer misdiagnoses. This integrated approach ensures better care outcomes while controlling costs.Supporting Clinical Decision-Making and Healthcare QualityGoogle Bard's launch signifies a milestone in the use of AI to improve healthcare. The platform provides healthcare providers with a suite of computational tools, empowering them to make more informed decisions and enhance the quality of care. Its ability to quickly analyze vast amounts of patient data enables the identification of risk factors, potential diagnoses, and treatment recommendations. Moreover, Google Bard supports collaboration and comparisons of treatment options among healthcare teams. By leveraging this technology, healthcare professionals can provide personalized care plans, improving outcomes and reducing medical errors. The platform's data-driven insights and analytics also support research and development efforts, allowing researchers to identify trends and patterns and develop innovative treatments.Google Bard, with its AI-driven capabilities and secure cloud-based platform, holds immense potential to revolutionize healthcare delivery. By enhancing efficiency, accessibility, and patient outcomes, it is poised to make a significant impact on the healthcare industry. The integration of AI, machine learning, and cloud computing in telemedicine enables more accurate diagnoses, faster treatments, and improved care coordination. Moreover, Google Bard's ability to reduce healthcare costs and improve access to care reinforces its value as a transformative tool. As the platform continues to evolve, it promises to shape the future of healthcare, empowering medical professionals and benefiting patients worldwide.SummaryGoogle Bard is revolutionizing healthcare with its practical applications. For instance, it enhances healthcare efficiency and improves patient outcomes through streamlined data management and analysis. Reducing administrative burdens and optimizing workflows, it reduces healthcare costs and ensures better access to care. Furthermore, it supports clinical decision-making by providing real-time insights, aiding healthcare professionals in delivering higher-quality care. Overall, Google Bard's transformative technology is reshaping healthcare, benefiting patients, providers, and the industry as a whole.Author BioJulian Melanson is one of the founders of Leap Year Learning. Leap Year Learning is a cutting-edge online school that specializes in teaching creative disciplines and integrating AI tools. We believe that creativity and AI are the keys to a successful future and our courses help equip students with the skills they need to succeed in a continuously evolving world. Our seasoned instructors bring real-world experience to the virtual classroom and our interactive lessons help students reinforce their learning with hands-on activities.No matter your background, from beginners to experts, hobbyists to professionals, Leap Year Learning is here to bring in the future of creativity, productivity, and learning!
Read more
  • 0
  • 0
  • 22353

article-image-use-bard-to-implement-data-science-projects
Darren Broemmer
20 Jun 2023
7 min read
Save for later

Use Bard to Implement Data Science Projects

Darren Broemmer
20 Jun 2023
7 min read
Bard is a large language model (LLM) from Google AI, trained on a massive dataset of text and code. Bard can be used to generate Python code for data science projects. This can be extremely helpful for data scientists who want to save time on coding or are unfamiliar with Python. It also empowers those of us who are not full-time data scientists but have an interest in leveraging machine learning (ML) technologies.The first step is to define the problem you are trying to solve. In this article, we will use Bard to create a binary text classifier. It will take a news story as input and classify it as either fake or real. Given a problem to solve, you can brainstorm solutions. If you are familiar with machine learning technologies, you are able to do this yourself. Alternatively, you can ask Bard for help in finding an appropriate algorithm that meets your requirements. The classification of text documents often uses term frequency techniques. We don’t need to know more than that at this point, as we can have Bard help us with the details of the implementation.The overall design of your project could also involve feature engineering and visualization methods. As in most software engineering efforts, you will likely need to iterate on the design and implementation. However, Bard can help you do this much faster.Reading and parsing the training dataAll of the code from this article can be found on GitHub. Bard will guide you, but to run this code, you will need to install a few packages using the following commands.python -m pip install pandas python -m pip install scikit-learn To train our model, we can use the news.csv data set within this project found here, originally sourced from a Data Flair training exercise. It contains the title and text of almost 8,000 news articles labeled as REAL or FAKE.To get started , Bard can help us write code to parse and read this data file. Pandas is a popular open-source data analysis and manipulation tool for Python. We can prompt Bard to use this library to read the file.Image 1: Using Pandas to read the fileRunning the code shows the format of the csv file and the first few data rows, just as Bard described. It has an unnamed article id in the first column followed by the title, text, and classification label.broemmerd$ python test.py   Unnamed: 0                                              title                                              text label 0        8476                       You Can Smell Hillary’s Fear  Daniel Greenfield, a Shillman Journalism Fello...  FAKE 1       10294  Watch The Exact Moment Paul Ryan Committed Pol...  Google Pinterest Digg Linkedin Reddit Stumbleu...  FAKE 2        3608        Kerry to go to Paris in gesture of sympathy  U.S. Secretary of State John F. Kerry said Mon...  REAL 3       10142  Bernie supporters on Twitter erupt in anger ag...  — Kaydee King (@KaydeeKing) November 9, 2016 T...  FAKE 4         875   The Battle of New York: Why This Primary Matters  It's primary day in New York and front-runners...  REALTraining our machine learning modelNow that we can read and understand our training data, we can prompt Bard to write code to train an ML model using this data. Our prompt is detailed regarding the input columns in the file used for training. However, it specifies a general ML technique we believe is applicable to the solution.The text column in the news.csv contains a string with the content from a new article. The label column contains a classifier label of either REAL or FAKE. Modify the Python code to train a machine-learning model using term frequency based on these two columns of data. Image 2: Bard for training ML modelsWe can now train our model. The output of this code is shown below: broemmerd$ python test.py Accuracy: 0.9521704814522494We have our model working. Now we just need a function that will apply it to a given input text. We use the following prompt. Modify this code to include a function called classify_news that takes a text string as input and returns the classifier, either REAL or FAKE.Bard generates the following code for this function. Note that it also refactored the previous code to include the use of the TfidfVectorizor in order to support this function.Image 3: Including classify_news function Testing the classifierTo test the classifier with a fake story, we will use an Onion article entitled “Chill Juror Good With Whatever Group Wants To Do For Verdict.” The Onion is a satirical news website known for its humorous and fictional content. Articles in The Onion are intentionally crafted to appear as genuine news stories, but they contain fictional, absurd elements for comedic purposes.Our real news story is a USA Today article entitled “House blocks push to Censure Adam Schiff for alleging collusion between Donald Trump and Russia.”Here is the code that reads the two articles and uses our new function to classify each one. The results are shown below.with open("article_the_onion.txt", "r") as f:   article_text = f.read()   print("The Onion article: " + classify_news(article_text)) with open("article_usa_today.txt", "r") as f:   article_text = f.read()   print("USA Today article: " + classify_news(article_text)) broemmerd$ python news.py Accuracy: 0.9521704814522494 The Onion article: FAKE USA Today article: REALOur classifier worked well on these two test cases.Bard can be a helpful tool for data scientists who want to save time on coding or who are not familiar with Python. By following a process similar to the one outlined above, you can use Bard to generate Python code for data science projects.Additional guidance on coding with BardWhen using Bard to generate Python code for data science projects, be sure to use clear and concise prompts. Provide the necessary detail regarding the inputs and the desired outputs. Where possible, use specific examples. This can help Bard generate more accurate code. Be patient and expect to go through a few iterations until you get the desired result. Test the generated code at each step in the process. It will be difficult to determine the cause of errors if you wait until the end to start testing.Once you get familiar with the process, you can use Bard to generate Python code that can help you solve data science problems more quickly and easily.Author BioDarren Broemmer is an author and software engineer with extensive experience in Big Tech and Fortune 500. He writes on topics at the intersection of technology, science, and innovation.LinkedIn  
Read more
  • 0
  • 0
  • 4957

article-image-openchatkit-could-be-your-open-source-alternative-to-chatgpt
Julian Melanson
20 Jun 2023
5 min read
Save for later

OpenChatKit Could be Your Open-Source Alternative to ChatGPT

Julian Melanson
20 Jun 2023
5 min read
It’s no surprise that LLMs like ChatGPT and Bard possess impressive capabilities. However, it’s important to note that they are proprietary software, subject to restrictions in terms of access and usage due to licensing constraints. Consequently, this limitation has generated significant interest within the open-source community, leading to the development of alternative solutions that emphasize freedom, transparency, and community-driven collaboration.In recent months, the open-source community Together has introduced OpenChatKit, an alternative to ChatGPT, aimed at providing developers with a versatile chatbot solution. OpenChatKit utilizes the GPT-NeoX language model developed by EleutherAI, which consists of an impressive 20 billion parameters. Additionally, the model has been fine-tuned specifically for chat use with 43 million instructions. OpenChatKit's performance surpasses the base model in the industry-standard HELM benchmark, making it a promising tool for various applications.OpenChatKit Components and CapabilitiesOpenChatKit is accompanied by a comprehensive toolkit available on GitHub under the Apache 2.0 license. The toolkit includes several key components designed to enhance customization and performance:Customization recipes: These recipes allow developers to fine-tune the language model for their specific tasks, resulting in higher accuracy and improved performance.Extensible retrieval system: OpenChatKit enables developers to augment bot responses by integrating information from external sources such as document repositories, APIs, or live-updating data during inference time. This capability enhances the bot's ability to provide contextually relevant and accurate responses.Moderation model: The toolkit incorporates a moderation model derived from GPT-JT-6B, fine-tuned to filter and determine which questions the bot should respond to. This feature helps ensure appropriate and safe interactions.Feedback mechanisms: OpenChatKit provides built-in tools for users to provide feedback on the chatbot's responses and contribute new datasets. This iterative feedback loop allows for continuous improvement and refinement of the chatbot's performance.OpenChatKit's Strengths and LimitationsDevelopers highlight OpenChatKit's strengths in specific tasks such as summarization, contextual question answering, information extraction, and text classification. It excels in these areas, offering accurate and relevant responses.However, OpenChatKit's performance is comparatively weaker in tasks that require handling questions without context, coding, and creative writing—areas where ChatGPT has gained popularity. OpenChatKit may occasionally generate erroneous or misleading responses (hallucinations), a challenge that is also encountered in ChatGPT. Furthermore, OpenChatKit sometimes struggles with smoothly transitioning between conversation topics and may occasionally repeat answers.Fine-Tuning and Specialized Use CasesOpenChatKit's performance can be significantly improved by fine-tuning it for specific use cases. Together, the developers are actively working on their own chatbots designed for learning, financial advice, and support requests. By tailoring OpenChatKit to these specific domains, they aim to enhance its capabilities and deliver more accurate and contextually appropriate responses.Comparing OpenChatKit with ChatGPTIn a brief evaluation, OpenChatKit did not demonstrate the same level of eloquence as ChatGPT. This discrepancy can partly be attributed to OpenChatKit's response limit of 256 tokens, which is less than the approximately 500 tokens in ChatGPT. As a result, OpenChatKit generates shorter responses. However, OpenChatKit outperforms ChatGPT in terms of response speed, generating replies at a faster rate. The language transition between different languages does not appear to pose any challenges for OpenChatKit, and it supports formatting options like lists and tables.The Role of User Feedback in ImprovementTogether recognizes the importance of user feedback in enhancing OpenChatKit's performance and plan to leverage it for further improvement. Actively involving users in providing feedback and suggestions ensures that OpenChatKit evolves to meet user expectations and becomes increasingly useful across a wide range of applications.The Future of Decentralized Training for AI ModelsThe decentralized training approach employed in OpenChatKit, as previously seen with GPT-JT, represents a potential future for large-scale open-source projects. By distributing the computational load required for training across numerous machines instead of relying solely on a central data center, developers can leverage the combined power of multiple systems. This decentralized approach not only accelerates training but also promotes collaboration and accessibility within the open-source community.Anticipating Future DevelopmentsOpenChatKit is the pioneer among open-source alternatives to ChatGPT. However, it is likely that other similar projects will emerge. Notably, Meta's LLaMa models, which were leaked, boast parameters three times greater than GPT-NeoX-20B. With these advancements, it is only a matter of time before chatbots based on these models enter the scene.Getting Started with OpenChatKitGetting started with the program is simple:Head to https://openchatkit.net/#demo in your browserRead through the guidelines and agree to the Terms & ConditionsType your prompt into the chatboxNow you can test-drive the program and see how you like it compared to other LLMS. SummaryIn summation, OpenChatKit presents an exciting alternative to ChatGPT. Leveraging the powerful GPT-NeoX language model and extensive fine-tuning for chat-based interactions, OpenChatKit demonstrates promising capabilities in tasks such as summarization, contextual question answering, information extraction, and text classification. While some limitations exist, such as occasional hallucinations and difficulty transitioning between topics, fine-tuning OpenChatKit for specific use cases significantly improves its performance. With the provided toolkit, developers can customize the chatbot to suit their needs, and user feedback plays a crucial role in the continuous refinement of OpenChatKit. As decentralized training becomes an increasingly prominent approach in open-source projects, OpenChatKit sets the stage for further innovations in the field, while also foreshadowing the emergence of more advanced chatbot models in the future.Author BioJulian Melanson is one of the founders of Leap Year Learning. Leap Year Learning is a cutting-edge online school that specializes in teaching creative disciplines and integrating AI tools. We believe that creativity and AI are the keys to a successful future and our courses help equip students with the skills they need to succeed in a continuously evolving world. Our seasoned instructors bring real-world experience to the virtual classroom and our interactive lessons help students reinforce their learning with hands-on activities.No matter your background, from beginners to experts, hobbyists to professionals, Leap Year Learning is here to bring in the future of creativity, productivity, and learning! 
Read more
  • 0
  • 0
  • 8073
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 €18.99/month. Cancel anytime
article-image-build-a-project-that-automates-your-code-review
Luis Sobrecueva
19 Jun 2023
15 min read
Save for later

Build a Project that Automates your Code Review

Luis Sobrecueva
19 Jun 2023
15 min read
Developers understand the importance of a solid code review process but find it time-consuming. Language Models (LLMs) offer a solution by providing insights into code flows and enforcing best practices. A project aims to automate code reviews using LLMs, revolutionizing developers' approach. An intelligent assistant will swiftly analyze code differences, generating feedback in seconds. Imagine having an AI-powered reviewer guiding you to write cleaner, more efficient code. The focus is to streamline the code review workflow, empowering developers to produce high-quality code while saving time. The system will offer comprehensive insights through automated analysis, highlighting areas that need attention and suggesting improvements. By embracing LLMs' potential and automation, this project aims to make code reviews seamless and rewarding. Join the journey to explore LLMs' impact on code review and enhance the development experience.Project OverviewIn this article, we are developing a Python program that will harness the power of OpenAI's ChatGPT for code review. This program will read diff changes from the standard input and generate comprehensive code review comments. The generated comments will be compiled into an HTML file, which will include AI-generated feedback for each diff file section, presented alongside the diff sections themselves as code blocks with syntax highlighting. To simplify the review process, the program will automatically open the HTML file in the user's default web browser.Image 1: Project PageBuild your ProjectLet's walk through the steps to build this code review program from scratch. By following these steps, you'll be able to create your own implementation tailored to your specific needs. Let's get started:1. Set Up Your Development Environment Ensure you have Python installed on your machine. You can download and install the latest version of Python from the official Python website.2. Install Required Libraries To interact with OpenAI's ChatGPT and handle diff changes, you'll need to install the necessary Python libraries. Use pip, the package installer for Python, to install the required dependencies. You can install packages by running the following command in your terminal:pip install openai numpy3. To implement the next steps, create a new Python file named `chatgpt_code_reviewer.py`.4. Import the necessary modules:import argparse import os import random import string import sys import webbrowser import openai from tqdm import tqdm5. Set up the OpenAI API key (you'll need to get a key at https://openai.com if you don't have one yet):openai.api_key = os.environ["OPENAI_KEY"]6. Define a function to format code snippets within the code review comments, ensuring they are easily distinguishable and readable within the generated HTML report.def add_code_tags(text):    # Find all the occurrences of text surrounded by backticks    import re    matches = re.finditer(r"`(.+?)`", text)    # Create a list to store the updated text chunks    updated_chunks = []    last_end = 0    for match in matches:     # Add the text before the current match     updated_chunks.append(text[last_end : match.start()])     # Add the matched text surrounded by <code> tags     updated_chunks.append("<b>`{}`</b>".format(match.group(1)))     # Update the last_end variable to the end of the current match     last_end = match.end()    # Add the remaining text after the last match    updated_chunks.append(text[last_end:])    # Join the updated chunks and return the resulting HTML string    return "".join(updated_chunks) 7. Define a function to generate a comment using ChatGPT:def generate_comment(diff, chatbot_context):    # Use the OpenAI ChatGPT to generate a comment on the file changes    chatbot_context.append(     {           "role": "user",           "content": f"Make a code review of the changes made in this diff: {diff}",     }    )    # Retry up to three times    retries = 3    for attempt in range(retries):     try:           response = openai.ChatCompletion.create(                 model="gpt-3.5-turbo",                 messages=chatbot_context,                 n=1,                 stop=None,                 temperature=0.3,           )     except Exception as e:           if attempt == retries - 1:                 print(f"attempt: {attempt}, retries: {retries}")                 raise e  # Raise the error if reached maximum retries           else:                 print("OpenAI error occurred. Retrying...")                 continue    comment = response.choices[0].message.content    # Update the chatbot context with the latest response    chatbot_context = [     {           "role": "user",                 "content": f"Make a code review of the changes made in this diff: {diff}",     },     {           "role": "assistant",           "content": comment,     }    ]    return comment, chatbot_context  The `generate_comment` function defined above uses the OpenAI ChatGPT to generate a code review comment based on the provided `diff` and the existing `chatbot_context`. It appends the user's request to review the changes in the `chatbot_context`. The function retries the API call up to three times to handle any potential errors. It makes use of the `openai.ChatCompletion.create()` method and provides the appropriate model, messages, and other parameters to generate a response. The generated comment is extracted from the response, and the chatbot context is updated to include the latest user request and assistant response. Finally, the function returns the comment and the updated chatbot context.This function will be a crucial part of the code review program, as it uses ChatGPT to generate insightful comments on the provided code diffs.8. Define a function to create the HTML output:def create_html_output(title, description, changes, prompt): random_string = "".join(random.choices(string.ascii_letters, k=5))    output_file_name = random_string + "-output.html"    title_text = f"\nTitle: {title}" if title else ""    description_text = f"\nDescription: {description}" if description else ""    chatbot_context = [     {           "role": "user",           "content": f"{prompt}{title_text}{description_text}",     }    ]    # Generate the HTML output    html_output = "<html>\n<head>\n<style>\n"    html_output += "body {\n    font-family: Roboto, Ubuntu, Cantarell, Helvetica Neue, sans-serif;\n    margin: 0;\n    padding: 0;\n}\n"    html_output += "pre {\n    white-space: pre-wrap;\n    background-color: #f6f8fa;\n    border-radius: 3px;\n  font-size: 85%;\n    line-height: 1.45;\n    overflow: auto;\n    padding: 16px;\n}\n"    html_output += "</style>\n"    html_output += '<link rel="stylesheet"\n href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css">\n <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>\n'    html_output += "<script>hljs.highlightAll();</script>\n"    html_output += "</head>\n<body>\n"    html_output += "<div style='background-color: #333; color: #fff; padding: 20px;'>"    html_output += "<h1 style='margin: 0;'>AI code review</h1>"    html_output += f"<h3>Diff to review: {title}</h3>" if title else ""    html_output += "</div>"    # Generate comments for each diff with a progress bar    with tqdm(total=len(changes), desc="Making code review", unit="diff") as pbar:     for i, change in enumerate(changes):           diff = change["diff"]           comment, chatbot_context = generate_comment(diff, chatbot_context)           pbar.update(1)           # Write the diff and comment to the HTML           html_output += f"<h3>Diff</h3>\n<pre><code>{diff}</code></pre>\n"           html_output += f"<h3>Comment</h3>\n<pre>{add_code_tags(comment)}</pre>\n"    html_output += "</body>\n</html>"    # Write the HTML output to a file    with open(output_file_name, "w") as f:     f.write(html_output)    return output_file_name The `create_html_output` function defined above takes the `title`, `description`, `changes`, and `prompt` as inputs. It creates an HTML output file that contains the code review comments for each diff, along with the corresponding diff sections as code blocks with syntax highlighting. Let's explain it in more detail:First, the function initializes a random string to be used in the output file name. It creates the appropriate title and description text based on the provided inputs and sets up the initial `chatbot_context`. Next, the function generates the HTML structure and styling, including the necessary CSS and JavaScript libraries for syntax highlighting. It also includes a header section for the AI code review. Using a progress bar, the function iterates over each change in the changes list. For each change, it retrieves the `diff` and generates a comment using the `generate_comment` function. The progress bar is updated accordingly. The function then writes the `diff` and the corresponding comment to the HTML output. The `diff` is displayed within a `<pre><code>` block for better formatting, and the comment is wrapped in `<pre>` tags. The `add_code_tags` function is used to add code tags to the comment, highlighting any code snippets. After processing all the changes, the function completes the HTML structure by closing the `<body>` and `<html>` tags.Finally, the HTML output is written to a file with a randomly generated name. The file name is returned by the function as the output. This `create_html_output` function makes the final HTML output that presents the code review comments alongside the corresponding diff sections.9. Define a function to get diff changes from the pipeline:def get_diff_changes_from_pipeline():    # Get the piped input    piped_input = sys.stdin.read()    # Split the input into a list of diff sections    diffs = piped_input.split("diff --git")    # Create a list of dictionaries, where each dictionary contains a single diff section    diff_list = [{"diff": diff} for diff in diffs if diff]    return diff_list The `get_diff_changes_from_pipeline` function defined above retrieves the input from the pipeline, which is typically the output of a command like `git diff`. It reads the piped input using the`sys.stdin.read()`. The input is then split based on the "diff --git" string, which is commonly used to separate individual diff sections. This splits the input into a list of diff sections. By dividing the diff into separate sections, this function enables code reviews of very large projects. It overcomes the context limitation that LLMs have by processing each diff section independently. This approach allows for efficient and scalable code reviews, ensuring that the review process can handle projects of any size. The function returns the list of diff sections as the output, which can be further processed and utilized in the code review pipeline10. Define the main function:def main():    title, description, prompt = None, None, None    changes = get_diff_changes_from_pipeline()    # Parse command line arguments    parser = argparse.ArgumentParser(description="AI code review script")    parser.add_argument("--title", type=str, help="Title of the diff")    parser.add_argument("--description", type=str, help="Description of the diff")    parser.add_argument("--prompt", type=str, help="Custom prompt for the AI")    args = parser.parse_args()    title = args.title if args.title else title    description = args.description if args.description else description    prompt = args.prompt if args.prompt else PROMPT_TEMPLATE    output_file = create_html_output(title, description, changes, prompt)    try:     webbrowser.open(output_file)    except Exception:     print(f"Error running the web browser, you can try to open the outputfile: {output_file} manually") if __name__ == "__main__":    main() The `main` function serves as the entry point of the code review script. It begins by initializing the `title`, `description`, and `prompt` variables as `None`. Next, it calls the `get_diff_changes_from_pipeline` function to retrieve the diff changes from the pipeline. These changes will be used for the code review process. The script then parses the command line arguments using the `argparse` module. It allows specifying optional arguments such as `--title`, `--description`, and `--prompt` to customize the code review process. The values provided through the command line are assigned to the corresponding variables, overriding the default `None` values. After parsing the arguments, the `create_html_output` function is called to generate the HTML output file. The `title`, `description`, `changes`, and `prompt` is passed as arguments to the function. The output file name is returned and stored in the `output_file` variable. Finally, the script attempts to open the generated HTML file in the default web browser using the `webbrowser` module. If an error occurs during the process, a message is printed, suggesting manually opening the output file.11. Save the file and run it using the following command: git diff master..branch | python3 chatgpt_code_reviewer.pyA progress bar will be displayed and after a while, the browser will open an html file with the output of the command, depending on the number of files to review it may take a few seconds or a few minutes, in this video, you can see the process. Congratulations! You have now created your own ChatGPT code reviewer project from scratch. Remember to adapt and customize the prompt[1] based on your specific requirements and preferences. You can find the complete code on this ChatGPTCodeReviewer GitHub repository.Happy coding! Article Reference[1] The `prompt` is an essential component of the code review process using ChatGPT. It is typically a text that sets the context and provides instructions to the AI model about what is expected from its response like what it needs to review, specific questions, or guidelines to focus the AI's attention on particular aspects of the code.In the code, a default `PROMPT_TEMPLATE` is used if no custom prompt is provided. You can modify the `PROMPT_TEMPLATE` variable or pass your prompt using the `--prompt` argument to tailor the AI's behavior according to your specific requirements.By carefully crafting the prompt, you can help steer the AI's responses in a way that aligns with your code review expectations, ensuring the generated comments are relevant, constructive, and aligned with the desired code quality standards.Author Bio Luis Sobrecueva is a software engineer with many years of experience working with a wide range of different technologies in various operating systems, databases, and frameworks. He began his professional career developing software as a research fellow in the engineering projects area at the University of Oviedo. He continued in a private company developing low-level (C / C ++) database engines and visual development environments to later jump into the world of web development where he met Python and discovered his passion for Machine Learning, applying it to various large-scale projects, such as creating and deploying a recommender for a job board with several million users. It was also at that time when he began to contribute to open source deep learning projects and to participate in machine learning competitions and when he took several ML courses obtaining various certifications highlighting a MicroMasters Program in Statistics and Data Science at MIT and a Udacity Deep Learning nanodegree. He currently works as a Data Engineer at a ride-hailing company called Cabify, but continues to develop his career as an ML engineer by consulting and contributing to open-source projects such as OpenAI and Autokeras.Author of the book: Automated Machine Learning with AutoKeras 
Read more
  • 0
  • 0
  • 7679

article-image-help-chatgpt-improve-with-knowledge-graphs
Maxime Labonne
17 Jun 2023
9 min read
Save for later

Help ChatGPT Improve with Knowledge Graphs

Maxime Labonne
17 Jun 2023
9 min read
ChatGPT has shown impressive capabilities in processing and generating human-like text. However, it is not without its imperfections. A primary concern is the model's propensity to produce either inaccurate or obsolete answers, often called "hallucinations."The New York Times recently highlighted this issue in their article, "Here's What Happens When Your Lawyer Uses ChatGPT." It presents a lawsuit where a lawyer leaned heavily on ChatGPT to assist in preparing a court filing for a client suing an airline. The model generated fictional court decisions to back its arguments, which didn't go unnoticed. This incident underscores the need for solutions to ground AI models like ChatGPT and improve their performance.To address this, we propose an approach that focuses on augmenting ChatGPT using a knowledge graph. This method aims to provide a structured context, ensuring the model outputs are accurate but also relevant and up-to-date. By bridging the gap between the unstructured textual world of ChatGPT and the structured clarity of knowledge graphs, we strive to enhance the effectiveness and reliability of AI language models.All the code used in this article is available on Google Colab and on GitHub.What is a knowledge graph?A knowledge graph is a structured format of knowledge representation, usually composed of entities and relationships. In a typical knowledge graph, entities are the nodes, and the relationships between them are the edges. The graph-based representation allows complex relationships to be modeled in a way that's intuitive and closer to human understanding. Here is a simple illustration of a knowledge graph: Source: Wikipedia. CC BY-SA 4.0 Google has been using knowledge graphs since 2012 to provide additional contextual information and sources. The structured representation of data offers a new dimension of context to the AI model, grounding it in validated knowledge.Applying Knowledge Graphs to Improve ChatGPTA crucial limitation of ChatGPT is its lack of real-time information updates. Since the model was last trained using data up until 2021, it doesn't have access to events, data, or context after that year. This leads to ChatGPT having outdated or incomplete information about events, technological advancements, or other critical happenings post-2021.Let's illustrate this limitation by asking ChatGPT about a recent event, When did Apple announce the Vision Pro?. Given the model's knowledge cutoff in 2021, we would expect it to be unaware of this announcement, which happened in 2023.!pip install -q openai langchain import os import openai os.environ['OPENAI_API_KEY'] = "your OpenAI key" openai.api_key = os.environ['OPENAI_API_KEY'] question = "When did apple announced the Vision Pro?" completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", temperature=0, messages=[{"role": "user", "content": question}]) print(completion["choices"][0]["message"]["content"]) As an AI language model, I do not have access to current events or real-time information. However, as of my last training data, Apple has not announced any product called "Vision Pro." It is possible that this product does not exist or has not been announced yet. As expected, ChatGPT is unable to provide the correct answer due to its training data limitations. This clearly highlights the need for constant updates to the model's knowledge base, which can be addressed by integrating it with a continuously updated knowledge graph.By implementing such a knowledge graph, we can ensure that ChatGPT can provide accurate, current, and reliable information, effectively addressing the "hallucination" issues as well as the knowledge cutoff limitations.Sentence-Level Knowledge GraphsTo demonstrate this, we'll use the LangChain library, a powerful tool designed for building frameworks around large language models. The library includes a component called GraphIndexCreator, which can parse a sentence and create a knowledge graph. This component is currently limited and cannot process long corpus of text, but it serves as a perfect starting point for our experiment.Let's start with a straightforward sentence: "Apple announced the Vision Pro in 2023."from langchain.llms import OpenAI from langchain.indexes import GraphIndexCreator from langchain.chains import GraphQAChain from langchain.prompts import PromptTemplate text = "Apple announced the Vision Pro in 2023." index_creator = GraphIndexCreator(llm=OpenAI(temperature=0)) graph = index_creator.from_text(text) graph.get_triples()[('Apple', 'Vision Pro', 'announced'), ('Vision Pro', '2023', 'was announced in')] By feeding this sentence into the GraphIndexCreator, it creates a knowledge graph by identifying the sentence's entities and relationships, forming triplets of information in the format of (source node, relation, and target node). However, the GraphIndexCreator might get confused with the relations and target nodes due to the inherent complexity of natural language.Even though it's a tiny graph based on a single sentence, we can represent it visually using popular Python libraries such as matplotlib and networkx.import networkx as nx import matplotlib.pyplot as plt # Create graph G = nx.DiGraph() G.add_edges_from((source, target, {'relation': relation}) for source, relation, target in graph.get_triples()) # Plot the graph plt.figure(figsize=(8,5), dpi=300) pos = nx.spring_layout(G, k=3, seed=0) nx.draw_networkx_nodes(G, pos, node_size=2000) nx.draw_networkx_edges(G, pos, edge_color='gray') nx.draw_networkx_labels(G, pos, font_size=12) edge_labels = nx.get_edge_attributes(G, 'relation') nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=10) # Display the plot plt.axis('off') plt.show() Image 2: Visual Pro Graph Now, let's enhance ChatGPT using the knowledge graph. We will use another component of the LangChain library, GraphQAChain, to this end.Initializing the GraphQAChain, we input the same question we asked earlier, "When did Apple announce the Vision Pro?". This time, ChatGPT leverages the knowledge graph we've just built.chain = GraphQAChain.from_llm(OpenAI(temperature=0), graph=graph, verbose=True) chain.run(question)> Entering new GraphQAChain chain...Entities Extracted: Apple, Vision ProFull Context:Apple announced Vision ProVision Pro was announced in 2023> Finished chain. Apple announced Vision Pro in 2023.This time, ChatGPT was able to output the correct information! The good thing is that we don't need any parser to build our knowledge graphs and can use existing ones. In the next experiment, let's try to use a bigger graph and see if it's still as performant.Bigger Knowledge GraphsIn this experiment, we manually create this more complex graph by supplying a list of triplets to the GraphIndexCreator object using the add_triple() method. Each triplet represents a distinct piece of knowledge related to Apple, such as the products it has created or where it is located.from langchain.graphs.networkx_graph import KnowledgeTriple # Knowledge graph kg = [ ('Apple', 'is', 'Company'), ('Apple', 'created', 'iMac'), ('Apple', 'created', 'iPhone'), ('Apple', 'created', 'Apple Watch'), ('Apple', 'created', 'Vision Pro'), ('Apple', 'developed', 'macOS'), ('Apple', 'developed', 'iOS'), ('Apple', 'developed', 'watchOS'), ('Apple', 'is located in', 'USA'), ('Steve Jobs', 'co-founded', 'Apple'), ('Steve Wozniak', 'co-founded', 'Apple'), ('Tim Cook', 'is the CEO of', 'Apple'), ('iOS', 'runs on', 'iPhone'), ('macOS', 'runs on', 'iMac'), ('watchOS', 'runs on', 'Apple Watch'), ('Apple', 'was founded in', '1976'), ('Apple', 'owns', 'App Store'), ('App Store', 'sells', 'iOS apps'), ('iPhone', 'announced in', '2007'), ('iMac', 'announced in', '1998'), ('Apple Watch', 'announced in', '2014'), ('Vision Pro', 'announced in', '2023'), ] graph = index_creator.from_text('') for (node1, relation, node2) in kg: graph.add_triple(KnowledgeTriple(node1, relation, node2))Although we could include many more triplets (real-world knowledge graphs often encompass millions of nodes), the size of our graph for this demonstration is sufficient. When visualized, this more extensive knowledge graph exhibits greater complexity and a richer depiction of information.# Create directed graph G = nx.DiGraph() for node1, relation, node2 in kg: G.add_edge(node1, node2, label=relation) # Plot the graph plt.figure(figsize=(25, 25), dpi=300) pos = nx.spring_layout(G, k=2, iterations=50, seed=0) nx.draw_networkx_nodes(G, pos, node_size=5000) nx.draw_networkx_edges(G, pos, edge_color='gray', edgelist=G.edges(), width=2) nx.draw_networkx_labels(G, pos, font_size=12) edge_labels = nx.get_edge_attributes(G, 'label') nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=12) # Display the plot plt.axis('off') plt.show()Image 4: Larger GraphWith this larger graph, we once again ask ChatGPT the question: "When did Apple announce the Vision Pro?" Leveraging the GraphQAChain object, ChatGPT processes the information embedded in the knowledge graph.chain = GraphQAChain.from_llm(OpenAI(temperature=0), graph=graph, verbose=True) chain.run(question)> Entering new GraphQAChain chain...Entities Extracted: Apple, Vision ProFull Context:Apple is CompanyApple created iMacApple created iPhoneApple created Apple WatchApple created Vision ProApple developed macOSApple developed iOSApple developed watchOSApple is located in USAApple was founded in 1976Apple owns App StoreVision Pro announced in 2023> Finished chain. Apple announced the Vision Pro in 2023.ChatGPT successfully extracts the correct information from the more expansive knowledge graph. This result demonstrates that our model can not only scale to larger graphs but can also efficiently navigate a more extensive knowledge base.The possibilities for implementing larger and more diverse knowledge graphs are practically endless. They can be populated with data from various sources, such as legal documents, code documentation, scientific literature, and more, enhancing the AI's understanding and response accuracy across multiple domains. The integration of ChatGPT and knowledge graphs thus holds immense promise for future AI development.ConclusionAs seen in our experiments, knowledge graphs can significantly aid in grounding and improving ChatGPT's outputs. A key challenge with large knowledge graphs is finding connections between distant nodes, a problem often referred to as graph completion. Successfully addressing this issue would allow ChatGPT to make insightful connections and propose new ideas based on the information available in the knowledge graph.However, the process of integrating knowledge graphs into language models like ChatGPT is still an evolving field. To further explore the various applications and delve into the details of implementing knowledge graphs, consider the book "Hands-On Graph Neural Networks Using Python", which provides a comprehensive guide on this subject. Through this type of research and experimentation, we can continuously improve AI's ability to understand and generate text, moving us closer to more reliable and grounded AI models.Author BioMaxime Labonne is a senior applied researcher at J.P. Morgan with a Ph.D. in machine learning and cyber security from the Polytechnic Institute of Paris.During his Ph.D., Maxime worked on developing machine learning algorithms for anomaly detection in computer networks. He then joined the AI Connectivity Lab at Airbus, where he applied his expertise in machine learning to improve the security and performance of computer networks. He then joined J.P. Morgan, where he develops techniques to solve a variety of challenging problems in finance and other domains.In addition to his research work, Maxime is passionate about sharing his knowledge and experience with others through Twitter (@maximelabonne) and his personal blog.
Read more
  • 0
  • 0
  • 6478

article-image-making-the-best-out-of-hugging-face-hub-using-langchain
Ms. Valentina Alto
17 Jun 2023
6 min read
Save for later

Making the best out of Hugging Face Hub using LangChain

Ms. Valentina Alto
17 Jun 2023
6 min read
Since the launch of ChatGPT in November 2022, everyone is talking about GPT models and OpenAI. There is no doubt that the Generative Pre-trained Transformers (GPT) architecture developed by OpenAI has demonstrated incredible results, also given the investments in training (almost 500 billion tokens) and complexity of the model (175 billion parameters for the GPT-3).Nevertheless, there is an incredible number of open-source Large Language Models (LLMs) that have been widespread in the last months. Below are some examples:Dolly: 12 billion parameters LLM developed by Databricks and trained on their ML platform. Source codeàhttps://github.com/databrickslabs/dollyStableML: This is a series of LLM developed by StabilityAI, the company behind the popular image generation model Stable Diffusion. The series encompasses a variety of LLMs, some of which are fine-tuned on specific use cases. Source codeàhttps://github.com/Stability-AI/StableLMFalcon LLM: A 40 billion parameters LLM developed by the Technology Innovation Institute and trained on a particularly high-quality dataset called RefinedWeb. Plus, as for now (June 2023) ranks 1 globally in the latest Hugging Face independent verification of open-source AI models. Source codeà https://huggingface.co/tiiuaeGPT NeoX and GPT-J: An open-source reproduction of the OpenAI’s GPT series developed by Eulether AI, with respectively 40 and 6 billion parameters. Source codeà https://huggingface.co/EleutherAI/gpt-neox-20b and https://huggingface.co/EleutherAI/gpt-j-6bOpenLLaMa: As for the previous class of models, also this one is an open-source reproduction of Meta AI’s LLaMA and has 3.7 billion parameters. Source codeàhttps://github.com/openlm-research/open_llamaIf you are interested in getting deeper into those models and their performance, you can reference the Hugging Face leaderboard here.Image1: Hugging Face Leaderboard Now, LLMs are great, yet to unlock their real power we need them to be positioned within an applicative logic. In other words, we want our LLMs to infuse intelligence within our applications.For this purpose, we will be using LangChain, a powerful lightweight SDK which makes it easier to integrate and orchestrate LLMs within applications. LangChain is one of the most popular LLMs orchestrators, yet if you want to explore further packages I encourage you to read about Semantic Kernel and Jarvis.One of the nice things about LangChain is its integration with external tools: those might be OpenAI (and other LLMs vendors), data sources, search APIs, and so on. In this article, we are going to explore how LangChain makes it easier to leverage open-source LLMs by leveraging its integration with the Hugging Face Hub.Welcome to the realm of open source LLMsThe Hugging Face Hub serves as a comprehensive platform comprising more than 120k models, 20kdatasets, and 50k demo apps (Spaces), all of which are openly accessible and shared as open-source projects. It provides an online environment where developers can effortlessly collaborate and collectively develop machine learning solutions. Thanks to LangChain, it is way easier to start interacting with open-source LLMs. Plus, you can also surround those models with all the libraries provided by LangChain in terms of prompt design, memory retention, chain management, and so on.Let’s see an implementation with Python. To reproduce the code, make sure to have: Python 3.7.1 or higheràyou can check your Python version running python --version in your terminalLangChain installedàyou can install it via pip install langchainThe huggingface_hub Python package installedà you can install it via pip install huggingface_butHugging Face Hub API keyàto get the API key, you can register into the portal here and then generate your secret key.For this example, I’m going to use the lightest version of Dolly, developed by Databricks and available in three sizes: 3, 7, and 12 billion parameters.from langchain import HuggingFaceHub from getpass import getpass HUGGINGFACEHUB_API_TOKEN = "your-api-key" import os os.environ["HUGGINGFACEHUB_API_TOKEN"] = HUGGINGFACEHUB_API_TOKEN repo_id = " databricks/dolly-v2-3b" llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature":0, "max_length":64})As you can see from the above code, the only information we need are our Hugging Face Hub API key and the model’s repo ID; then, LangChain will take care of initializing our model thanks to the direct integration with Hugging Face Hub.Now that we have initialized our model, it is time to define the structure of the prompt:from langchain import PromptTemplate, LLMChain template = """Question: {question} Answer: Let's think step by step.""" prompt = PromptTemplate(template=template, input_variables=["question"]) llm_chain = LLMChain(prompt=prompt, llm=llm)Finally, we can feed our model with a first question:question = "In the first movie of Harry Potter, what is the name of the three-headed dog? “ print(llm_chain.run(question)) Output: The name of the three-headed dog in Harry Potter and the Philosopher Stone is Fuffy.Even though I tested the light version of Dolly with “only” 3 billion parameters, it came with pretty accurate results. Of course, for more complex tasks or real-world projects, heavier models might be taken into consideration, like the one emerging as top performers in the Hugging Face leaderboard mentioned at the beginning of this article.ConclusionThe realm of open-source LLM is growing exponentially, and this creates a vibrant environment of experimentation and tuning from which anyone can benefit. Plus, some interesting trends are rising, like the reduction of the number of models’ parameters in favour of an increase in quality of the training dataset. In fact, we saw that the current top performer among the open source model is Falcon LLM, with “only” 40 billion parameters, which gained its strength from the high-quality training dataset. Finally, with the development of orchestration frameworks like LangChain and similar, it’s getting easier and easier to leverage open source LLMs and integrate them into our applications. Referenceshttps://huggingface.co/docs/hub/indexOpen LLM Leaderboard — a Hugging Face Space by HuggingFaceH4Hugging Face Hub — 🦜🔗 LangChain 0.0.189Overview (huggingface.co)stabilityai (Stability AI) (huggingface.co)Stability-AI/StableLM: StableLM: Stability AI Language Models (github.com)Author BioValentina Alto graduated in 2021 in data science. Since 2020, she has been working at Microsoft as an Azure solution specialist, and since 2022, she has been focusing on data and AI workloads within the manufacturing and pharmaceutical industries. She has been working closely with system integrators on customer projects to deploy cloud architecture with a focus on modern data platforms, data mesh frameworks, IoT and real-time analytics, Azure Machine Learning, Azure Cognitive Services (including Azure OpenAI Service), and Power BI for dashboarding. Since commencing her academic journey, she has been writing tech articles on statistics, machine learning, deep learning, and AI in various publications and has authored a book on the fundamentals of machine learning with Python.Author of the book: Modern Generative AI with ChatGPT and OpenAI ModelsLink - Medium  LinkedIn  
Read more
  • 0
  • 0
  • 15487

article-image-creating-a-data-model-with-chatgpt-is-easier-than-you-think
Sagar Lad
16 Jun 2023
6 min read
Save for later

Creating a Data Model with ChatGPT is Easier than you think

Sagar Lad
16 Jun 2023
6 min read
In today's data-driven world, the ability to build accurate and efficient data models is paramount for businesses and individuals alike. However, the process of constructing a data model can often be complex and daunting, requiring specialized knowledge and technical skills. But what if there was a way to simplify this process and make it accessible to a wider audience? Enter ChatGPT, a powerful language model developed by OpenAI. In this article, we will explore how ChatGPT can be leveraged to build data models easily, using a practical example. By harnessing the capabilities of ChatGPT, you'll discover how data modeling can become a more approachable and intuitive task for everyone, regardless of their technical background.Build Data Model with ChatGPTConsider data modeling as the process of drawing diagrams for software applications that provide an overview of all the data pieces they include. The data flow is depicted in the diagram using text and symbols. It serves as a model for creating a new database that will allow a company to utilize the data efficiently for its needs. The primary objective of the data model is to establish an overall picture of the types of data that are used, how they are kept in the system, the relationships between the data entities, and the various ways in which they can be arranged and grouped. The norms and procedures for gathering feedback from the business stakeholders are taken into consideration when building data models.The Data Model functions as a better understanding of what is designed, much like a roadmap or blueprint might. It offers a comprehensive review of the standardized methodologies and schema to define and manage data in a way that is common and uniform throughout the organization. According to the level of abstraction, there are three different types of data models.Conceptual Data Model: It provides a helicopter view of the system description, its organization, and business rules to be considered. Initial project requirements are captured using the conceptual model. It mainly consists of the business entities, their constraints and characteristics, and the relationship between them for data integrity and security requirements.Logical Data Model: The logical data model provides detailed insights into the concepts and relationship which consists of data attributes and the relationship between the entities. It is very much useful for data-driven projects or initiatives.Physical Data Model: It provides an overview of how the data should be stored physically within the database. It is a final design to implement the relational database including the relationship using the primary and foreign keys.                           Image 1 : Types of Data Modelling TechniquesThe data model was created using a variety of data modeling methodologies, as seen in the graphic above. The most popular data modeling technique utilized by any corporate organization is entity relationship modeling, also known as dimensional modeling. Erwin Data Modeler, ER/Studio, Archi, and other tools are available on the market to construct data models utilizing these data modeling methodologies. The data Modelling technique mainly involves below steps :  Identify the entitiesFind the entity propertiesCreate a relationship between the entitiesCorrelated attributes to the entityDefine the degree of normalization to improve the performanceValidate and Finalise the data modelLet’s start with creating a data model using chatGPT. The goal is to ask chatGPT to start with the data modeling activities for the anti-money laundering(AML) system of a banking domain: Image 1: The data model for the banking system, Part 1  Image 2: Data Modelling  for AML Process for Bank As you can see in the image, once we provide an input to the chatGPT, it provides a step-by-step process of building the data model. The first step is to understand the AML regulations and identify the stakeholders for the system to capture the requirements. Once the stakeholders are identified, the next step is to define the data modeling goals including the list of data sources, and perform the data profiling. Once data profiling steps are done, the next activity is to create a conceptual, logical, and physical data model.Now, Let’s check with chatGPT to create a conceptual model with all the entities. Image 3: Conceptual Data Model, Part 1                 Image 4 : AML Conceptual ModelAfter the input, chatGPT responds with the list of actors, entities, and relationships between the entities to define the conceptual model. With this information, we can have a high-level overview of the system by building the conceptual data model. Let’s ask chatGPT to build the logical data model once the conceptual data model is ready:Image 5: AML data model for ERwin Tool                  Image 6 : AML Logical Data Model, Part 2 As you can see in the above image, step by step process to create a logical data model is to open the Erwin Tool and create a new data model. In the new data model, add all entities, their attributes, and the relationship between the entities. Once entities are defined, set up primary and foreign keys for all entities and validate the data model. After the validation, adjust the review comments and finalize the logical data model and generate the documentation for the same.Next, Let’s ask chatGPT if it can add new customer information to the existing conceptual model.                  Image 5 : AML Logical Data Model with Customer Information As we can see in the above image, chatGPT asks to first identify the source information and create an entity and attributes for the same. Once it is done, we have to define the cardinality to understand how entities are related to each other. Then define primary and foreign key relationships, data model validation and generate documentation.ConclusionIn this article, we understood the importance of building the data model and step by step process to create the data model. Later in this article, we also checked how to use chatGPT to create conceptual and logical data models.Author BioSagar Lad is a Cloud Data Solution Architect with a leading organisation and has deep expertise in designing and building Enterprise-grade Intelligent Azure Data and Analytics Solutions. He is a published author, content writer, Microsoft Certified Trainer, and C# Corner MVP.Link - Medium , Amazon , LinkedIn 
Read more
  • 0
  • 0
  • 12503
article-image-microsoft-fabric-revolutionizing-data-analytics-and-ai-integration
Julian Melanson
15 Jun 2023
7 min read
Save for later

Microsoft Fabric: Revolutionizing Data Analytics and AI Integration

Julian Melanson
15 Jun 2023
7 min read
In today's data-driven world, organizations are constantly seeking ways to unlock the full potential of their data and seamlessly integrate artificial intelligence into their operations. Addressing this need, Microsoft has introduced Microsoft Fabric at the Build 2023 developer conference. This cutting-edge data analytics platform brings together essential data and analytics tools into a unified software-as-a-service (SaaS) product. In this article, we will explore the features of Microsoft Fabric, uncovering how it simplifies AI integration and revolutionizes data analytics, empowering organizations to harness the power of their data.A Holistic Approach to Data AnalyticsMicrosoft Fabric offers a holistic solution by integrating platforms such as Data Factory, Synapse, and Power BI into a cohesive and comprehensive platform. By replacing disparate systems with a simplified and cost-effective platform, Microsoft Fabric provides organizations with a unified environment for AI integration. It consolidates essential components like data integration, data engineering, data warehousing, data science, real-time analytics, applied observability, and business intelligence into a single ecosystem, equipping data professionals with a comprehensive suite of tools.Core Workloads in Microsoft Fabric:Microsoft Fabric supports seven core workloads that cater to various aspects of data analytics and AI integration, ensuring a seamless end-to-end experience:Data Factory: This workload facilitates seamless data integration by offering over 150 connectors to popular cloud and on-premises data sources. With its user-friendly drag-and-drop functionality, Data Factory simplifies data integration tasks.Synapse Data Engineering: With a focus on data engineering, this workload promotes collaboration among data professionals, streamlining the data engineering workflow and ensuring efficient data processing.Synapse Data Science: Designed for data scientists, this workload enables the development, training, deployment, and management of AI models. It offers an end-to-end workflow and infrastructure support for streamlined AI development.Synapse Data Warehousing: This workload provides a converged lake house and data warehousing experience. Optimizing SQL performance on open data formats, it offers efficient and scalable data warehousing capabilities.Synapse Real-Time Analytics: Tailored for handling high volumes of streaming data, this workload enables developers to analyze semi-structured data in real time with minimal latency. It caters to IoT devices, telemetry, and log data.Power BI Integration: Microsoft Fabric seamlessly integrates powerful visualization capabilities and AI-driven analytics from Power BI. This integration empowers business analysts and users to derive valuable insights through visually appealing representations.Data Activator: This workload offers a no-code experience for real-time data detection and monitoring. By triggering notifications and actions based on predefined data patterns, Data Activator ensures proactive data management.Simplifying AI DevelopmentMicrosoft Fabric addresses the challenges organizations face in AI development by providing a unified platform that encompasses all necessary capabilities to extract insights from data and make them accessible to AI models or end users. To enhance usability, Fabric integrates its own copilot tool, allowing users to interact with the platform using natural language commands and a chat-like interface. This feature streamlines code generation, query creation, AI plugin development, custom Q&A, visualization creation, and more.The Power of OneLake and Integration with Microsoft 365Microsoft Fabric is built upon the OneLake open data lake platform, which serves as a central repository for data. OneLake eliminates the need for data extraction, replication, or movement, acting as a single source of truth. This streamlined approach enhances data governance while offering a scalable pricing model that aligns with usage. Furthermore, Fabric seamlessly integrates with Microsoft 365 applications, enabling users to discover and analyze data from OneLake directly within tools such as Microsoft Excel. This integration empowers users to generate Power BI reports with a single click, transforming data analysis into a more intuitive and efficient process. Additionally, Fabric enables users of Microsoft Teams to bring data directly into their chats, channels, meetings, and presentations, expanding the reach of data-driven insights. Moreover, sales professionals using Dynamics 365 can leverage Fabric and OneLake to unlock valuable insights on customer relationships and business processes.Getting Started with Microsoft FabricFollow these steps to start your Fabric (Preview) trial.Open the Fabric homepage and select the Account Manager.In the Account Manager, select Start Trial.If prompted, agree to the terms and then select Start Trial.Once your trial capacity is ready, you receive a confirmation message. Select Got it to begin working in Fabric.Open your Account manager again. Notice that you now have a heading for Trial status. Your Account manager keeps track of the number of days remaining in your trial. You also see the countdown in your Fabric menu bar when you work on a product experience.You now have a Fabric (Preview) trial that includes a Power BI individual trial (if you didn't already have a Power BI paid license) and a Fabric (Preview) trial capacity.Below is a list of end-to-end tutorials available in Microsoft Fabric with links to Microsoft’s website.Multi-experience tutorialsThe following table lists tutorials that span multiple Fabric experiences.Tutorial nameScenarioLakehouseIn this tutorial, you ingest, transform, and load the data of a fictional retail company, Wide World Importers, into the lakehouse and analyze sales data across various dimensions.Data ScienceIn this tutorial, you explore, clean, and transform a taxicab trip dataset, and build a machine-learning model to predict trip duration at scale on a large dataset.Real-Time AnalyticsIn this tutorial, you use the streaming and query capabilities of Real-Time Analytics to analyze the New York Yellow Taxi trip dataset. You uncover essential insights into trip statistics, taxi demand across the boroughs of New York, and other related insights.Data warehouseIn this tutorial, you build an end-to-end data warehouse for the fictional Wide World Importers company. You ingest data into a data warehouse, transform it using T-SQL and pipelines, run queries, and build reports.Experience-specific tutorialsThe following tutorials walk you through scenarios within specific Fabric experiences.Tutorial nameScenarioPower BIIn this tutorial, you build a dataflow and pipeline to bring data into a lakehouse, create a dimensional model, and generate a compelling report.Data FactoryIn this tutorial, you ingest data with data pipelines and transform data with dataflows, then use the automation and notification to create a complete data integration scenario.Data Science end-to-end AI samplesIn this set of tutorials, learn about the different Data Science experience capabilities and examples of how ML models can address your common business problems.Data Science - Price prediction with RIn this tutorial, you build a machine learning model to analyze and visualize the avocado prices in the US and predict future prices.SummaryMicrosoft Fabric revolutionizes data analytics and AI integration by providing organizations with a unified platform that simplifies the complex tasks involved in AI development. By consolidating data-related functionalities and integrating with Microsoft 365 applications, Fabric empowers users to harness the power of their data and make informed decisions. With its support for diverse workloads and integration with OneLake, Microsoft Fabric paves the way for organizations to unlock the full potential of data-driven insights and AI innovation. As the landscape of AI continues to evolve, Microsoft Fabric stands as a game-changing solution for organizations seeking to thrive in the era of data-driven decision-making.Author BioJulian Melanson is a full-time teacher and best-selling instructor dedicated to helping students realize their full potential. With the honor of teaching over 150,000 students from 130 countries across the globe, he has honed his teaching skills to become an expert in this field. He focuses on unlocking the potential of creativity and productivity with AI tools and filmmaking techniques learned over the years, creating countless content for clients from many industries.
Read more
  • 0
  • 0
  • 3971

article-image-using-langchain-for-large-language-model-powered-applications
Avratanu Biswas
15 Jun 2023
5 min read
Save for later

Using LangChain for Large Language Model — Powered Applications

Avratanu Biswas
15 Jun 2023
5 min read
This article is the second part of a series of articles, please refer to Part 2 for learning how to Get to grips with LangChain framework and how to utilize it for building LLM-powered AppsIntroductionLangChain is a powerful and open-source Python library specifically designed to enhance the usability, accessibility, and versatility of Large Language Models (LLMs) such as GPT-3 (Generative Pre-trained Transformer 3), BERT(Bidirectional Encoder Representations from Transformers), BLOOM (BigScience Large Open-science Open-access Multilingual Language Model). It provides developers with a comprehensive set of tools to seamlessly combine multiple prompts, creating a harmonious orchestra for working with LLMs effortlessly. The project was initiated by Harrison Chase, with the first commit made in late October 2022. In just a few weeks, LangChain gained immense popularity within the open-source community. Image 1: The popularity of the LangChain Python libraryLangChain for LLMsTo fully grasp the fundamentals of LangChain and utilize it effectively — understanding the fundamentals of LLMs is essential. In simple terms, LLMs are sophisticated language models or AI systems that have been extensively trained on massive amounts of text data to comprehend and generate human-like language. Albeit their powerful capabilities, LLMs are generic in nature i.e. lacking domain-specific knowledge or expertise. For instance, when addressing queries in fields like medicine or law, while an LLM can provide general insights, it, however, may struggle to offer in-depth or nuanced responses that require specialized expertise. Alongside such limitations, LLMs are susceptible to biases and inaccuracies present in training data which can yield contextually plausible, yet incorrect outputs. This is where LangChain shines — serving as an open-source library that leverages the power of LLMs and mitigates their drawbacks by providing abstractions and a diverse range of modules, akin to Lego blocks, thus facilitating intuitive integration with other tools and knowledge bases.In brief, LangChain presents a useful approach for handling text data, wherein the initial step involves preprocessing of the large corpus by segmenting it into smaller chunks or summaries. These chunks are then transformed into vector representations, enabling efficient comparisons and retrieval of similar chunks when questions are posed. This approach of preprocessing, real-time data collection, and interaction with the LLM is not only applicable to the specific context but can also be effectively utilized in other scenarios like code and semantic search.Image 2 - Typical workflow of Langchain ( Image created by Author)A typical workflow of LangChain involves several steps that enable efficient interaction between the user, the preprocessed text corpus, and the LLM. Notably, the strengths of LangChain lie in its provision of an abstraction layer, streamlining the intricate process of composing and integrating these text components, thereby enhancing overall efficiency and effectiveness.Key Attributes offered by LangChainThe core concept behind LangChain is its ability to connect a “Chain of thoughts” around LLMs, as evident from its name. However, LangChain is not limited to just a few LLMs —  it provides a wide range of components that work together as building blocks for advanced use cases involving LLMs. Now, let’s delve into the various components that the LangChain library offers, making our work with LLMs easier and more efficient.Image 3:  LangChain features at a glance. (Image created by Author)Prompts and Prompt Templates: Prompts refer to the inputs or queries we send to LLMs. As we have experienced with ChatGPT, the quality of the response depends heavily on the prompt. LangChain provides several functionalities to simplify the construction and handling of prompts. A prompt template consists of multiple parts, including instructions, content, and queries.Models: While LangChain itself does not provide LLMs, it leverages various Language Models (such as GPT3 and BLOOM, discussed earlier), Chat Models (like get-3.5-turbo), and Text Embedding Models (offered by CohereAI, HuggingFace, OpenAI).Chains: Chains are an end-to-end wrapper around multiple individual components, playing a major role in LangChain. The two most common types of chains are LLM chains and vector index chains.Memory: By default, Chains in LangChain are stateless, treating each incoming query or input independently without retaining context (i.e., lacking memory). To overcome this limitation, LangChain assists in both short-term memory (using previous conversational messages or summarised messages) and long-term memory (managing the retrieval and updating of information between conversations).Indexes: Index modules provide various document loaders to connect with different data resources and utility functions to seamlessly integrate with external vector databases like Pinecone, ChromoDB, and Weaviate, enabling smooth handling of large arrays of vector embeddings. The types of vector indexes include Document Loaders, Text Splitters, Retriever, and Vectorstore.Agents: While the sequence of chains is often deterministic, in certain applications, the sequence of calls may not be deterministic, with the next step depending on the user input and previous responses. Agents utilize LLMs to determine the appropriate actions and their orders. Agents perform these tasks using a suite of tools.Limitations on LangChain usageAbstraction challenge for debugging: The comprehensive abstraction provided by LangChain poses challenges for debugging as it becomes difficult to comprehend the underlying processes.Higher token consumption due to prompt coupling: Coupling a chain of prompts when executing multiple chains for a specific task often leads to higher token consumption, making it less cost-effective. Increased latency and slower performance: The latency period experienced when using LangChain in applications with agents or tools is higher, resulting in slower performance.Overall, LangChain provides a broad spectrum of features and modules that greatly enhance our interaction with LLMs. In the subsequent sections, we will explore the practical usage of LangChain and demonstrate how to build simple demo web applications using its capabilities.Referenceshttps://docs.langchain.com/docs/https://github.com/hwchase17/langchain https://medium.com/databutton/getting-started-with-langchain-a-powerful-tool-for-working-with-large-language-models-286419ba0842https://medium.com/@avra42/how-to-build-a-personalized-pdf-chat-bot-with-conversational-memory-965280c160f8AuthorAvratanu Biswas, Ph.D. Student ( Biophysics ), Educator, and Content Creator, ( Data Science, ML & AI ).Twitter    YouTube    Medium     GitHub
Read more
  • 0
  • 0
  • 19384

article-image-the-little-known-benefits-of-creating-architecture-design-with-chatgpt
Sagar Lad
15 Jun 2023
5 min read
Save for later

The Little-Known Benefits of Creating Architecture Design with ChatGPT

Sagar Lad
15 Jun 2023
5 min read
Software architecture acts as a blueprint for the system, using abstraction to control the system's complexity and establish inter-component communication. In the ever-evolving landscape of software architecture, a groundbreaking innovation has emerged, reshaping the way developers design and optimize their systems. Enter ChatGPT, an advanced language model that has revolutionized the field with its remarkable capabilities. With its deep understanding of natural language, ChatGPT is unlocking new horizons in software architecture. From streamlining development processes to enhancing user interactions, this article delves into the transformative potential of ChatGPT, exploring how it is reshaping the very foundations of software architecture as we know it.In this piece, we'll examine the value of software architecture and how chatGPT may help us build it.  Architecture Design with ChatGPTThe entire design of the software, its elements, and its behavior are represented by the software system architect. In a nutshell, it is a visual representation of how software applications are made by connecting their many components. The following are examples of software architecture activities: Implementation Details: It could be architectural artifacts, source code, documentation, repository, etc.Implementation Design decisions: It includes options for technology (cloud or on-premises), architectural style (monolithic or distributed), storage (AWS S3, Azure Blob, ADLS Gen2, etc.), ingestion pattern (batch or real-time streaming pattern), and more.Infrastructure Considerations: Deployment Choices, Component Configurations, etc.Let’s understand in detail about the process of software architecture.Requirement Gathering: Any project should begin with functional and non-functional requirements since they will determine how to create the software architecture and how to prepare the finished product in accordance with the needs of the stakeholders.Create a Helicopter view of the solution: Using the mind map, provide a high-level overview of the system's constituent parts. It is a useful method for capturing your requirements as a diagram.Refine functional and non-functional requirements: Examine the non-functional needs in terms of performance, security, cost-effectiveness, etc. once you have thoroughly refined the functional requirements to comprehend the overall functioning of the program.Design each component in detail: Start with creating the platform's infrastructure and creating the application components while taking into account the functional and non-functional needs.Create a phase-wise approach for the implementation: Once the infrastructure and application implementation design considerations are clear, begin preparing deliverables for a phased rollout. It should include the state of architecture as it is today, architecture in transition, and architecture in the future. Make a visual representation of the application and infrastructure, taking into account networking, security, and interconnection issues.Below are the best practices that can be followed while designing the software architecture for any application:Design your application considering the best and worst-case scenarioDesign your application which should be able to scale up and scale downCreate loosely coupled architecture design for the smooth functioning of the system Create a multi-thread processing to speed up the processing for batch and real-time streaming implementationDesign your application with 7 layers of security implementationMake a choice to store your dataNow, Let’s use ChatGPT to create a software architecture for an application. Our goal is to create a data mesh architecture for the retail industry using the azure technology. The major requirement is also to define and capture data architecture requirements.Image 1 - Part 1, Data mesh responseImage 2 - Part 2, Data mesh responseImage 3- Part 3, Data mesh responseImage 4- Part 4, Data mesh response ChatGPT first offers suggestions for a group of Azure services to be used to implement the batch and real-time streaming patterns after receiving input from the user. The principles for implementing a data mesh architecture are then provided, including domain-driven data ownership, data-driven products, self-service data infrastructure, and data governance, including data discovery and monitoring.Let’s check with chatGPT on how the networking setup should be done for these Azure services:Image 5: Part 1, Networking responseImage 6: Part 2 Networking response Image 7: Part 3 Networking response  The configuration of a VNET, subnet, NSG rules, Azure firewall, VNET peering, VPN gateway, and the private link is advised by chatGPT. These Azure networking components can be used to manage the services' interconnection. Another major requirement to implement data mesh architecture is also to check how domain-specific data will be managed and operationalized for the data mesh architecture. Image 8: Part 1,  Domain-specific Data ManagementImage 9: Part 2,  Domain-specific Data ManagementImage 10: Part 3,  Domain-specific Data ManagementThe goal of chatGPT's proposals is to produce domain-specific cleansed data that end users can utilize directly to extract value from the data. Since these data domain stores are being built by domain experts, they are also in charge of managing, supporting, and operationalizing the data as needed.ConclusionIn this post, we looked in detail at the overall process of software architecture design as well as its sequential process. The best techniques for creating the software architecture for any application were also demonstrated. Later, we used chatGPT to develop a data mesh architecture implementation, complete with networking setup and operationalization, for a retail domain.Author BioSagar Lad is a Cloud Data Solution Architect with a leading organization and has deep expertise in designing and building Enterprise-grade Intelligent Azure Data and Analytics Solutions. He is a published author, content writer, Microsoft Certified Trainer, and C# Corner MVP.Link - Medium , Amazon , LinkedIn  
Read more
  • 0
  • 0
  • 5737
article-image-babyagi-empowering-task-automation-through-advanced-ai-technologies
Rohan Chikorde
15 Jun 2023
8 min read
Save for later

BabyAGI: Empowering Task Automation through Advanced AI Technologies

Rohan Chikorde
15 Jun 2023
8 min read
In today's rapidly evolving technological landscape, the demand for efficient task automation has grown exponentially. Businesses and individuals alike are seeking innovative solutions to streamline their workflows, optimize resource allocation, and enhance productivity. In response to this demand, a groundbreaking autonomous AI agent called BabyAGI has emerged as a powerful tool for task management.BabyAGI stands out from traditional AI agents by leveraging cutting-edge technologies from OpenAI, Pinecone, LangChain, and Chroma. These technologies work in synergy to provide a comprehensive and versatile solution for automating tasks and achieving specific objectives.This comprehensive blog post aims to delve into the world of BabyAGI, exploring its unique features, functionalities, and potential applications. Additionally, it will provide a step-by-step guide on how to set up and run BabyAGI effectively, allowing users to harness its full potential for task automation. By the end of this blog post, you will have a deep understanding of BabyAGI and the tools required to utilize it successfully. Whether you're a project manager looking to optimize workflows, a content creator seeking innovative ideas, or an individual aiming to streamline personal tasks, BabyAGI can revolutionize your approach to task management.Understanding BabyAGIBabyAGI is an autonomous AI agent that brings together the power of various advanced technologies to revolutionize task automation. By leveraging the capabilities of OpenAI's GPT3.5 or GPT4 models, BabyAGI possesses a remarkable ability to generate creative ideas and insights. One of the distinguishing features of BabyAGI is its focus on brainstorming and ideation. Unlike traditional AI agents that rely on browsing external resources, BabyAGI draws upon its existing knowledge base, which is built using the vast amount of information available up until 2021. By avoiding interruptions caused by web searches, BabyAGI can maintain its train of thought and provide uninterrupted suggestions and solutions.The integration of Pinecone's vector database service is another key component of BabyAGI's capabilities. Pinecone enables BabyAGI to store and manage information in a unique way by converting it into vectors. These vectors capture the essential details of the data, making it easier for BabyAGI to understand and work with. LangChain, another technology incorporated into BabyAGI, enhances its integration potential. This means that BabyAGI can be seamlessly integrated into existing systems, allowing users to leverage its functionalities alongside other tools and resources.Chroma, the final technology in BabyAGI's arsenal, brings an innovative approach to the table. Chroma focuses on efficient task management, helping users prioritize and optimize their workflows. By automating repetitive and time-consuming tasks, BabyAGI frees up valuable resources and allows users to focus on more strategic and value-added activities. The combination of these advanced technologies in BabyAGI makes it a versatile and powerful tool for various industries and individuals. Project managers can leverage BabyAGI's brainstorming capabilities to generate new ideas and innovative approaches. Content creators can tap into BabyAGI's creativity to enhance their creative process and produce engaging content. Individuals can rely on BabyAGI to automate mundane tasks, freeing up time for more fulfilling activities.BabyAGI represents a significant leap forward in task automation. By combining the capabilities of OpenAI's models, Pinecone's vector database, LangChain's integration potential, and Chroma's efficiency, BabyAGI offers a unique and powerful solution for brainstorming, ideation, and task management. Its ability to generate creative ideas, prioritize tasks, and optimize workflows sets it apart as a revolutionary tool in the realm of AI-driven automation.How It WorksThe script operates through an endless loop, executing the following sequence:Retrieves the initial task from the list of tasks.Dispatches the task to the execution agent, which leverages OpenAI's API to accomplish the task within the given context.Enhances the obtained result and archives it in Chroma/Weaviate.Chroma is an open-source embedding database. Chroma makes it easy to build LLM apps by making knowledge, facts, and skills pluggable for LLMs. Weaviate is an open-source vector database. It allows you to store data objects and vector embeddings from your favorite ML models, and scale seamlessly into billions of data objects. Generates fresh tasks and reorganizes the task list based on the objective and the outcome of the preceding task.Image 1: Working, Pic Credits: https://github.com/yoheinakajima/babyagiThe function execution_agent() utilizes the OpenAI API, employing two parameters: the objective and the task. It sends a prompt to the OpenAI API, which in turn provides the task result. The prompt consists of a description of the AI system's task, the objective, and the task itself. The returned result is a string.In the function task_creation_agent(), OpenAI's API is employed to generate new tasks based on the objective and the result of the previous task. The function takes four parameters: the objective, the previous task's result, the task description, and the current task list. It sends a prompt to the OpenAI API, which response with a list of new tasks as strings. The function returns the new tasks as a list of dictionaries, where each dictionary contains the task name.The prioritization_agent() function utilizes the OpenAI API to rearrange the task list based on priority. It accepts the ID of the current task as a parameter. It sends a prompt to the OpenAI API, receiving the reprioritized task list as a numbered list.Lastly, the script utilizes Chroma/Weaviate to store and retrieve task results for context. It creates a Chroma/Weaviate collection using the specified table name in the TABLE_NAME variable. The script employs Chroma/Weaviate to store task results in the collection, including the task name and any additional metadata.Setting Up BabyAGITo unleash the power of BabyAGI, the first step is to ensure that Python and Git are installed on your system. Python serves as the programming language for BabyAGI, while Git enables easy access to the necessary files and updates. If you don't have Python and Git installed, you can obtain them from their respective sources. For Python, head over to python.org and download the latest version compatible with your operating system. Follow the installation instructions provided by the Python installer to set it up on your machine. It is recommended to choose the option to add Python to your system's PATH during installation for easier accessibility.For Windows users, Git can be obtained by visiting the official Git website. Download the appropriate installer for your system and execute it. The installer will guide you through the installation process, allowing you to choose the desired options. Select the option to add Git to your system's PATH for convenient usage. Once you have Python and Git installed, the next crucial step is to acquire an OpenAI API Key. This key grants you access to OpenAI's powerful GPT3.5 or GPT4 models, which are essential for BabyAGI's operation. To obtain an API Key, you need a paid OpenAI account.Visit the OpenAI website and log in to your account. Navigate to the API section and follow the instructions to obtain your API Key. It is crucial to keep this key secure as it provides access to powerful AI models and should not be shared with unauthorized individuals.  Image 2: OpenAI API KeyWith Python, Git, and the OpenAI API Key in place, you are now ready to proceed with setting up BabyAGI. The next step involves downloading the BabyAGI source code from its GitHub repository. Visit the GitHub page and locate the download option.Clone the repository via git clone https://github.com/yoheinakajima/babyagi.git and cd into the cloned repository. Install the required packages: pip install -r requirements.txtCopy the .env.example file to .env: cp .env.example .env. This is where you will set the following variables.Set your OpenAI API key in the OPENAI_API_KEY and OPENAPI_API_MODEL variables. In order to use with Weaviate you will also need to set up additional variables detailed here.             Set the name of the table where the task results will be stored in the TABLE_NAME variable.(Optional) Set the name of the BabyAGI instance in the BABY_NAME variable.(Optional) Set the objective of the task management system in the OBJECTIVE variable.(Optional) Set the first task of the system in the INITIAL_TASK variable.Run the script: python babyagi.pyNote: The intention behind this script is to run it continuously as an integral component of a task management system. It is crucial to exercise responsible usage due to the potential for high API utilization when running the script continuously.ConclusionBabyAGI is a revolutionary AI agent that brings together the strengths of OpenAI, LangChain, and Chroma to deliver a powerful tool for task automation. With its ability to generate creative ideas, optimize workflows, and enhance decision-making, BabyAGI is transforming the way professionals approach task management. By automating repetitive tasks and providing valuable insights, it empowers project managers, content creators, and decision-makers to achieve better outcomes and maximize productivity. As technology continues to evolve, BabyAGI stands at the forefront of innovation, paving the way for more efficient and intelligent task management in a wide range of industries.Author BioRohan is an accomplished AI Architect professional with a post-graduate in Machine Learning and Artificial Intelligence. With almost a decade of experience, he has successfully developed deep learning and machine learning models for various business applications. Rohan's expertise spans multiple domains, and he excels in programming languages such as R and Python, as well as analytics techniques like regression analysis and data mining. In addition to his technical prowess, he is an effective communicator, mentor, and team leader. Rohan's passion lies in machine learning, deep learning, and computer vision.LinkedIn
Read more
  • 0
  • 0
  • 5914

article-image-implementing-azure-ad-protection-with-chatgpt
Steve Miles
15 Jun 2023
8 min read
Save for later

Implementing Azure AD Protection with ChatGPT

Steve Miles
15 Jun 2023
8 min read
IntroductionCybersecurity professionals face numerous challenges daily, from threat detection to incident response. The advent of AI-powered language models, also called Generative AI such as ChatGPT or Google's Bard, has revolutionized how experts approach their tasks. In this tutorial, we will explore how ChatGPT can assist cybersecurity professionals in performing various tasks efficiently and effectively. From analyzing logs and conducting risk assessments to developing incident response strategies, ChatGPT's capabilities can be harnessed to streamline workflows and enhance productivity. In this blog, let's dive into the practical applications and benefits of integrating Generative AI into (cyber)security operations.In this article, we will cover a tutorial on implementing Azure AD Protection with ChatGPT and also cover certain other areas of cybersecurity where GPT can be beneficial.Implementing Azure AD Identity Protection with ChatGPTAzure AD Identity Protection helps organizations safeguard their Azure Active Directory (Azure AD) identities by detecting and mitigating identity-related risks. In this section, we will explore how ChatGPT can assist in implementing Azure AD Identity Protection through code examples using Python and the Microsoft Graph API.1. Set up the EnvironmentBefore we begin, ensure that you have the following prerequisites in place:Python is installed on your machine.The requests library is installed. You can install it using the following command: pip install requests Azure AD application registered with the appropriate permissions to access Azure AD Identity Protection.2. Acquire Access TokenTo interact with the Microsoft Graph API, we must acquire an access token. Use the following Python code to obtain the access token:```python import requests # Azure AD application details tenant_id = 'YOUR_TENANT_ID' client_id = 'YOUR_CLIENT_ID' client_secret = 'YOUR_CLIENT_SECRET' # Microsoft Graph token endpoint token_url = f'https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token' # Request access token payload = {    'grant_type': 'client_credentials',    'client_id': client_id,    'client_secret': client_secret,    'scope': 'https://graph.microsoft.com/.default' } response = requests.post(token_url, data=payload) if response.status_code == 200:    access_token = response.json()['access_token'] else:    print('Error: Failed to obtain access token') ```Make sure to replace the placeholders with your Azure AD application details.3. Query Azure AD Identity Protection Data with ChatGPTNow that we have the access token, we can leverage ChatGPT to query Azure AD Identity Protection data. Use the following code example to interact with the model and retrieve identity protection insights:```python import openai openai.api_key = 'YOUR_OPENAI_API_KEY' def query_model(question):    response = openai.Completion.create(        engine='text-davinci-003',        prompt=question,        max_tokens=100,        temperature=0.5,        n=1,        stop=None,        temperature=0.5,    )    if response.choices:        return response.choices[0].text.strip()    else:        return None # Example question for querying Azure AD Identity Protection data question = "What are the recent risky sign-ins detected by Azure AD Identity Protection?" # Microsoft Graph API endpoint for risky sign-ins graph_api_url = 'https://graph.microsoft.com/v1.0/identityProtection/riskyUsers' # Send API request with the access token headers = {    'Authorization': f'Bearer {access_token}',    'Content-Type': 'application/json' } response = requests.get(graph_api_url, headers=headers) if response.status_code == 200:    risky_sign_ins = response.json()    # Process the response as needed    # ...    # Query the AI model for insights or recommendations    insights = query_model(question)    if insights:        print("Identity Protection Insights:")        print(insights)    else:        print("Error: Failed to obtain insights from the AI model") else:    print("Error: Failed to retrieve risky sign-ins data from Azure AD Identity Protection") ```Ensure you have appropriate permissions and update the `graph_api_url` with the relevant endpoint for the Azure AD Identity Protection data you want to retrieve.4. Interpret and Utilize InsightsOnce you obtain insights from the AI model, interpret, and utilize them to improve your identity protection practices. This could involve taking proactive measures to mitigate risks, investigating suspicious activities, or implementing additional security measures based on the recommendations provided.Remember to adapt the code examples based on your specific requirements and refer to the Microsoft Graph API documentation for available endpoints and data structures. https://learn.microsoft.com/en-us/graph/Other application areas1. Analyzing Log FilesOne of the most important aspects of cybersecurity is analyzing log files for suspicious activity and potential security breaches. Chat can help businesses automate this process. By importing log files into the model, ChatGPT can quickly identify patterns, anomalies, and potentially malicious activities. This analysis allows cybersecurity professionals to focus on the most important issues, saving valuable time and effort. In addition, ChatGPT's ability to create human-readable summaries of log data simplifies the interpretation and communication of findings for stakeholders.2. Conducting Risk AssessmentsConducting a comprehensive risk assessment is essential to understanding an organization's security posture. ChatGPT can help in this process by using its powerful capabilities to provide context and insights. By interacting with the model, organizations can ask specific questions about potential vulnerabilities, attacks, or best practices related to their risk assessments. ChatGPT's feedback provides knowledge of the organization's security environment and offers real value actionable insights that help businesses identify and prioritize risks and remediation tasks.3. Developing Incident Response StrategiesTime is of the essence in a cybersecurity incident. Generative AI can be an invaluable tool for developing effective incident response mechanisms. By leveraging its natural language processing capabilities, businesses can use ChatGPT to brainstorm and optimize response processes. The model can provide recommendations based on historical data, industry standards, and best practices, helping to create robust and efficient incident response systems. Generative AI can understand and generate human-like responses, making it an ideal virtual security analyst for cybersecurity professionals in high-pressure and time-sensitive situations.4. Automating Routine TasksCybersecurity professionals are often faced with increasing volume and velocity of repetitive and time-consuming tasks, such as vulnerability assessments, log analysis, and updating firewall rules. Generative AI can help automate these routine tasks, freeing experts to focus on complex real-value organizational security challenges. By integrating ChatGPT with existing automation frameworks, organizations can create chatbot-like interfaces that interact with the model to perform pre-defined actions. This approach increases productivity and reduces the risk of human error associated with manual processing.5. Enhancing Threat Intelligence AnalysisEffective threat reporting is essential for proactive cybersecurity defenses. Generative AI can enhance threat intelligence data analysis by extracting insights from a vast repository of security information. By asking about emerging threats, known vulnerabilities, or attack techniques, administrators can gain a deeper understanding of the ongoing threat landscape. ChatGPT's ability to understand complex security issues enhances the accuracy and relevance of threat intelligence reports, contributing to timely decision-making.ConclusionIn conclusion, it is easier and more efficient to implement Azure AD in conjunction with ChatGPT. As the cybersecurity landscape continues to evolve, businesses must embrace AI-powered solutions to stay ahead of malicious actors. Generative AI provides valuable support for various cybersecurity tasks, including log analysis, risk assessment, incident response planning, workflow automation, and threat intelligence analysis capabilities, enabling cybersecurity professionals to streamline their workflow, increase productivity, and make more informed decisions. While it is important to exercise proper judgment and credentials when implementing AI models, integrating Generative AI  such as ChatGPT into the cybersecurity industry offers significant opportunities for businesses to manage their tasks faster, more accurately, and more efficiently.Author BioSteve Miles (SMiles) is the CTO responsible for the tools and technologies selection for the cloud practice of a multi-billion turnover IT distributor based in the UK and Ireland. He is also a multi-cloud and hybrid technology strategist with 20+ years of telco, co-location, hosted data center, hybrid, and multi-cloud infrastructure experience. Steve is an Alibaba Cloud MVP (Most Valuable Professional), as well as being a Microsoft Azure MVP (Most Valuable Professional), and MCT (Microsoft Certified Trainer). Published freelance author for Microsoft technologies and certification guides, as well as an editorial and technical reviewer. Amongst many hybrid/cloud-based certifications, he is Alibaba Cloud Certified, with 20+ Cloud/Hybrid based Microsoft certifications with 14 of those being in Azure.His roles have included network security architect, global solutions architect, public cloud security solutions architect, and Azure practice technical lead. He currently works for a leading multi-cloud distributor based in the UK and Dublin in a cloud and hybrid technology leadership role.His first Microsoft certification was on Windows NT. He is an MCP, MCITP, MCSA, and MCSE for Windows Server and many other Microsoft products. He also holds multiple Microsoft Fundamentals, Associate, Expert, and Specialty certifications in Azure Security, Identity, Network, M365, and D365. He also holds multiple security and networking vendor certifications, as well as PRINCE2 and ITIL, and is associated with industry bodies such as the CIF, ISCA, and IISP.Author of the book: Azure Security Cookbook 
Read more
  • 0
  • 0
  • 5008
Modal Close icon
Modal Close icon