Generating Haikus with Llama 3.2

At the recent OPIG retreat, I was tasked with writing the pub quiz. The quiz included five rounds, and it’s always fun to do a couple “how well do you know your group?” style rounds. Since I work with Transformers, I thought it would be fun to get AI to create Haiku summaries of OPIGlet research descriptions from the website.

AI isn’t as funny as it used to be, but it’s a lot easier to get it to write something coherent. There are also lots of knobs you can turn like temperature, top_p, and the details of the prompt. I decided to use Meta’s new Llama 3.2-3B-Instruct model which is publicly available on Hugging Face. I ran it locally using vllm, and instructed it to write a haiku for each member’s description using a short script which parses the html from the website.

After playing around with temperature, top_p and prompts, I was able to get outputs which were creative but still (mostly) haikus. Here are a few of my favourites:

For Guy:

Benchmarks flawed
Optimism vs reality
Uncertainty reigns

For Henriette (with a bonus line):

Biotherapeutics
Golden threads of hope
Computing guides the way
Nature’s secrets yield

For Dylan:

Antimicrobial
Resistance spreads so fast now
Tuberculosis falls

I was impressed with the model’s style and ability to weave in just enough detail to identify the person. My script for generating these uses OpenAI’s Python API. Due to an error in my code, these were actually generated using client.completions.create rather than client.chat.completions.create which meant that the model (which was trained for chat) didn’t receive the prompt token and instead continued to autocomplete. This will work but will not generate clear, concise answers. Instead, it will often continue to generate text, sometimes critquing its own haiku until it hits the max token limit. To overcome this, I had to write extra code to regenerate the answers if they were too long. Once I switched to the chat interface, the model generated great responses on the first try every time. If you are interested in generating your own AI poetry, feel free to adapt the code from my GitHub.

Author