Enhancing air high quality with generative AI

As of this writing, Ghana ranks as the 27th most polluted country in the world, going through important challenges resulting from air air pollution. Recognizing the essential function of air high quality monitoring, many African international locations, together with Ghana, are adopting low-cost air high quality sensors.

The Sensor Evaluation and Training Centre for West Africa (Afri-SET), goals to make use of know-how to handle these challenges. Afri-SET engages with air quality sensor manufacturers, offering essential evaluations tailor-made to the African context. By way of evaluations of sensors and knowledgeable decision-making assist, Afri-SET empowers governments and civil society for efficient air high quality administration.

On December 6th-8th 2023, the non-profit group, Tech to the Rescue, in collaboration with AWS, organized the world’s largest Air Quality Hackathon – geared toward tackling one of many world’s most urgent well being and environmental challenges, air air pollution. Greater than 170 tech groups used the most recent cloud, machine studying and synthetic intelligence applied sciences to construct 33 options. The answer addressed on this weblog solves Afri-SET’s problem and was ranked as the highest 3 profitable options.

This put up presents an answer that makes use of a generative artificial intelligence (AI) to standardize air high quality knowledge from low-cost sensors in Africa, particularly addressing the air high quality knowledge integration downside of low-cost sensors. The answer harnesses the capabilities of generative AI, particularly Giant Language Fashions (LLMs), to handle the challenges posed by numerous sensor knowledge and mechanically generate Python features primarily based on varied knowledge codecs. The elemental goal is to construct a manufacturer-agnostic database, leveraging generative AI’s means to standardize sensor outputs, synchronize knowledge, and facilitate exact corrections.

Present challenges

Afri-SET at the moment merges knowledge from quite a few sources, using a bespoke strategy for every of the sensor producers. This guide synchronization course of, hindered by disparate knowledge codecs, is resource-intensive, limiting the potential for widespread knowledge orchestration. The platform, though purposeful, offers with CSV and JSON recordsdata containing a whole bunch of hundreds of rows from varied producers, demanding substantial effort for knowledge ingestion.

The target is to automate knowledge integration from varied sensor producers for Accra, Ghana, paving the way in which for scalability throughout West Africa. Regardless of the challenges, Afri-SET, with restricted assets, envisions a complete knowledge administration resolution for stakeholders looking for sensor internet hosting on their platform, aiming to ship correct knowledge from low-cost sensors. The try is deprived by the present deal with knowledge cleansing, diverting invaluable expertise away from constructing ML fashions for sensor calibration. Moreover, they intention to report corrected knowledge from low-cost sensors, which requires info past particular pollution.

The answer had the next necessities:

  • Cloud internet hosting – The answer should reside on the cloud, guaranteeing scalability and accessibility.
  • Automated knowledge ingestion – An automatic system is important for recognizing and synchronizing new (unseen), numerous knowledge codecs with minimal human intervention.
  • Format flexibility – The answer ought to accommodate each CSV and JSON inputs and be versatile on the formatting (any affordable column names, items of measure, any nested construction, or malformed CSV equivalent to lacking columns or further columns)
  • Golden copy preservation – Retaining an untouched copy of the info is crucial for reference and validation functions.
  • Price-effective – The answer ought to solely invoke LLM to generate reusable code on an as-needed foundation as a substitute of manipulating the info on to be as cost-effective as potential.

The objective was to construct a one-click resolution that takes completely different knowledge construction and codecs (CSV and JSON) and mechanically converts them to be built-in right into a database with unified headers, as proven within the following determine. This permits for knowledge to be aggregated for additional manufacturer-agnostic evaluation.

Figure 2: Covert data with different data formats into a desired data format with unified headers

Determine 1: Covert knowledge with completely different knowledge codecs right into a desired knowledge format with unified headers

Overview of resolution

The proposed resolution makes use of Anthropic’s Claude 2.1 basis mannequin by way of Amazon Bedrock to generate Python codes, which converts enter knowledge right into a unified knowledge format. LLMs excel at writing code and reasoning over textual content, however are likely to not carry out as properly when interacting straight with time-series knowledge. On this resolution, we leverage the reasoning and coding talents of LLMs for creating reusable Extract, Remodel, Load (ETL), which transforms sensor knowledge recordsdata that don’t conform to a common normal to be saved collectively for downstream calibration and evaluation. Moreover, we make the most of the reasoning capabilities of LLMs to grasp what the labels imply within the context of air high quality sensor, equivalent to particulate matter (PM), relative humidity, temperature, and so forth.

The next diagram exhibits the conceptual structure:

Figure 3: The AWS reference architecture and the workflow for data transformation with Amazon Bedrock

Determine 2: The AWS reference structure and the workflow for knowledge transformation with Amazon Bedrock

Answer walkthrough

The answer reads uncooked knowledge recordsdata (CSV and JSON recordsdata) from Amazon Simple Storage Service (Amazon S3) (Step 1) and checks if it has seen the system kind (or knowledge format) earlier than. If sure, the answer retrieves and executes the previously-generated python codes (Step 2) and the reworked knowledge is saved in S3 (Step 10). The answer solely invokes the LLM for brand new system knowledge file kind (code has not but been generated). That is executed to optimize efficiency and decrease value of LLM invocation. If the Python code shouldn’t be out there for a given system knowledge, the answer notifies the operator to examine the brand new knowledge format (Step 3 and Step 4). At the moment, the operator checks the brand new knowledge format and validates if the brand new knowledge format is from a brand new producer (Step 5). Additional, the answer checks if the file is CSV or JSON. If it’s a CSV file, the info will be straight transformed to a Pandas knowledge body by a Python perform with out LLM invocation. If it’s a JSON file, the LLM is invoked to generate a Python perform that creates a Pandas knowledge body from the JSON payload contemplating its schema and the way nested it’s (Step 6).

We invoke the LLM to generate Python features that manipulate the info with three completely different prompts (enter string):

  1. The primary invocation (Step 6) generates a Python perform that converts a JSON file to a Pandas knowledge body. JSON recordsdata from producers have completely different schemas. Some enter knowledge makes use of a pair of worth kind and worth for a measurement. The latter format leads to knowledge frames containing one column of worth kind and one column of worth. Such columns should be pivoted.
  2. The second invocation (Step 7) determines if the info must be pivoted and generates a Python perform for pivoting if wanted. One other subject of the enter knowledge is that the identical air high quality measurement can have completely different names from completely different producers; for instance, “P1” and “PM1” are for a similar kind of measurement.
  3. The third invocation (Step 8) focuses on knowledge cleansing. It generates a Python perform to transform knowledge frames to a standard knowledge format. The Python perform could embody steps for unifying column names for a similar kind of measurement and dropping columns.

All LLM generated Python codes are saved within the repository (Step 9) in order that this can be utilized to course of each day uncooked system knowledge recordsdata for transformation into a standard format.

The information is then saved in Amazon S3 (Step 10) and will be printed to OpenAQ so different organizations can use the calibrated air high quality knowledge.

The next screenshot exhibits the proposed frontend for illustrative functions solely as the answer is designed to combine with Afri-SET’s current backend system


The proposed technique minimizes LLM invocations, thus optimizing value and assets. The answer solely invokes the LLM when a brand new knowledge format is detected. The code that’s generated is saved, in order that an enter knowledge with the identical format (seen earlier than) can reuse the code for knowledge processing.

A human-in-the-loop mechanism safeguards knowledge ingestion. This occurs solely when a brand new knowledge format is detected to keep away from overburdening scarce Afri-SET assets. Having a human-in-the-loop to validate every knowledge transformation step is non-obligatory.

Computerized code technology reduces knowledge engineering work from months to days. Afri-SET can use this resolution to mechanically generate Python code, primarily based on the format of enter knowledge. The output knowledge is reworked to a standardized format and saved in a single location in Amazon S3 in Parquet format, a columnar and environment friendly storage format. If helpful, it may be additional prolonged to an information lake platform that makes use of AWS Glue (a serverless knowledge integration service for knowledge preparation) and Amazon Athena (a serverless and interactive analytics service) to research and visualize knowledge. With AWS Glue customized connectors, it’s easy to switch knowledge between Amazon S3 and different purposes. Moreover, it is a no-code expertise for Afri-SET’s software program engineer to effortlessly construct their knowledge pipelines.


This resolution permits for straightforward knowledge integration to assist broaden cost-effective air high quality monitoring. It provides data-driven and knowledgeable laws, fostering group empowerment and inspiring innovation.

This initiative, geared toward gathering exact knowledge, is a big step in the direction of a cleaner and more healthy atmosphere. We consider that AWS know-how can assist handle poor air high quality by way of technical options much like the one described right here. If you wish to prototype related options, apply to the AWS Health Equity initiative.

As at all times, AWS welcomes your suggestions. Please go away your ideas and questions within the feedback part.

Concerning the authors

Sandra Subject is an Environmental Fairness Chief at AWS. On this function, she leverages her engineering background to seek out new methods to make use of know-how for fixing the world’s “To Do listing” and drive optimistic social impression. Sandra’s journey consists of social entrepreneurship and main sustainability and AI efforts in tech corporations.

Qiong (Jo) Zhang, PhD, is a Senior Accomplice Options Architect at AWS, specializing in AI/ML. Her present areas of curiosity embody federated studying, distributed coaching, and generative AI.  She holds 30+ patents and has co-authored 100+ journal/convention papers. She can be the recipient of the Greatest Paper Award at IEEE NetSoft 2016, IEEE ICC 2011, ONDM 2010, and IEEE GLOBECOM 2005.

Gabriel Verreault is a Senior Accomplice Options Architect at AWS for the Industrial Manufacturing section. Gabriel works with AWS companions to outline, construct, and evangelize options round Sensible Manufacturing, Sustainability and AI/ML. Gabriel additionally has experience in industrial knowledge platforms, predictive upkeep, and mixing AI/ML with industrial workloads.

Venkatavaradhan (Venkat) Viswanathan is a World Accomplice Options Architect at Amazon Internet Companies. Venkat is a Expertise Technique Chief in Information, AI, ML, generative AI, and Superior Analytics. Venkat is a World SME for Databricks and helps AWS prospects design, construct, safe, and optimize Databricks workloads on AWS.

Leave a Reply

Your email address will not be published. Required fields are marked *