LLMs are trendy, but there's an emerging ecosystem around them that opens the door to new ways of building AI solutions.
To say that AI has turned the world upside down is nothing short of an understatement. For better or worse, the launch of ChatGPT opened the floodgates to a wider audience. These days, you find people talking about AI the same way you would find them talking about politics, their hobbies, or their latest trends. Yes, yes, we all know that AI is more than NLP and generative transformers, but we cannot deny that ChatGPT (and Bard and Bing) is the killer AI app in the eyes of users.
OpenAI has opened up GPT-4 for its API to all users, Meta has released Llama2 under one of the most comprehensive , not-quite-open-but-still-very-flexible licenses on the market, Huggingface is seeing more users than ever, and Microsoft is pulling its weight reach to position Azure as the true solution for AI applications . And that's just the tip of the iceberg. We are living in a time full of opportunities for established companies and startups to tinker with AI and integrate it into their products.
But where to start? Generative AI is not a magic box. It's not like it can turn into a fully functional app (yet!). You also can't rule out a short script making an API call to a server to output something and call it a day. This might have worked a few years ago, when chatbots could be branded as “companion apps” . And even then, most of these applications needed to have a certain level of complexity to add context, memory, and other factors to make a conversation viable.
Today we're going to talk about complementary software, solutions that have grown out of the AI craze and that can help everyone from senior developers to no-code enthusiasts build AI solutions that meet their needs and their projects. But before we jump in, we should talk about a key number called Jerônimo Bruner .
Narrative Psychology as a Framework for AI
While the nature of this article is to explore and understand what tools we have at our disposal to build better AI solutions, we think it's important to start by thinking about how we will use these tools.
To be blunt, AI is not a solution in and of itself. You need to have a clear goal of what you want to achieve, and most importantly, you need to have a technology stack capable of managing the scope and intent of your project.
So what does psychology have to do with AI? A lot, actually. On the one hand, AI labs like OpenAI use behavioral psychology principles to teach their machines; Reinforcement learning is an applied technology that owes much to the enormous work of BF Skinner.
But today we are not going to talk about the principles of behaviorism. That would be a topic in itself. No. Today we're going to talk about cognitive psychology, a field that owes a lot to computer science and that, in turn, has a lot to teach us in terms of processing information in new ways.
During the first half of the 20th century, psychology focused on observing and analyzing behaviors. There was little interest in what was going on inside the mind. First, because psychology was trying to distance itself from philosophy and its approach to the mind, and second, because we didn't have the tools to measure how the brain processes information.
So psychology turned to computer science and information theory for solutions. Just as an algorithm models a process without precisely conveying how a CPU handles information, psychologists created models that explained how the mind works without having to explain what was happening in terms of brain cells.
In some ways, it was a fantastic solution to the problem that plagued American psychology, but it came at the cost of prejudices that plague the field to this day. Algorithms and models tend to favor linear and logical processes and, for better or worse, humans are not rational ; therefore, models tend to fail when we take complex behaviors and ideas into account.
Jerome Bruner is one of the cognitive psychologists who felt disillusioned with the less-than-ideal results the field was getting and, in response, published in the 1970s a fantastic book called Real Minds, Possible Worlds . In it, he would lay the foundations for a new theory of mind based on language and narrative.
His ideas encourage us to think critically about how AI should work too. Thanks to these new language models, we have seen the emergence of autonomous agents like BabyAGI – computer software with a semblance of “internal dialogue” together with short- and long-term memory. AI can plan, prioritize, execute and evaluate.
Yes, the underlying instructions are still zeros and ones – it is a computer program, after all – but we could say something similar about brain activity. After all, what is behind our thoughts if not the electrical activity in our brains (at least in part)?
Should AI rely purely on algorithms and data patterns, or should it also “understand” stories and contexts? A notable example is AI in healthcare, where understanding a patient's backstory – comprised of lifestyle choices, family history and cultural practices – is as critical to conclusive diagnoses as interpreting medical data.
Bruner also defends cognitive flexibility, implying possible worlds – or realities – that can be shaped through changes in our mental models. Therefore, when working with AI, this flexibility suggests employing multiple modeling techniques that cater to diverse scenarios, rather than rigidly adhering to a one-size-fits-all approach.
Consider weather forecasting: While we generally use regression models based on historical data to predict future conditions, we may need different models that prioritize real-time satellite imagery over obsolete historical records during adverse events like cyclones or floods.
Furthermore, Bruner presents tolerance to ambiguity as an intrinsic human attribute – a reminder for us to work with AI to design these systems to be resilient against uncertain data streams, rather than just precise streams.
Autonomous vehicles perfectly illustrate this principle: while driving in clear weather conditions can be managed by precise sensors and map databases, navigating on foggy mornings requires greater tolerance for ambiguous visual information – an entirely alternative strategy!
Last but not least, how cultural factors influence cognition provides fascinating insight, inviting us to create more culturally sensitive AI tools. Companies like Google have already started to embrace this idea; Your translation software now considers informal slang alongside official linguistic rules when interpreting languages.
But wouldn't solutions that work like humans be less logical, less accurate, and more error-prone? Well yes, but that's a feature, not a bug. Many companies stand to gain from implementing complex human agents as part of the service; for example, an artist who uses generative AI to create inspirational images may be inspired by a “mistake.”
Think about how many times you have been surprised by someone's ingenuity – for example, how children create fantastic stories and art because they are less likely to be overwhelmed by common sense. We wouldn't use mind-bending AI to make high-risk investments, but a writer looking for someone to bounce ideas off of could ask for nothing better.
So, with these ideas in mind, let's talk about tools and how they can help us create human-like agents.
Langchain
We could write a million articles about Langchain, and it wouldn't be enough to even scratch the surface of this extremely powerful framework. To quote from their website : “LangChain is a framework for developing applications powered by language models.”
If building an AI-powered application from scratch is like building a building with bricks and concrete, using langchain is like assembling a building using Lego blocks. And while this analogy may seem a little restrictive at first, don't forget that people have managed to build the Death Star out of Legos.
Silly comparisons aside, Langchain features a modular architecture, featuring different modules, each designed for a specific functionality. For example, the Models module integrates various models and language types, acting as the backbone for any Langchain-based application. A practical example would be the integration of a “BERT” model that provides semantic understanding for a Chatbot developed in Langchain.
Another example, the Prompts module, focuses on managing and optimizing prompts, thereby improving the relevance and accuracy of the result. For example, if we were developing a personal assistant app, fine-tuning the prompts could potentially improve its conversational skills by providing personalized responses to the user.
Going through each module would take a lot of time, so we recommend resources like the official Langchain Documentation and Langchain Tutorials . These how-to guides are packed with examples that provide valuable insights into working with Langchain and building AI-powered applications from the ground up.
Instead, let's focus on how tools like Langchain can be implemented. As some of you may have already guessed, Langchain works by adding a layer of abstraction. For example, instead of making direct API calls to a language model, Langchain takes care of this hassle for us.
This brings us to the first benefit. Since we're not working directly with API calls or libraries for a specific LLM solution, it's relatively easy to change AI providers (or mix and match with ease). If we do our jobs correctly, switching between LLMs will be as easy as changing a single line of code.
This gives you enormous flexibility and control over your project. Service providers sometimes change their policies without much concern for the impact it might have on their customers – case in point, the Reddit API Disaster . If you are tied to a single supplier, you are more vulnerable to sudden changes that could affect your product. Langchain helps you keep your codebase as reusable and future-proof as possible.
Langchain's power goes beyond its core modules, thanks to its extensive integrations with multiple language model providers, text embedding model providers, document loaders, and text splitters, among others. For example, Langchain not only has a modular system and extensive integrations, but also a wide range of real-world applications, from developing autonomous agents that make decisions based on evolving circumstances to creating personal assistants that remember interactions.
The Langchain pipeline is based on the idea of building chains of actions. For example, if we emulate an autonomous agent, we could design several links to build the chain, such as:
- A module that takes user input and classifies it, and based on that classification, sends the input to a specialized “brain”
- A series of specialized modules for each area; for example, custom-trained models for each area of our business to serve as chatbots for users
- A module that, based on the user's request, creates a series of steps to achieve their objective
- A module that prioritizes which step to take first
- A module that can search the web and scrape web pages to provide more accurate results
- A module that, based on the different answers from each step, builds a final answer
Note that what we are doing here is an extension of what Bruner tells us about human cognition. In human terms, we are just creating “inner voices” that handle different tasks – just like you “talk to yourself” when you are analyzing something or like some people talk to themselves when they are thinking.
One use case that we find particularly notable is Langchain's ability to query tabular data. Imagine an application where a user can ask to find all employees who joined in the last 6 months and live in a certain city in a company database. Leveraging Langchain, you can achieve this by using language models to interact with and extract insights from structured data.
Langchain is a versatile tool with vast potential for application across multiple domains. Starting to learn Langchain may seem daunting, but equipped with the right resources and an insatiable curiosity, you'll be on the right path. On the plus side, Langchain supports Python and Javascript, so it's not like you have to learn a new language from scratch.
Pinecone as an AI solution
What is pine cone? Pinecone is a managed vector database designed for machine learning applications. It's basically like giving our LLM solutions a nice upgrade – like going from a bicycle to a fully loaded sports car.
Now, if you have no idea what Pinecone is, don't worry; you are not alone. Many find it as perplexing as the crossword puzzles we see in our morning newspapers. But we are here to solve these confusion problems.
Pinecone is a vector database designed specifically for machine learning applications. To put it simply, vector databases are a type of software designed to handle heavy, multidimensional data often found in AI and machine learning applications.
Imagine you're shopping online for a new pair of sneakers and the website suggests items based on your searches and preferences. This is basically an AI feature known remotely as a “recommendation engine”. These engines extract tons of data to suggest relevant items. Now that's a lot of heavy lifting in terms of data! That's where our main star, Pinecone, comes into play. It indexes high-dimensional data more efficiently, making AI platforms like the “recommendation engine” work more efficiently. Cool, right?
Weaving a more technical layer, Pinecone uses data structures known as “Vector Spaces”. Visualize a vast cosmos where every star is a data point. Some of these stars are close neighbors, while others are galaxies far, far away. The proximity between stars determines their relationship or similarity.
Pinecone helps you find these neighbors efficiently and accurately. This capability forms the backbone of algorithms in recommendation systems, search engines, personalization, and anomaly detection, where relationships between data points are the bread and butter.
Remember that time you searched for a cat video and fell down the rabbit hole of cute animal videos for the next hour? This is a typical example of an AI recommendation system at work, enabled by engines like Pinecone.
Our first trick to leveraging Pinecone is to ditch traditional database solutions and adopt similarity searches. Pinecone uses vector embedding, which allows us to retrieve items based on their relational similarity rather than exact matches. This means our LLM solutions can understand context like never before.
Let's paint a picture here. Imagine having to find a pair of blue shoes in a huge closet. Traditional methods would force us to check every shoe. Not with pine cone! It would fit all the blue shoes we have in seconds.
Now, next, let's talk about the scalability that Pinecone offers. We know that scaling machine learning capabilities can be a difficult task. Pinecone, however, allows us to scale horizontally easily, making it possible to handle large volumes of data without sacrificing speed or efficiency.
Additionally, Pinecone puts a huge amount of power in our hands with real-time processing. So instead of waiting for results until the system processes our usual batch of data (like watching an entire season in one night), we get fast, real-time results (like live streaming an exciting sports game).
Lastly, Pinecone's ease of use should not be underestimated. After all, we want to spend our time on innovative ideas and not solving implementation problems. With its managed service approach, Pinecone takes complexity out of the equation. As easy as pie, right?
In Acts of Meaning , Bruner explains that humans are natural storytellers. Instead of remembering things like a perfect picture, we remember fragments of information and connect them with the same principles that authors use to write stories. These stories, in turn, are heavily influenced by the ideas and concepts shared by a community.
So what does this mean for our AI? Simple. Let's say you like video games and watch videos about them on YouTube. Now, a simple recommendation system would keep throwing video game content at you non-stop. But what if the system detects that you like a specific type of video game? For example, videos focused on the philosophical basis of games.
Suddenly, you see a recommendation from a philosophy channel, but what happens? You've never been interested in philosophy, right? Well, you play and get absorbed by the content. AI just guessed the proximity that helped you discover an interest you didn't know you had.
Pinecone allows us to store language in a very natural way, rather than relying on tables. We can have documents from different conversations and search results, and we use this dynamic search style to find results by proximity.
No, we are not creating awareness here; What we are trying to say is that we have a fantastic opportunity to rethink the way we approach AI as products and services – a way that is more human, that brings another way of understanding information that is not based on logic and reason.
Tools like Langchain and Pinecone are just two examples of how we can build complex systems with relative ease thanks to creativity and community effort. And as these tools continue to grow, you can be sure that the future of AI will be extremely bright.
If you liked this, be sure to check out our other articles on AI.
- The computer vision revolution is here – and it’s amazing
- Conscious Computers: The Future of NLP?
- ChatGPT corporate code leaks: Samsung's dilemma
- Could we develop a system similar to JARVIS?
- 9 Essential Skills Tech Workers Need in the Emerging Age of AI
Source: BairesDev