I have to do this for a project: [project outline] Now that you have a balanced dataset,…
- User
I have to do this for a project:
[project outline] Now that you have a balanced dataset, your team needs to come up with different ways to prompt a LLM using your dataset as input. Once you have a list of prompts, you will need to abstract the prompts such that you can iterate through your dataset using your code. We will refer to these prompt abstractions as Prompt Templates. You can review online prompt template repositories to get a good idea. It can be difficult to parse LLM response because of non-standard response, it is a good idea to manually prompt the LLM first to get a sense of what logic is needed to parse your LLM responses.
What makes a good, average or bad response? Your team will design an evaluation protocol to measure the performance of the LLM. Depending on your problem, a simple exact match may suffice, other cases may need relaxed or heuristic approaches. Some use cases may best be evaluated by humans, do consider that there is only 3 of you and probably 1000 data points. The evaluation protocol and your experiment results are the main output of this project. This is a paradigm shift from software-based outputs common for most courses you have taken so far. To be clear, you are not making a website or an application that uses an LLM, you are designing and implementing evaluation experiments to measure the performance of LLMs. Your mentors will be there to help with the design choices, but you will need to document what you considered and the justification for the evaluation protocol in your final report. Good luck, we can’t wait to read all the ideas that you will come up with.
I have already done this:
create a vibe label for each song
def assign_vibe_label(row): if row['energy'] > 0.7 and row['valence'] > 0.6: return 'upbeat' elif row['energy'] > 0.7 and row['valence'] <= 0.6: return 'workout' elif row['energy'] <= 0.5 and row['valence'] > 0.6: return 'romantic' elif row['energy'] <= 0.5 and row['valence'] <= 0.4: return 'sad' else: return 'chill'
format an english-y prompt for each song
def format_song(row): mood = row['vibe_label'] speed = "fast" if row['tempo'] > 120 else "slow" if row['tempo'] < 90 else "medium-tempo" acousticness = "acoustic" if row['acousticness'] > 0.5 else "electronic"
codereturn f'"{row["track_name"]}" by {row["track_artist"]} is a {mood}, {speed} {row["playlist_genre"]} song that is {acousticness} and {"danceable" if row["danceability"] > 0.6 else "more relaxed"}.'prompt the model
def get_song_recommendations(prompt, selection): system_message = "You are a world famous DJ. Based on the following database of songs and their descriptions, recommend the specified amount of songs that match the requested vibe."
- Assistant
- User
my output from my model sometimes looks like this with the json in front of it:
RAW: '["AMOR DE CINE","Gratitude","Blue Drift","Barracuda","Lost Love"]' RAW: '["AZAMAN","Born to Be Alive - The Original","Do For Love","Como Quiero Yo","Dancing With Your Ghost"]' RAW: '
json\n["Run It Up (feat. Offset & Moneybagg Yo)","Bad (feat. Rihanna) - Remix","Club Can\'t Handle Me (feat. David Guetta)","Don\'t Sleep (feat. Thundercat)","Lean Wit Me"]\n'this is my current parse function: def parse_recommendations(raw_text): return json.loads(raw_text)
how can I make the ```json part go away?
- Assistant
To handle the output from your model that includes the unwanted "```json" part in some cases, you can modify your
parse_recommendationsfunction to strip away that portion before attempting to parse it as JSON. Here's how you can enhance the function:Updated Parse Function
You can add a couple of steps to clean the input before loading it as JSON:
- Remove the unwanted parts using string manipulation.