Fine-tuning IPL AI Oracle to speak cricket fluently

Macbeth, Act V, Scene V by William Shakespeare

The IPL 2026 carnival is just around the corner, and my enhanced IPL app “IPL AI Oracle” is just in time for IPL fans. The current version of IPL AI Oracle, refines my earlier implementation to be more accurate and to handle a wider range of natural language queries related to IPL. My previous post “Introducing IPL AI Oracle: AI that speaks cricket!!! discusses an implementation which had 4 tabs

  • General queries
  • Match Analysis
  • Head-to-head
  • Team vs All Teams

The data for this app comes from Cricsheet. The data consists of ball-by-ball data for all IPL matches since 2006 in yaml format. This data was then pre-processed into a suitable format for use by the tabs both for the analytics and the natural language query functionality

The tabs provide analytics of IPL matches, head-to-head and team vs All Teams. Each of the 4 tabs allow for user query in natural language based on the tab general queries, queries on IPL matches, queries on head-to-head performance between 2 teams and natural language queries between a team versus All Teams.

For details about the implementation, please see the post “Introducing IPL AI Oracle: AI that speaks cricket!!! The IPL analytics are based on my Python package ‘yorkpy‘. which itself is based on its earlier avatar ‘yorkr‘ in R available in CRAN. For handling the natural language queries, in my previous implementaion, I used prompt templates for each of the tabs which would construct an appropriate prompt to gpt-4.1-nano LLM. Ths earlier implementation with prompt templates worked fine for a reasonable number of user queries. However, for each user query the prompt constructed was quite large and guzzled up tokens quite fast and I was running out of my subscription very early.

So, in this current implementation I finetune gpt-4o-mini-2024-07-18, one of the smaller gpt models, to keep the costs low. The prompt templates were reduced to the bare minimum. The gpt-40-mini-2024-17-18 model is then trained on hand-created individual training examples for each tab. The initial set of training examples was around 220 queries with corresponding pandas code. The split is as follows

  • matches: 65 rows
  • head_to_head: 50 rows
  • teamVsAllTeams: 48 rows
  • general_queries: 39 rows

This is the ground truth from which all other examples were created. Subsequently, I used Claude Sonnet 4.5 to augment the initial set of questions. The amplification essentially consisted of different ways of asking the same query for example

  • What is V Kohli’s strike rate in IPL?
  • Show me V Kohli’s strike rate
  • V Kohli’s strike rate
  • Display V Kohli’s strike rate etc
  • Can you tell me V Kohli’s Strike rate
  • Find V Kohli’s Strike rate

The augmented data set was used in finetuning. The finetuning process was done several times as I would take each finetuned model and test it manually. I would find issues. Sometimes the question pattern itself would be missing or it would generate incorrect response Fortunately Sonnet 4.5 helped me to identify patterns which were under-represented or were inconsistent with other queries with similar patterns. Additional training examples were added for complex queries which required the generation of a lot of code for e.g. the batting or bowling scorecard in matches, head_to_head or teamAllTeams

The original training examples are augmented to produce 2760 examples with 12 variations for simple patterns and 15 training examples for complex ones. The scorecard code is further boosted and the final number of training examples are 3831 training data which cannbe split into

  • matches: 1212 examples
  • head_to_head: 1032 examples
  • teamVsAllTeams: 1002 examples
  • general_queries: 585 examples

This training data is then shuffled and split into training and validation in the ratio of 3447 (90%) : 384 (10%).

The base model was gpt-4o-mini-2024-07-18 which was the smallest and most economical. The default hyper parameters were used

  • Epochs – 3
  • Batch size – 6
  • LR multiplier – 1.8
  • Seed – 3
  • Train loss – 0.000
  • Validation loss – 0.003
  • Full validation loss – 0.002

Try out the enhanced IPL AI Oraclehttps://wizard-ai-three.vercel.app/
(When you click the above link, a page will open. Enter your email and click ‘Send magic link‘ button below. This will send a magic link to your email. Click the ‘Sign in’ button which will allow you login to the app IPL AI Oracle and start using it.)

Natural language queries

Here are some random natural language queries in different tabs

A) General queries tab

This tab deals with general on IPL queries

1) Top 3 scorers in IPL 2025?

2) What is Virat Kohli’s best years in IPL?

3) How many ducks did Rohit Sharma score in IPL?

4) What is Ravindra Jadeja’s Economy rate?



B) Matches tab

This tab deals with a selected individual match

  1. Batting scorecard of CSK

2) How many runs did RR score in powerplay?


3) Who were the top 3 bowlers in this match?

4) Who took wickets for in middle overs for Delhi Capitals?

C) Head to head tab

This tab takes into consideration all matches played between the 2 selected teams

  1. Bowling scorecard of Delhi Capitals

2. Who took the most wickers for KKR?


3) Who were the top scorers for KKR in death overs?

D) Team vs All Teams

  1. Who were most wicket takers for Chennai Super Kings in death over?

2. How many sixes did Dhoni hit in death overs?

3. Which batsmen from Gujarat Titans scored more than 100 runs?

In addition I have added 2 other tabs to the earlier tabs. Now there is

  • Batting Analysis tab
  • Bowling Analysis tab

These tab provide various batting and bowling analytics for IPL players

E) Batting Analysis tab

  1. batsmansFoursSizes – AB De Villiers

2. batsmanRunsVsStrikeRate – AB de Villiers

3. batsmanMovingAverage – Virat Kohli

4. batsmanCumulativeStrikeRate – Chris Gayle

F) Bowling Analysis Tab

  1. bowlerMeanEconomyRate – Andre Russell

2. bowlerCumulativeAverageEconRate – Bhuvaneshwar Kumar

3. bowlerWicketsAgainstOpposition – Jasprit Bumrah

Try out the enhanced IPL AI Oraclehttps://wizard-ai-three.vercel.app/. Enter your email and click the magic link sent to your email.

Note:

  1. IPL AI Oracle can make mistakes and sometimes generate erroneous code
  2. If the answer is wrong try to rephrase the question.
  3. Try to use the full name Rohit Sharma if possible
  4. You can use abbreviations like ER, SR and for teams CSK, RCB, KKR etc
  5. IPL AI Oracle is not always one shot, sometimes it is 2-shot

I will try to improve the model in future versions. For the current version I had to do some of the steps including the testing manually. I would like to experiment with Claude Code and automate the generation of training data, finetuning, testing using the finetuned model (using a test harness) and subsequently correcting/adding to the training data if needed repeating the steps again till the tests pass with a high degree of accuracy. Lets see.

Do give IPL AI Oracle (https://wizard-ai-three.vercel.app/) a try!!!

Also see

  1. Deblurring with OpenCV: Weiner filter reloaded
  2. Introducing QCSimulator: A 5-qubit quantum computing simulator in R
  3. Deconstructing Convolutional Neural Networks with Tensorflow and Keras
  4. Natural language processing: What would Shakespeare say?
  5. Presentation on “Intelligent Networks, CAMEL protocol, services & applications”
  6. Re-introducing cricketr! : An R package to analyze performances of cricketers
  7. Deep Learning from first principles in Python, R and Octave – Part 4
  8. The Anomaly

To see all posts click Index of posts

Introducing IPL AI Oracle: AI that speaks cricket!!!

What would you think if I sang out of tune?
Would you stand up and walk out on me?
Lend me your ears and I’ll sing you a song
And I’ll try not to sing out of key

Oh, I get by with a little help from AI
Mm, I get high with a little help from AI
Mm, gonna try with a little help with AI

Adapted from “With A Little Help From My Friends” from the album Sgt. Pepper’s Lonely Heart Club Band, Beatles, 1967

Introduction
For quite some time I have been wanting to create an application that allows user to query cricket data in plain English (Natural Language Query) and get the appropriate answer. Finally, I have been able to realise this idea with my latest application “IPL AI Oracle:AI that speaks cricket!!!“. While I have just done this for IPL, it can be done for any of the other T20 leagues namely (Intl. T20 Men’s and Women’s, BBL, PSL, NTB, CPL, WBBL etc.). The current app “IPL AI Oracle” is in Python, and is a distant cousin of my Shiny app GooglyPlusPlus written entirely in R (see
IPL 2023:GooglyPlusPlus now with by AI/ML models, near real-time analytics!)

GooglyPlusPlus is much more sophisticated with detailed analytics of batsmen, bowlers, teams, matches, head-to-head, team-vs-AllTeams, batsmen and bowler ranking and analyis. GooglyPlus also includes ball-by-ball Win Probability models using Logistic Regression and Deep Learning models. While, ‘IPL AI Oracle’ lacks the ML/DL models it includes the ability to answer user queries in simple English (Natural Language Query -NLQ) and generate the pandas code for the same.

IPL AI Oracle

The IPL AI Oracle has a 2 main modules

  • frontend
  • backend

a) Frontend

The frontend is made with Next.js, Typescript and has 4 tabs

  1. General queries
  2. Match Analysis
  3. Head-to-head
  4. Team vs All Teams

The frontend includes analytics for matches, head-to-head and team-vs-allTeams options. Plots can be generated for some features and uses Plotly.js for rendering of plots

b) Backend

The backend implements FastAPI endpoints for the different analytics and natural language queries.
A) The analytics in the 3 tabs namely match analysis, head-to-head and team vs All teams are implemented using my Python package ‘yorkpy‘. Since my package yorkpy has all the cricket rules baked into it, I used the code from my package verbatim for these tabs.

B) The data for the analytics comes from Cricsheet. Cricsheet includes ball-by-ball data in yaml, for all IPL matches from the beginning of time. This data is pre-processed with R utilities of my Shiny app GooglyPlusPlus. These R functions to convert the match data into the data required format for the a) Match Analysis Tab b) Head-to-head tab and c) Team vs All Teams tab which are then subsequently converted to csv for use by my package yorkpy. My Python package is based on pandas and can process this data and display the analytics required for the tabs

C) Plotly is used for generating the plots

D) Jinja templates are used for creating the prompts for the different tabs

D) For natural language query in each tab, originally I used Ollama and tried out Mistral 7B and DeepSeek Coder 6.7B. But then I realised that it has a large footprint, if deployed, and hence settled for gpt-4.1-nano

The frontend is deployed on Vercel and the backend is dockerised and deployed on Railway. Since the clock is ticking for Vercel, Railway and GPT API, I will be closely monitoring the usage.

Give IPL AI Oracle a try. Click this link IPL AI Oracle. (When you click the link you will be asked to enter your email address, to which a magic link will be sent. Clicking the link will give access to the link. Please wait 2-3 minutes for the mail, if still not received check your spam/trash folder)

Here are some random screenshots from the different tabs

I) IPL Analytics
A) Match Analysis
a) Batting scorecard – Chennai Super Kings vs Gujarat Titans (2025-05-25)

b) Batsmen vs Bowlers (Mumbai Indians vs Delhi Capitals – 2025-04-13)

B) Head-to-head Analysis

a) Top Bowlers Performance (Delhi Capitals vs Kolkata Knight Riders – all matches)
This tab takes into consideration all matches played between these 2 teams and computes analytics between these 2 teams

b) Wicket Types Analysis (Rajasthan Royals vs Mumbai Indians – all matches)

C) Team vs All Teams

a) Team Bowling Scorecard – Royal Challengers Bangalore

II) Natural Language Query (User queries)

A) General Queries
i) How many runs did V Kohli score in total ?

ii) How runs did MS Dhoni score in 2017?

iii) Which team won the most matches?

iv) Which bowler has the best economy rate?

v) How many times did Chennai Super Kings defeat Rajasthan Royals?

vi) How many wickets did Bumrah take in 2017?

B) Match analysis – Natural Language query

To use the Natural Language Query in this tab, you have to choose the match. For e.g.Chennai Super Kings vs Mumbai Indians (2025-04-20). Selecting a match between 2 teams will automatically create natural language chips (with red arrow). You can select any one of the chips (button) or type in your own question and click Ask Question

i) Who scored the most runs in this match?

This can be verified by selecting the Batting scorecard for the match

ii) Who took the most wickets in this match?

iii) What is the economy rate of JC Archer?

C) Head-vs-Head (Natural Language Query)

Before typing in a Natural Language Query (NLQ) ensure that Team 1 and Team 2 are selected

a) Which bowler took the most wickets between Royal Challengers Bangalore and Chennai Super Kings?

b) Which batsmen scored between 30 to 40 runs in these matches?

D) Team vs All Teams (Natural Language Query)

Remember to select the Team before using NLQ

a) Who are the top 3 batsman for Gujarat Titans?

b) What was Punjab King’s win percentage?


How I Built IPL AI Oracle (with a Little Help from AI)

Here are key highlights behind the build

  • Data for this app comes from Cricsheet which provides ball-by-ball details in every IPL match as yaml files
  • Pre-processing of these yaml files were done using R utilities I already had into RData data frames, which were then subsequently converted to CSV for the different tabs
  • All the analytics is based on my handcoded package yorkpy as it has all the cricket rules baked in
  • AI assisted coding was used quite heavily for the front-end and the FastAPI backend. This was done using Cursor either with Sonnet 4.5 or GPT-5 Codex
  • Prompt templates for the different tabs were hand-crafted based on my package yorkpy
  • All-in all, the application is a healthy mix of hand-coding and AI assisted coding.

Conclusion

Since I had to deploy the application in 3 different platforms a) Vercel b) Railway c) OpenAI. I have the clock ticking in all these platforms. I initially tried gpt-4.1-mini (SLM) and then switched to gpt-4.1-nano (Tiny LM) as it is more cost effective. Since the gpt-4.1-nano has only a few hundred million parameters and is designed for low latency and cost-effectiveness, it is not as forgiving to typos or incorrect names, as some of the bigger LLMs like GPT-4o or Sonnet 4.5. Hence natural language queries work in most situations but at times they do fail. It requires quite a bit of fine-tuning I guess. Maybe work for some other day, by which time I hope the $X =N tokens/million come down drastically, so that even hobbyists like me can afford it comfortably.

Do check out IPL AI Oracle! You will get a magic link which will enable access.

Also see

  1. Deep Learning from first principles in Python, R and Octave – Part 4
  2. Introducing QCSimulator: A 5-qubit quantum computing simulator in R
  3. Natural language processing: What would Shakespeare say?
  4. De-blurring revisited with Wiener filter using OpenCV
  5. Singularity (A short science fiction)
  6. Re-introducing cricketr! : An R package to analyze performances of cricketers
  7. Big Data 6: The T20 Dance of Apache NiFi and yorkpy
  8. Fun simulation of a Chain in Android
  9. Presentation on “Intelligent Networks, CAMEL protocol, services & applications
  10. “Internet of Things”. TEDxBNMIT

To see all posts click Index of posts