Where to Start – NLP with Azure OpenAI

I think without a doubt, one of the most talked about subjects at the moment is AI. Mass usage of OpenAI’s ChatGPT service exploded onto the scene this year, and we haven’t looked back. However, starting at such a broad scale of possibilities can be daunting. This post aims to simplify things down a bit, by looking at one single use case.

In this instance, I am going to take the Natural Language Processing capability offered by Azure OpenAI and have a GPT model summarise a piece of text for me. I completed sample lab files for this as part of a Microsoft Learn course, and I am reusing the Python here with some tweaks of mine!

All of the code for this solution is on Github here – https://github.com/wedoazure/sumo

The idea is that we take a text file, in my code I am using the first chapter from ‘Sherlock Holmes – The Hound of the Baskervilles’, but feel free to use whatever txt file you like, and send it to Azure OpenAI and ask for it to be summarised.

The app itself is command line based, very simple. It reads your text file, then sends a chat completion prompt to the Open AI model asking it to summarise your text.

The model then responds with a fixed length summary based on your input of word count and temperature.

The ability to adjust both is something I have added as my little variation. I had a couple of reasons for changing this up, but mostly built on the fact that your opinion of the output is important. For an example, read the actual text you want summarised, then have the app do it. Is the summary accurate? Is it a bit short, is it a bit too stiff? Change things up! Here is a 50 word summary at a temp of 0.5 versus 0.9 for the same txt file.

Sherlock Holmes and Dr. Watson examine a visitor’s stick, deducing that its owner is a country practitioner who walks a lot and has likely received a presentation from a hospital. The visitor, Dr. James Mortimer, arrives and confirms their deductions. He seeks Holmes’ assistance with a serious and extraordinary problem.

50 words at 0.5 temp

Dr. James Mortimer visits Sherlock Holmes and asks for his assistance with a mysterious problem. Through analyzing a stick left by a previous visitor, Holmes deduces that Dr. Mortimer is a country practitioner who used to work at Charing Cross Hospital. Dr. Mortimer confirms this and reveals that he has a strange case involving the curse of the Baskervilles.

50 words at 0.9 temp

As you can see, these are very different outputs, I personally prefer the response at 0.9, as I am summarising a work of fiction. However, if it was a financial report, you may need a lot less creativity and therefore force a lower temp. Similarly, you may want more words, or less, depending on your scope.

And that’s it! Short and sweet, using a single use case, minimal effort but impactful and useful outcome. I am sure I may make more tweaks, adding more advanced file input is definitely on the list. Let me know if you have any questions!

Leave a comment