Notebooks
A
Arize AI
Evaluate Code Readability Classifications

Evaluate Code Readability Classifications

agentsllmsLlamaIndexarize-phoenixopenaitutorialsevalsllmopsai-monitoringaiengineeringprompt-engineeringdatasetsllm-evalai-observabilityllm-evaluationsmolagentsanthropiclangchain

Open In Colab

phoenix logo
Docs | GitHub | Community

Code Readability Evals

Arize provides tooling to evaluate LLM applications, including tools to determine the readability or unreadability of code generated by LLM applications.

The purpose of this notebook is:

  • to evaluate the performance of an LLM-assisted approach to classifying generated code as readable or unreadable using datasets with ground-truth labels
  • to provide an experimental framework for users to iterate and improve on the default classification template.

Install Dependencies and Import Libraries

[ ]
[ ]

ℹ️ To enable async request submission in notebook environments like Jupyter or Google Colab, optionally use nest_asyncio. nest_asyncio globally patches asyncio to enable event loops to be re-entrant. This is not required for non-notebook environments.

Without nest_asyncio, eval submission can be much slower, depending on your organization's rate limits. Speed increases of about 5x are typical.

[ ]
[ ]

Download Benchmark Dataset

We'll evaluate the evaluation system consisting of an LLM model and settings in addition to an evaluation prompt template against a benchmark datasets of readable and unreadable code with ground-truth labels. Currently supported datasets for this task include:

  • openai_humaneval_with_readability
[ ]

Display Binary Readability Classification Template

View the default template used to classify readability. You can tweak this template and evaluate its performance relative to the default.

[ ]

The template variables are:

  • input: the query from the user describing the coding task
  • output: an implementation of the coding task

Configure the LLM

Configure your OpenAI API key.

[ ]

Instantiate the LLM and set parameters.

Benchmark Dataset Sample

Sample size determines run time Recommend iterating small: 100 samples Then increasing to large test set

[ ]

LLM Evals: Code Readability Classifications GPT-4

Run readability classifications against a subset of the data.

[ ]
[ ]

Evaluate the predictions against human-labeled ground-truth readability labels.

[ ]

Inspecting evaluations

Because the evals are binary classifications, we can easily sample a few rows where the evals deviated from ground truth and see what the actual code was in that case.

[ ]

Classifications with explanations

When evaluating a dataset for readability, it can be useful to know why the LLM classified text as readable or not. The following code block runs llm_classify with explanations turned on so that we can inspect why the LLM made the classification it did. There is speed tradeoff since more tokens is being generated but it can be highly informative when troubleshooting.

[ ]
[ ]

LLM Evals: Code Readability Classifications GPT-3.5

Run readability classifications against a subset of the data.

[ ]
[ ]

Preview: GPT-4 Turbo

[ ]
[ ]