08Oct

Demystifying Large Language Model Function Calling | by Cobus Greyling | Oct, 2024


Large Language Model (LLM) Function Calling enables models to interact directly with external functions and APIs, expanding their utility beyond language processing.

Before diving into demystifying LLM function calling, just a few considerations…

The term Large Language Model is increasingly seen as a general reference rather than a precise or technically accureate description.

Today, the term Foundation Models encompass a broader range of capabilities, including not only language but also vision and multimodal functionalities.

There are also specialised models like Small Language Models optimised for lightweight applications and Large Action Models, which are fine-tuned for structured outputs and agent-based tasks.

This evolution reflects the diversity in AI architectures, with models designed to meet specific needs across various domains and applications. As the landscape grows, terminology will likely continue to evolve.

When using the OpenAI API with function calling, the model itself does not run the functions.

Instead, it generates parameters for potential function calls.

Your application then decides how to handle these parameters, maintaining full control over whether to call the suggested function or take another action.

In AI language models, the introduction of functions adds a new layer of autonomy.

The function calling capability allows the model to independently determine whether a function call is needed to handle a particular task or if it should respond directly.

By doing so, the model dynamically selects the most suitable response strategy based on the context, enhancing both its adaptability and effectiveness.

This decision-making power introduces a more nuanced autonomy, enabling the model to switch seamlessly between execution and conversation.

In function calling with language models, the model operates autonomously to determine whether a specific function call is appropriate based on the request.

When it identifies a match, it transitions to a more structured approach, preparing data parameters needed for the function. This allows the language model to act as a mediator, enabling efficient function handling while maintaining flexibility in processing the request.

AI autonomy can be viewed on a spectrum, with varying levels of independence depending on the system’s design.

By integrating function calls within generative AI applications, we introduce not only structure but also an initial layer of autonomy.

This enables AI systems to assess and respond to specific requests with a degree of self-direction. As AI technology evolves, these levels of autonomy are expected to increase, allowing models to handle tasks with greater independence and sophistication.

Consequently, this progression will enhance AI’s capacity to manage complex functions autonomously.

From the Python application below, it can be seen that two functions are defined, for adding and another for subtracting.

These functions need not be as confined as in this simple illustrative example, it can break out to an API which is external.

You also see the schema which is defined for the functions and a description for each schema, together with a description for each input parameter.

pip install openai==0.28

import openai
import json

# Prompt user to input API key
api_key = input("Please enter your OpenAI API key: ")
openai.api_key = api_key

# Define the tools: an addition function and a subtraction function
def add_numbers(a, b):
return {"result": a + b}

def subtract_numbers(a, b):
return {"result": a - b}

# Define the function schema for OpenAI function calling
functions = [
{
"name": "add_numbers",
"description": "Add two numbers together",
"parameters": {
"type": "object",
"properties": {
"a": {
"type": "number",
"description": "The first number to add"
},
"b": {
"type": "number",
"description": "The second number to add"
}
},
"required": ["a", "b"]
}
},
{
"name": "subtract_numbers",
"description": "Subtract one number from another",
"parameters": {
"type": "object",
"properties": {
"a": {
"type": "number",
"description": "The number to subtract from"
},
"b": {
"type": "number",
"description": "The number to subtract"
}
},
"required": ["a", "b"]
}
}
]

# Define a function to handle the function calling based on the function name
def handle_function_call(function_name, arguments):
if function_name == "add_numbers":
return add_numbers(arguments['a'], arguments['b'])
elif function_name == "subtract_numbers":
return subtract_numbers(arguments['a'], arguments['b'])
else:
raise ValueError(f"Unknown function: {function_name}")

# Prompting the model with function calling
def call_gpt(prompt):
response = openai.ChatCompletion.create(
model="gpt-4-0613", # gpt-4-0613 supports function calling
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
],
functions=functions,
function_call="auto" # This allows the model to decide which function to call
)

# Prompting the model with function calling
def call_gpt(prompt):
response = openai.ChatCompletion.create(
model="gpt-4-0613", # gpt-4-0613 supports function calling
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
],
functions=functions,
function_call="auto" # This allows the model to decide which function to call
)

# Check if the model wants to call a function
message = response["choices"][0]["message"]
if "function_call" in message:
function_name = message["function_call"]["name"]
arguments = json.loads(message["function_call"]["arguments"])
result = handle_function_call(function_name, arguments)
print (function_name, arguments, result)
return f"Function called: {function_name}, Result: {result['result']}"
else:
return message["content"]

# Test the app
while True:
user_input = input("Enter a math problem (addition or subtraction) or 'exit' to quit: ")
if user_input.lower() == "exit":
break
response = call_gpt(user_input)
print(response)

Chief Evangelist @ Kore.ai | I’m passionate about exploring the intersection of AI and language. From Language Models, AI Agents to Agentic Applications, Development Frameworks & Data-Centric Productivity Tools, I share insights and ideas on how these technologies are shaping the future.

https://platform.openai.com/docs/guides/function-calling



Source link

07Oct

Exploring How the New OpenAI Realtime API Simplifies Voice Agent Flows | by Sami Maameri | Oct, 2024


Setting up a Voice Agent using Twilio and the OpenAI Realtime API

At the recent OpenAI Dev Day on October 1st, 2024, OpenAI’s biggest release was the reveal of their Realtime API:

“Today, we’re introducing a public beta of the Realtime API, enabling all paid developers to build low-latency, multimodal experiences in their apps.

Similar to ChatGPT’s Advanced Voice Mode, the Realtime API supports natural speech-to-speech conversations using the six preset voices already supported in the API.”

(source: OpenAI website)

As per their message, some of its key benefits include low latency, and its speech to speech capabilities. Let’s see how that plays out in practice in terms of building out voice AI agents.

It also has an interruption handling feature, so that the realtime stream will stop sending audio if it detects you are trying to speak over it, a useful feature for sure when building voice agents.

In this article we will:

  • Compare what a phone voice agent flow might have looked like before the Realtime API, and what it looks like now,
  • Review a GitHub project from Twilio that sets up a voice agent using the new Realtime API, so we can see what the implementation looks like in practice, and get an idea how the websockets and connections are setup for such an application,
  • Quickly review the React demo project from OpenAI that uses the Realtime API,
  • Compare the pricing of these various options.

Before the OpenAI Realtime API

To get a phone voice agent service working, there are some key services we require

  • Speech to Text ( e.g Deepgram),
  • LLM/Agent ( e.g OpenAI),
  • Text to Speech (e.g ElevenLabs).

These services are illustrated in the diagram below

(source https://github.com/twilio-labs/call-gpt, MIT license)

That of course means integration with a number of services, and separate API requests for each parts.

The new OpenAI Realtime API allows us to bundle all of those together into a single request, hence the term, speech to speech.

After the OpenAI Realtime API

This is what the flow diagram would look like for a similar new flow using the new OpenAI Realtime API.

Obviously this is a much simpler flow. What is happening is we are just passing the speech/audio from the phone call directly to the OpenAI Realtime API. No need for a speech to text intermediary service.

And on the response side, the Realtime API is again providing an audio stream as the response, which we can send right back to Twilio (i.e to the phone call response). So again, no need for an extra text to speech service, as it is all taken care of by the OpenAI Realtime API.

Let’s look at some code samples for this. Twilio has provided a great github repository example for setting up this Twilio and OpenAI Realtime API flow. You can find it here:

Here are some excerpts from key parts of the code related to setting up

  • the websockets connection from Twilio to our application, so that we can receive audio from the caller, and send audio back,
  • and the websockets connection to the OpenAI Realtime API from our application.

I have added some comments in the source code below to try and explain what is going on, expecially regarding the websocket connection between Twilio and our applicaion, and the websocket connection from our application to OpenAI. The triple dots (…) refere to sections of the source code that have been removed for brevity, since they are not critical to understanding the core features of how the flow works.

// On receiving a phone call, Twilio forwards the incoming call request to
// a webhook we specify, which is this endpoint here. This allows us to
// create programatic voice applications, for example using an AI agent
// to handle the phone call
//
// So, here we are providing an initial response to the call, and creating
// a websocket (called a MediaStream in Twilio, more on that below) to receive
// any future audio that comes into the call
fastify.all('/incoming', async (request, reply) => {
const twimlResponse = `

Please wait while we connect your call to the A. I. voice assistant, powered by Twilio and the Open-A.I. Realtime API
O.K. you can start talking!



`;

reply.type('text/xml').send(twimlResponse);
});

fastify.register(async (fastify) => {

// Here we are connecting our application to the websocket media stream we
// setup above. That means all audio that comes though the phone will come
// to this websocket connection we have setup here
fastify.get('/media-stream', { websocket: true }, (connection, req) => {
console.log('Client connected');

// Now, we are creating websocket connection to the OpenAI Realtime API
// This is the second leg of the flow diagram above
const openAiWs = new WebSocket('wss://api.openai.com/v1/realtime?model=gpt-4o-realtime-preview-2024-10-01', {
headers: {
Authorization: `Bearer ${OPENAI_API_KEY}`,
"OpenAI-Beta": "realtime=v1"
}
});

...

// Here we are setting up the listener on the OpenAI Realtime API
// websockets connection. We are specifying how we would like it to
// handle any incoming audio streams that have come back from the
// Realtime API.
openAiWs.on('message', (data) => {
try {
const response = JSON.parse(data);

...

// This response type indicates an LLM responce from the Realtime API
// So we want to forward this response back to the Twilio Mediat Stream
// websockets connection, which the caller will hear as a response on
// on the phone
if (response.type === 'response.audio.delta' && response.delta) {
const audioDelta = {
event: 'media',
streamSid: streamSid,
media: { payload: Buffer.from(response.delta, 'base64').toString('base64') }
};
// This is the actual part we are sending it back to the Twilio
// MediaStream websockets connection. Notice how we are sending the
// response back directly. No need for text to speech conversion from
// the OpenAI response. The OpenAI Realtime API already provides the
// response as an audio stream (i.e speech to speech)
connection.send(JSON.stringify(audioDelta));
}
} catch (error) {
console.error('Error processing OpenAI message:', error, 'Raw message:', data);
}
});

// This parts specifies how we handle incoming messages to the Twilio
// MediaStream websockets connection i.e how we handle audio that comes
// into the phone from the caller
connection.on('message', (message) => {
try {
const data = JSON.parse(message);

switch (data.event) {
// This case ('media') is that state for when there is audio data
// available on the Twilio MediaStream from the caller
case 'media':
// we first check out OpenAI Realtime API websockets
// connection is open
if (openAiWs.readyState === WebSocket.OPEN) {
const audioAppend = {
type: 'input_audio_buffer.append',
audio: data.media.payload
};
// and then forward the audio stream data to the
// Realtime API. Again, notice how we are sending the
// audio stream directly, not speech to text converstion
// as would have been required previously
openAiWs.send(JSON.stringify(audioAppend));
}
break;

...
}
} catch (error) {
console.error('Error parsing message:', error, 'Message:', message);
}
});

...

fastify.listen({ port: PORT }, (err) => {
if (err) {
console.error(err);
process.exit(1);
}
console.log(`Server is listening on port ${PORT}`);
});

So, that is how the new OpenAI Realtime API flow plays out in practice.

Regarding the Twilio MediaStreams, you can read more about them here. They are a way to setup a websockets connection between a call to a Twilio phone number and your application. This allows streaming of audio from the call to and from you application, allowing you to build programmable voice applications over the phone.

To get to the code above running, you will need to setup a Twilio number and ngrok also. You can check out my other article over here for help setting those up.

Since access to the OpenAI Realtime API has just been rolled, not everyone may have access just yet. I intially was not able to access it. Running the application worked, but as soon as it tries to connect to the OpenAI Realtime API I got a 403 error. So in case you see the same issue, it could be related to not having access yet also.

OpenAI have also provided a great demo for testing out their Realtime API in the browser using a React app. I tested this out myself, and was very impressed with the speed of response from the voice agent coming from the Realtime API. The response is instant, there is no latency, and makes for a great user experience. I was definitley impressed when testing it out.

Sharing a link to the source code here. It has intructions in the README.md for how to get setup

This is a picture of what the application looks like once you get it running on local

(source https://github.com/openai/openai-realtime-console, MIT license)

Let’s compare the cost the of using the OpenAI Realtime API versus a more conventional approach using Deepagram for speech to text (STT) and text to speech (TTS) and using OpenAI GPT-4o for the LLM part.

Comparison using the prices from their websites shows that for a 1 minute conversation, with the caller speaking half the time, and the AI agent speaking the other half, the cost per minute using Deepgram and GPT-4o would be $0.0117/minute, whereas using the OpenAI Realtime API would be $0.15/minute.

That means using the OpenAI Realtime API would be just over 10x the price per minute.

It does sound like a fair amount more expensive, though we should balance that with some of the benefits the OpenAI Realtime API could provide, including

  • reduced latencies, crucial for having a good voice experience,
  • ease of setup due to fewer moving parts,
  • conversation interruption handling provided out of the box.

Also, please do be aware that prices can change over time, so the prices you find at the time of reading this article, may not be the same as those reflected above.

Hope that was helpful! What do you think of the new OpenAI Realtime API? Think you will be using it in any upcoming projects?

While we are here, are there any other tutorials or articles around voice agents andvoice AI you would be interested in? I am deep diving into that field a bit just now, so would be happy to look into anything people find interesting.

Happy hacking!



Source link

07Oct

Top 5 Geospatial Data APIs for Advanced Analysis | by Amanda Iglesias Moreno | Oct, 2024


Explore Overpass, Geoapify, Distancematrix.ai, Amadeus, and Mapillary for Advanced Mapping and Location Data

Kyle Glenn in Unsplash (Source: https://unsplash.com/es/@kylejglenn)

Geographic data is important in many analyses, enabling us to decide based on location and spatial patterns. Examples of projects where geodata can come in handy include predicting house prices, route optimization in transportation, or establishing a marketing strategy for business.

However, as a data scientist, you will frequently face the challenge of where to obtain this data. In many cases, there are public sources with information on geographic data; however, in many cases, the information they provide needs to be revised for the analyses we want to perform.

This article will evaluate five of the most useful APIs for obtaining large-scale geographic data. We will assess their usage, advantages and disadvantages, and the main applications of the information they provide. Think of this article as a fundamental foundation for the use and applications of these APIs, so that you can later delve deeper into all the tools they offer.

The Overpass API allows access to the information available on the OpenStreetMap website. OpenStreetMap is an open geographic…



Source link

06Oct

Efficient Testing of ETL Pipelines with Python | by Robin von Malottki | Oct, 2024


How to Instantly Detect Data Quality Issues and Identify their Causes

Photo by Digital Buggu and obtained from Pexels.com

In today’s data-driven world, organizations rely heavily on accurate data to make critical business decisions. As a responsible and trustworthy Data Engineer, ensuring data quality is paramount. Even a brief period of displaying incorrect data on a dashboard can lead to the rapid spread of misinformation throughout the entire organization, much like a highly infectious virus spreads through a living organism.

But how can we prevent this? Ideally, we would avoid data quality issues altogether. However, the sad truth is that it’s impossible to completely prevent them. Still, there are two key actions we can take to mitigate the impact.

  1. Be the first to know when a data quality issue arises
  2. Minimize the time required to fix the issue

In this blog, I’ll show you how to implement the second point directly in your code. I will create a data pipeline in Python using generated data from Mockaroo and leverage Tableau to quickly identify the cause of any failures. If you’re looking for an alternative testing framework, check out my article on An Introduction into Great Expectations with python.



Source link

03Oct

LLM Symbolic Reasoning For Visual AI Agents | by Cobus Greyling | Oct, 2024


These symbols can represent spatial realities (for example, chair next to table), allowing the model to reason logically about tasks & answer questions based on these spatial observations. This helps AI make decisions or plan actions in real-world contexts.

Human reasoning can be understood as a cooperation between the intuitive & associative, and the deliberative & logical. ~ Source

Considering the image below, conversational AI systems traditionally followed System 2 approaches, characterised by deliberate and logical reasoning.

These systems relied on intent detection and structured flows to determine action sequences. With the rise of Generative AI and Large Language Models (LLMs), there’s a shift toward System 1 solutions, which are more intuitive and associative.

A possible approach to activity reasoning is to build a symbolic system consisting of symbols and rules, connecting various elements to mimic human reasoning.

Previous attempts, though useful, faced challenges due to handcrafted symbols and limited rules derived from visual annotations. This limited their ability to generalise complex activities.

To address these issues, a new symbolic system is proposed with two key properties: broad-coverage symbols and rational rules. Instead of relying on expensive manual annotations, LLMs are leveraged to approximate these properties.

Given an image, symbols are extracted from visual content, and fuzzy logic is applied to deduce activity semantics based on rules, enhancing reasoning capabilities.

This shift exemplifies how intuitive, associative reasoning enabled by LLMs is pushing the boundaries of AI agent systems in tasks like activity recognition.

With just a quick glance at an image, we as humans can naturally translate visual inputs into symbols or concepts.

This allows us to use common-sense reasoning to understand and imagine the broader context beyond the visible scene — similar to how we infer the existence of gravity without directly seeing it.



Source link

03Oct

Chain-Of-Symbol Prompting To Improve Spatial Reasoning | by Cobus Greyling | Oct, 2024


Redundant natural language and irrelevant information also can hamper the performance of LLMs.

Using symbols to represent spatial relationships in word sequences can provide a clearer and more understandable framework for large language models (LLMs).

This method potentially simplifies data processing for the models.

Researchers are exploring the use of symbols in prompting LLMs, highlighting its importance as it extends beyond traditional language comprehension. This under-explored area offers valuable insights into enhancing LLM capabilities and understanding.

Using a set of symbols to represent spatial relationships between objects in complex environments.

To examine the impact of symbolic representations in prompting, researchers focus on complex spatial understanding and planning tasks.

These tasks require large language models (LLMs) to interpret virtual spatial environments described in natural language, while also planning and achieving specific objectives within those settings.

This approach helps assess how effectively LLMs can navigate and manipulate spatial information.

The model is posed with the following question:

Answer this question: I have a chair, two potatoes, a cauliflower, a lettuce head, two tables, a cabbage, two onions, and three fridges. How many vegetables do I have?

Symbolic reasoning involves reasoning about objects, their relation to each-other and concepts.

And The Model Response:

The question lists several items, but only some of them are vegetables. Here’s the breakdown:

  • Potatoes: 2 (vegetable)
  • Cauliflower: 1 (vegetable)
  • Lettuce head: 1 (vegetable)
  • Cabbage: 1 (vegetable)
  • Onions: 2 (vegetable)

The other items (chair, tables, and fridges) are not vegetables.

Total number of vegetables: 2 + 1 + 1 + 1 + 2 = 7.

So, you have 7 vegetables.

Spatial reasoning in natural language processing focuses on understanding and processing spatial information within text. Some researchers have explored methods for training models on navigation tasks that require agents to reach specific locations based on textual descriptions.

Others have developed tasks where models generate instructions from “before” and “after” image pairs or created benchmarks for answering spatial questions about environments. Additionally, it has been observed that large language models struggle with text-based games that involve multi-step reasoning.



Source link

01Oct

What I Learned in my First 9 Months as a Freelance Data Scientist | by CJ Sullivan | Oct, 2024


Photo by Persnickety Prints on Unsplash

I can’t believe it has already been 9 months since I have been working as a freelance data scientist! I originally wrote about making the leap after I was 3 months in. Getting started my husband and I agreed that we would try it for 3 months and that we would know after 3 months if it was going to work. I am very pleased (and fortunate) to say that we knew after about a month that it looked like freelancing was going to work for us.

My original post garnered a lot of public and private questions from people facing layoffs, return-to-office mandates (which are typically layoffs in disguise), and burn out. I also have learned a lot more in the past 6 months about how to make this work. I also made some key mistakes and have learned from them on some things not to do. So I thought it was time to post an update to the original post.

I do recommend that you read my original post first because there are some important things in there that I will not cover here. Like last time, I would also like to give a shout out to Brett Trainor who has created on online community (it is mostly Gen X-ers, but applicable to most people) called The Corporate Escapees dedicated to helping people free themselves from corporate work. He also has a great presence on TikTok. Brett and the “Escapees” have been great to bounce ideas off of and provide a wealth of information on getting started and flourishing while working as a freelancer, fractional, consultant, or solopreneur.

In my original post I had laid out several things I love about having gone out on my own. These things included stuff like working on what I work on when I want to work on it and making my own rules for my company. In the past 6 months I have discovered some new ones and learned more about the ones I already knew. So I thought I would briefly describe them here.

First, I (still) get to work from home. I have been working from home since 2017, which has given me the freedom to live where I want. I am a mountain creature and so the idea of moving to some random city away from all of the outdoor activities I love is not at all appealing to me. (In fact, I left the field of my PhD so that I could take a remote job…something that was not possible in that field.) More importantly, we are seeing many companies that went remote with the pandemic issue return to office (RTO) mandates. It is well documented that many of these are layoffs in disguise. So in reality, I have more job stability as a freelancer! And those companies that are laying off still have work that needs to be done. They just don’t have the positions to do it because they have laid people off. This means that freelancing is actually going to be more stable over the long run, because these companies will need to bring in someone to do the work!

Next — and this is no small one — is that I no longer am subjected to the huge waste of time that is a performance review. I have watched coworkers turn themselves inside out writing their self assessments fretting over every single punctuation mark only to have them essentially ignored. I have written many self assessments that included jokes and laughable things that managers have never commented on or noticed because they never read them! The process of performance reviews is broken. And what is the point when the majority of the time “meets expectations” lands you a so-called raise that is less than the increase in the cost of living?

This is not to say that as a freelancer your performance doesn’t matter. It is just that you don’t have to get all anxious and waste your time listening to your boss rattle back to you some list of accomplishments, tell you that you are doing a good job, and not give you too much reward for it. Instead, the reward for a freelancer (or the management of a poorly-performing one) is done through repeat business. Does a client choose to renew or extend your contract? Are they giving your name out to their friends as a referral? If so, job well done!

One that should not be overlooked is the fact that I have control over how my company-of-one runs. This has a lot of different impacts. First, I do not have to go ask numerous managers permission to work on a thing. If I want to work on something, I work on it. Ideally, there are others who need that type of work done that I can help. Second, I determine the finances of the company and don’t need to ask permission to attend a conference, take a class, travel to meet with a prospective client, or buy a new software tool. While it might sound silly, I actually am giddy (in a geeky kind of way) that I get to pick my own computer. I greatly dislike being forced to use Windows or Mac (Pop_OS FTW!!!) or being tied into a particular type of hardware. If I think it would benefit my business by me attending or speaking at a particular conference, I go and don’t need to play “Mother May I?” to get permission to go. If I decide I need to buy a particular book for my continuing education, I don’t need to ask someone. There is great freedom in this! (And, by the way, these things are tax deductible as well!)

Networking (Image created by author using DALL-E)

Definitely the most common questions I have received since writing my initial post 6 months ago have to do with networking. When you are working as a freelancer, the old saying goes: “your network is your net worth.” There are a lot of implications to this statement and not all of them are pretty. So I am going to share some hard truths here.

First, networks are established over time. Good networks include people who tend fall into one of a few categories:

  • People you have worked with in the past and are familiar with your work
  • Other people in your field who know of your experience, skills, and interests
  • People who work for companies that have problems that you can solve

(Note that this is not an exhaustive list, but you get the point.)

When you are freelancer you are selling a brand and that brand is you. Think about it like buying a car. You are not going to buy a car that is a brand you have never heard of. Further, you are not going to buy a brand that has not made a car before just because they have an assortment of parts. People buy things they trust.

What this means is that it is really hard to be a successful freelancer — in data science or otherwise — if you have not already been working as a data scientist for some period of time. When clients hire freelancers they are trying to solve a problem. They want to know that the freelancer they are hiring knows how to solve it and has experience in doing so. This means that it is very difficult to be a successful data science freelancer as your first job out of school. Even graduate school. Real-world experience is highly valued by those who look to hire freelancers.

The good news is that the act of getting that so-called real-world experience is already a key step in developing your network (i.e. the group in the first bullet point above). Many freelancers I know have their previous employers as some of their first clients. This is also why it is really important to avoid burning bridges with those you have worked with in the past, because you never know could be your client in the future!

In my previous post I suggested things like conference attendance and speaking as ways to grow your network further. I still hold to that. However, it is also important to recognize that not everyone does well at conferences. There are some neurodivergent people who find conferences to be difficult. And that is OK! There are ways to build your network beyond conferences, especially including things like blogging here and elsewhere! What you are looking to do, whether at conferences or blogging, is to grow your brand and brand awareness. When people think of you as a data scientist, what types of things do you want them to think of? Maybe you are a whiz at forecasting. Blog about it! Maybe you really enjoy writing code to solve a certain type of problem. Create a YouTube video about it!

Increasing your brand awareness (and network) through a good portfolio

The important thing here is about creating that brand awareness of the brand that is you. This, of course, means that people need to be able to find your brand and learn about it. Particularly if your network is not large, this means that people need to be able to see your work. Here is where creating a really awesome portfolio can help. Getting your portfolio in front of people in the last category above can help you grow your network and land jobs.

There is a ton of content out there about how to create a good data science portfolio. I will just summarize some key points here.

First, your portfolio should use an interesting data set. Do not use any data set from educational forums such as the Titanic data set, MNIST, cat versus dog via imagery, etc. Kaggle, while a great learning tool, does not always reflect the real work. You want the data to be as realistic as possible. It should be noisy and messy because this is how real-world data is. It should answer an interesting question (bonus points if it is an interesting question that could make a company money or solve a big problem). And it should also be data on a subject you are interested in and knowledgeable about so you can personally identify if the answers make sense and talk people through it like a subject matter expert.

Second, you need to tell a complete story for each project in your portfolio. Do not just put up a bunch of code with no explanation for how to use it. Do not provide results from some model without an explanation of what is going on with the model and the data and what conclusions should be drawn. A good portfolio project is as much about the explanations of your work as it is about the code. Your explanations should be extensive. You need to demonstrate that you not only know how to code, but know how to walk the reader through the full start-to-finish story of problem to solution.

Your portfolio projects, when possible, should be interactive. You want people to be able to see that the code runs. I personally am a big fan of setting up an inexpensive virtual machine somewhere and running Streamlit dashboards for interactivity.

Because your portfolio is about brand awareness, think about what your brand is. For example, if you are wanting to advertise yourself as being really good with recommendation engines, don’t waste time demonstrating solutions in image analysis. You are going to be showing your future clients the types of problems you can solve for them. The more obvious you make that, the better.

Finally, whenever you make an update to your portfolio, you need to get the word out there. Make a blog post or YouTube video to go with it. Make the code publicly available on GitHub or GitLab. Post on LinkedIn links to the portfolio and point out the new content. Post another link once the blog post is published.

Image created by author with DALL-E

I love being a specialist. Many people do. I have some pretty deep knowledge in some pretty specific domains. However, being a freelancer is about solving a problem. Frequently (and especially with startups that don’t have many employees) you will be expected to know how to do more than create the small, superb solution to the problem. You will need to know how to solve the problem from beginning to end. This means that you will need to work beyond that small, niche skill.

For me, this has meant that I have been learning (an ongoing process) many skills that go beyond my favorite areas of graphs, NLP, LLMs, etc. I have had to learn a fair bit more about data engineering, MLOps/LLMOps, and cloud architecture. I am paying to take classes and go to conferences on these subjects (see above…my management approved it 😉 ). These are investments in me, which means they are investments in my business. The more I can offer clients, the more clients whose problems I can solve. It is important as a freelancer that you be able to offer as much as possible!

Image created by author with DALL-E

Early on in my freelancing I was thinking about who my dream client is. Those who know me know that work culture really matters to me. The places I have seen with the work culture that most closely resembles my values tend to be startups. I also know the types of data science problems I like to work on (graphs, natural languages processing, generative AI, geospatial). So I initially figured that I would look just for startups with those types of problems.

I was then exposed to a great book called “The Freelancer’s Bible: Everything You Need to Know to Have the Career of Your Dreams―On Your Terms” by Sara Horowitz. This opened my eyes to a different way of looking at clients with an eye towards creating a diverse pool of current and prospective clients.

If you get into this book, you will learn that the best financial stability while freelancing comes from having a variety of types of clients ranging from major clients who are steady and consistent to those who might be profitable after some work with them to those who might be long shots. It is worth noting in my case that startups, by the very fact that they are startups and especially true of early-stage startups, might not necessarily be considered “steady and consistent.” If you rely only on them then you need to be prepared for your work to be cancelled or your hours cut due to fluctuations in the cash flow and budget. And it is a bad idea to compensate for that by taking on a lot of startups (see below on taking on too much work). This also means that you need to have a good financial cushion such that if hours dry up a bit for a period of time you can still pay your bills.

In practice, it is better to have an even mix of clients from companies that have been around for some time to startups and those in between. This will make your freelancing business more resilient to when contracts end or clients have to cut back your hours. Remember the goal: steady, predictable income.

Photo by Junseong Lee on Unsplash

If you came here looking to talk about health insurance in the United States as freelancer, I would direct you to the “Mistakes I have made so far section below.” Don’t worry, I will cover that topic. But let’s hit a few other insurance topics first.

By far, one of the biggest changes in going solo has been the fact that I no longer have company-provided benefits. This has a few implications that you need to factor in as you are determining your finances for going solo. This section might be fairly US-centric since other countries offer different benefits. But it is definitely something to educate yourself on, regardless of where you live.

First, when you are working for a company it is unlikely that they are going to sue you if you do a bad job (with a few exceptions, of course). However, when you are working as a solopreneur that is not a guarantee. When I was just getting started, I didn’t really think about these things. I just figured that my clients and I would have a contract with a solid statement of work, good communication, and clear deliverables and that would take care of that. I have not been sued (and hope that I never am!), but it is naive to think that it couldn’t happen at some point in the future.

This is what professional liability insurance is for. It covers both businesses and individuals for claims that might arise out of allegations of mistakes, missed deliveries, or breach of contract. In fact, some larger organizations that you might contract with actually require that you carry it. So best to plan for this in advance. It is really easy to get online and reasonable plans cost less than $200/month.

Another insurance I had not initially considered was long-term disability insurance. Many people have disability insurance, both short- and long-term, as part of their corporate benefits package and don’t even think about it. In my specific case, I am the sole bread winner for my family for a big portion of the year (my spouse works a seasonal job). If something were to happen to me and I couldn’t work, this would be a devastating blow to my family, one we could not afford. Therefore, getting disability insurance is something you should really think about.

Generally speaking “long term” means beyond 3 months. If you sit down and price it out, you will find that the price of short-term and long-term is about the same. Therefore, we decided not to get short-term disability insurance since it is so expensive, which implies that we will make sure that we are financially able to cover 3 months of living without an income should something happen to me.

Another big benefit that corporate employers offer (at least in the United States) is that they contribute something to your retirement. Typically, this is in the form of a 401k matching contribution. As a freelancer, you can still contribute to your retirement, but you need to make the conscious decision to do so since you will no longer have an employer automatically deducting it from your paycheck. Here is where I strongly recommend you talk with a financial advisor on the best ways to save for retirement.

Image created by author with DALL-E

I have likely made the idea of working freelance sound a bit like rainbows, puppies, and unicorns. In a way, that is how I feel. But I also have made some pretty big mistakes. So please learn from me and my mistakes and go into your decision-making process with better information than I had!

Health insurance

At least in the United States this is the 800 pound gorilla in the room that keeps people tied to corporate work. There is no reasonably-priced way to get health insurance when you are working for yourself. Yes, there is the open market (AKA Obamacare), so at least that option exists (a brief moment of tribute to the freelancers who went out there before Obamacare).

As I previously said, my spouse works seasonally but is offered health insurance during the season. So it made sense that we would go on is health insurance when I left corporate. This left us trying to figure out what we would do when the season was over. We had the option of COBRA (the ability to keep your health insurance through your existing, corporate plan while paying the full monthly premiums) or to go on the open market. Because I was having surgery while he was still working, we decided to do COBRA since I would be reaching my maximum out-of-pocket (OOP) and we could then take advantage of not having to pay anything for the rest of the year.

This. Was. A. Mistake.

The problem was that we didn’t fully realize how much COBRA costs. We knew it was expensive, but we completely underestimated. For our family of 3, it came out to $3000/month. Yes, really. Yet I now know that I can get comparable packages on the open market for half that. It is still not cheap and it is tax deductible either way. If I sat down and really calculated out how much we were saving by reaching max OOP, it still would have been cheaper to go on the open market. A lesson we will not repeat next year.

Taking on too much work

I will admit that I frequently worry that I will not have enough billable hours. In the beginning of the freelancing journey, you worry that you will not make enough money, so you take on a ton of work to make sure you do. Later in the journey, you will have a contract come to and end (sometimes prematurely) or a client throttle back your hours.

My anxiety sometimes gets the better of me. In an effort to make sure that I never dip below what I made in my corporate work, I have a tendency to overcompensate and take on too many clients or too many hours. I am very fortunate to be in the situation where I can do so. Some have suggested taht I bring on additional employees into my company so I can accommodate this work load. However, this is a double-edged sword. The moment you take on additional employees you are responsible for getting them work. If I am constantly nervous one month to the next about whether I will meet my income requirements, adding additional employees to that mix is only going to make that feeling worse.

One final note on that anxiety has to do with your financial planning. In my original article I talked a fair bit about this. However, I would like to add that you can help alleviate some of that anxiety by having a good amount of savings before going into freelancing. That way, should work be light for a particular month you know that you are not going to be immediately in trouble. One bit of advice I was given was to be able to support yourself without any paying work at all for 6 months. This might sound rather extreme, but having set aside money for when the work is light is very, very important.

On the complexities of working with larger organizations

It is great to be able to work with client organizations of all sizes. As I have previous stated, I really enjoy working with smaller startups. However, like I said before, diversity of clients is also important. Thus, it is a good idea to have some larger companies that you are supporting.

This is not without its complexities though. The larger the organization, the larger the bureaucracy. What this means for the freelancer is that it takes much more time and is much harder to get them under contract. They frequently have requirements for things like proof of liability insurance (see above), registration as an entity in complicated systems, and even drug and background tests. Sometimes they expect that you will pay for those things out of pocket before they can work with you.

It is important to keep all of this in mind should you wish to work with them. Not only will your time assembling these things not be compensated (and, in fact, will cost you money since it is taking time away from other paying clients), but you might also have to spend money in the form of fees for drug and background tests, signing up for liability insurance, etc. It is up to you to decide if it is worth it. Again, I refer you to the points about diversity of clients.

Photo by Duy Pham on Unsplash

The importance of a support network when you go out on your own cannot be overstated. When you work in a corporate setting, you can always meet up (in person or virtually) with a coworker for a gripe session, to bounce ideas off of, or just for general socialization. As a freelancer, you do not have that as easily and it can get lonely.

I have been able to make my freelancing work so far due to the support of a group of people. First and foremost, without the support of my husband this would not have been possible. In fact, I think going solo without the support of your significant other if you have one is a supremely bad idea. There is nothing certain or guaranteed about freelancing and that can be challenging on a family.

Similarly, it is important to have people to bounce ideas off of who are not your clients. There are many groups of solopreneurs available online, such as The Corporate Escapees I referred to before, who are like-situated individuals. Many are not data scientists themselves, but they possess a wealth of information on the business side of things. I strongly recommend finding a group that you resonate with.

Photo by Nick Fewings on Unsplash

I am very fortunate that 9 months in things are going strong! In my original post I talked about feeling much more secure not being in the corporate world. That is even more true today. With all of the layoffs in the tech world, I hear from friends and former colleagues all the time about how hard of a time they are having at finding a new job. This is really, really sad and I truly feel for them.

I also stated in the original article that my definition of success is whether I can sustain this model long term. I have experienced having my hours throttled and clients coming and going, but each time it seems that things have worked out since I have other work that comes up to take its place. So that seems very positive to me.

My next steps, which I hope to report back on 6 months from now, involve creating diversity of income streams. Working on an hourly basis as a freelancer is nice, but now I am looking to create other types of work, whether through retainers or creation of sellable products, that will generate revenue beyond simply billing hours. Stay tuned!





Source link

30Sep

GenAI with Python: Build Agents from Scratch (Complete Tutorial) | by Mauro Di Pietro | Sep, 2024


with Ollama, LangChain, LangGraph (No GPU, No APIKEY)

Photo by Mathieu Stern on Unsplash

(All images are by the author unless otherwise noted)

Intro

Prompt Engineering is the practice of designing and refining prompts (text inputs) to enhance the behavior of Large Language Models (LLMs). The goal is to get the desired responses from the model by carefully crafting the instructions. The most used prompting techniques are:

  • Chain-of-Thought: involves generating a step-by-step reasoning process to reach a conclusion. The model is pushed to “think out loud” by explicitly laying out the logical steps that lead to the final answer.
  • ReAct (Reason+Act): combines reasoning with action. The model not only thinks through a problem but also takes actions based on its reasoning. So it’s more interactive as the model alternates between reasoning steps and actions, refining its approach iteratively. Basically, it’s a loop of “thought”, “action”, “observation”.

Let’s make an example: imagine asking an AI to “find the best laptop under $1000”.

Normal Answer: “Lenovo Thinkpad”.

– Chain-of-Thought Answer: “I need to consider factors like performance, battery life, and…



Source link

29Sep

Exploring the Link Between Sleep Disorders and Health Indicators | by Mary Ara | Sep, 2024


A Python analysis of a MIMIC-IV health data (DREAMT) to uncover insights into factors affecting sleep disorders.

Photo by Benjamin Voros on Unsplash

In this article, I will be analysing participants’ information from the DREAMT dataset in order to uncover relationships between sleep disorders like sleep apnea, snoring, difficulty breathing, headaches, Restless Legs Syndrome (RLS), snorting and participant characteristics like age, gender, Body Mass Index (BMI), Arousal Index, Mean Oxygen Saturation (Mean_SaO2), medical history, Obstructive apnea-hypopnea index (OAHI) and Apnea-Hypopnea Index (AHI).

The participants here are those who took part in the DREAMT study.

The outcome will be a comprehensive data analytics report with visualizations, insights, and conclusion.

I will be employing a Jupyter notebook with Python libraries like Pandas, Numpy, Matplotlib and Seaborn.

The data being used for this analysis comes from DREAMT: Dataset for Real-time sleep stage EstimAtion using Multisensor wearable Technology 1.0.1. DREAMT is part of the MIMIC-IV datasets hosted by PhysioNet.



Source link

28Sep

Model Deployment with FastAPI, Azure, and Docker | by Sabrine Bendimerad | Sep, 2024


A Complete Guide to Serving a Machine Learning Model with FastAPI

pixabay.com

Welcome to this third article in my MLOps series. In the first article, we explored Docker and how it simplifies application packaging. In the second article, we managed machine learning models using MLflow, Azure, and Docker. Now, in this third part, we’ll bring everything together by building a FastAPI application that serves our previously stored model on Azure. This allows us to create a prediction service that can be accessed globally!

An API is like a bridge. Whenever you interact with a library in Python, you’re using its API. It’s the public part of an application that you can interact with, while everything behind it is hidden.

APIs are commonly used to communicate with web applications, and they provide a set of URLs that return data (You send a request with some parameters and get a response back). Most often, the data comes back in formats like JSON or XML, which are easy to parse. This is different from websites that return HTML, which includes info for rendering pages. With APIs, you get just the raw data.

Some APIs are public, while others are private. When building an API, you decide what data to share, how to…



Source link

Protected by Security by CleanTalk