This app is a demonstration of product summary creation given specifications and grammar correction using the OpenAI API with finetuned custom models. Check it out live here Grammar correction and Generate descriptions.
For preparing the data, johnlewis (https://johnlewis.com) website was scraped for categories womens-shoes, womens-boots, mens-trainers and mens-shoes. Product specification and Product description was scraped from the product pages of mentioned categories. Both product specification data and description were transformed in a manner so that the model would be able to understand clearly, as the number of training samples used was limited (320 training samples). Levenshtein distance was used to separate similar looking datapoints as they would not present any extra information in training.
OpenAI's model "Ada" (GPT-3 series) was chosen for this task as this model had the lowest cost among all. Better models like the davinci or the GPT-3.5 series can also be chosen for better results.
Data was prepared as per the expected input of the model, in pairs of prompts and completion, where prompts are the specification of the product (transformed) and completions are the expected description. After that, a finetuning job was queued using OpenAI's CLI. A validation set of 50 samples was also provided with 320 training samples. The model took about 15 minutes of time to finetune for 4 epochs, after which it was ready for inference. For inference, the parameters being used are temperature = 0.6, top_p = 1, frequency_penalty = 0, presence_penalty = 0, max_tokens = 256. These values were decided upon through experimentation and some common knowledge. Currently, the model can be inferenced on https://openai-experiments.onrender.com/finetuning.
-
If you don’t have Python installed, install it from here.
-
Clone this repository.
-
Navigate into the project directory:
$ cd openai-experiments
-
Create a new virtual environment:
$ python -m venv venv $ . venv/bin/activate
-
Install the requirements:
$ pip install -r requirements.txt
-
Make a copy of the example environment variables file:
$ cp .env.example .env
-
Add your API key to the newly created
.env
file. -
Run the app:
$ flask run
You should now be able to access the app at http://localhost:5000!.