Artificial Intelligence
Terminology
Inference
In the field of artificial intelligence (AI), inference is the process that a trained machine learning model uses to draw conclusions from brand-new data. An AI model capable of making inferences can do so without examples of the desired result. In other words, inference is an AI model in action.
Embeddings
Embeddings in AI are essentially numerical representations of data, like words or images, that capture their underlying relationships and meanings in a compact form. Think of them as condensed versions of information that help AI systems understand similarities, differences, and patterns more efficiently. These embeddings enable AI to perform tasks like language translation, image recognition, and recommendation systems by mapping complex data into a space where computations are easier, making AI smarter and more effective at various tasks.
Multimodal
Models that work with two or more types of data are known as “multimodal AI models”.
Types of modalities:
- Text (natural language)
- Visuals: images and video
- Audio: text-to-speech and speech-to-text, sound, music, ect.
Retrieval-augmented generation (RAG)
Retrieval-augmented generation (RAG) is an approach in artificial intelligence where a model generates text or other content based not only on its own knowledge but also on information retrieved from external sources.
In RAG, the model typically consists of two components: a generator, such as a language model like GPT, and a retriever, which retrieves relevant information from a large database or corpus. The generator then incorporates this retrieved information to produce more accurate, relevant, and contextually appropriate outputs.
This approach allows AI systems to generate content that is not only fluent and coherent but also grounded in real-world knowledge or specific domains. It’s particularly useful for tasks like question answering, summarization, and content generation where access to external information is beneficial.
Vectors
They’re mathematical entities that represent quantities or attributes of data, such as the features of an image or the words in a sentence. Vectors are used to store and manipulate this information in a way that computers can understand. For example, in image recognition, each pixel’s color and position could be represented by a vector. In natural language processing, words can be represented by vectors that capture their meanings and relationships with other words. Vectors are super handy because they allow AI systems to perform calculations and comparisons, making them essential for tasks like pattern recognition, classification, and prediction.
Semantic Search
Semantic search goes beyond matching keywords. It analyzes the intent, context, and semantics of your query, providing results that are more aligned with your expectations.
Effective Prompting
- Be specific
- Use technical terms
- Provide context
- Give examples
- Iterate
Example:
- How do I center something? vs
- How do I center an element on a webpage? vs
- How do I center a div element horizontally and vertically using CSS?
What does temperature do?
- Controls how daring the output is
- Can be set from 0 to 2
- Defaults to 1
Zero-Shot vs Few-Shots approach
In the Zero-Shot approach, imagine asking a language model to write a poem about love without ever giving it any examples of poetry or specific instructions on how to write about love.
In the Few-Shot approach, you might give the same model a few examples of love poems and ask it to write a new poem about love based on what it learned from those examples.
Open Source AI
Hugging Face
Hugging Face (https://huggingface.co/) is a machine learning (ML) and data science platform and community that helps users build, deploy and train machine learning models.
It provides the infrastructure to demo, run and deploy artificial intelligence (AI) in live applications. Users can also browse through models and data sets that other people have uploaded. Hugging Face is often called the GitHub of machine learning because it lets developers share and test their work openly.
Transformers.js
Transformers.js (https://xenova.github.io/transformers.js) allows to run hugging face transformers directly in the browser, with no need for a server!
Example code:
import { pipeline } from '@xenova/transformers';
// Allocate a pipeline for sentiment-analysis
let pipe = await pipeline('sentiment-analysis');
let out = await pipe('I love transformers!');
// [{'label': 'POSITIVE', 'score': 0.999817686}]
Ollama
Ollama (https://ollama.com/) is a tool to run Large Language Models locally, without the need of a cloud service. Its usage is similar to Docker, but it’s specifically designed for LLMs. You can use it as an interactive shell, through its REST API or using it from a Python library.
OpenAI
Useful links:
https://platform.openai.com/tokenizer
https://platform.openai.com/playground
https://platform.openai.com/docs/guides/safety-best-practices
Four types of AI risks
Safety Best Pratices (Moderation)
async function main() {
//note: relevant for both inputs and outputs
const completion = await openai.moderations.create({
input: "I hate you!"
});
const {flagged, categories} = completion.results[0];
console.log("flagged", flagged);
console.log("categories", categories);
}
More information: https://platform.openai.com/docs/guides/moderation/overview