Tech 21. Oct. 2023

Unlock the Power of AI: Transcending Newspaper Photos to Create Structured Event Announcements.

In rural areas, smaller events are typically advertised through flyers or newspaper articles, often in non-digital or unstructured formats. This presents the challenge of leveraging easily created snapshot photos, such as those taken with a smartphone, to convert these materials into structured event announcements.

My proposed approach

The approach may appear straightforward and involves a series of interconnected technologies:

  1. Capture an image using a smartphone.
  2. Employ image analysis software with OCR capabilities to extract specific information, particularly text.
  3. Utilize AI tools to ascertain whether the extracted information pertains to event announcements.
  4. Employ AI tools to generate structured data.

Beyond this stage, a separate journey unfolds, involving the classification, translation, and scopification of the event. However, these aspects will not be addressed here.

Step 1: Starting with the photo

While taking a photo is a straightforward task, it’s essential to consider cropping the appropriate region before analyzing the content. This is crucial because smartphones may capture more than just the intended flyer or article.

Here is the original snapshot:

Original

As a proof-of-concept, I manually cropped the article using Mac Preview.

Cropped

Step 2: OCR

Subsequently, I also perform text extraction using the text selection feature in Mac Preview.

Seenotretter berichtet von seinen Erlebnissen ANKLAM. „Grenzen fanden wir keine auf dem Mittel. meer, außer den Grenzen zwischen Leben und Tod” heißt es in dem Buch „Das Schimmern der See” von Adrian Pourviseh. Dieses schildert Erlebnisse von Rettungskräften der Crew der Sea-Watch 3 auf dem Mittelmeer bei der Rettung von Menschen. Der Autor war bei den Erlebnissen hautnah dabei, da er selbst Mitglied der Seenotretter war. Adrian Pourviseh liest am Auf seiner Lesetour Dienstag in Anklam. macht Adrian Pourviseh FOTO: SEA-WATCH nun auch Halt in Ank. lam. Am 24. Oktober um kratiebahnhof aus dem 19 Uhr wird er im Demo- Buch vorlesen.

At this stage, I prefer to take a flexible approach and observe how far we can progress. However, deeper challenges are already becoming evident, so please continue reading.

Step 3: Determine whether the information pertains to an event announcement.

As a proof of concept, I am currently utilizing ChatGPT manually through a web browser UI with the following prompt:

Determine if the following content contains an event announcement.

The answer is:

Yes, the provided content contains an event announcement. It mentions that Adrian Pourviseh, the author of the book “Das Schimmern der See,” will be reading from his book at a specific location and time, which is an event. The event is scheduled for October 24th at 19:00 at the Demo-Kratiebahnhof in Anklam.

For API usage, the prompt needs to be modified to emulate an API and provide JSON data in response. However, for now, let’s proceed as is.

Step 4: How to obtain structured data?

Creating structured data is an enjoyable process with OpenAI’s ChatGPT. Let’s give it a try with a prompt:

Act as an api. Return json with the interface.

interface eventAnnouncement {
startDateTime: sting; // ISO
endDateTime: string; // ISO
location: string; // where does the event take place
title: string;
description: string; // summary of the given text
}

Extract structured data for the followng event announcement.

ChatGPT returns:

{
    "startDateTime": "2023-10-24T19:00:00",
    "endDateTime": "2023-10-24T20:00:00",
    "location": "Demo-Kratiebahnhof, Anklam",
    "title": "Adrian Pourviseh Book Reading",
    "description": "Adrian Pourviseh will be reading from his book 'Das Schimmern der See,' sharing experiences of the Sea-Watch 3 rescue crew in the Mediterranean."
}

Let’s perform a manual check:

  • Date and time: The correct date and start time are provided. While no end time is specified, we assume it to be one hour, which is acceptable.
  • Location: In general, the location is correct. However, due to the print article, the wording is not perfect. It should read as “Demokratiebahnhof”.
  • Title and description: Both are excellent. Perhaps we should verify the accuracy in German, as the original content was in German.

Just add “Answer in German please.” to the promt:

{
    "startDateTime": "2023-10-24T19:00:00",
    "endDateTime": "2023-10-24T20:00:00",
    "location": "Demo-Kratiebahnhof, Anklam",
    "title": "Lesung von Adrian Pourviseh",
    "description": "Adrian Pourviseh wird aus seinem Buch 'Das Schimmern der See' vorlesen, in dem er seine hautnahen Erlebnisse als Mitglied der Seenotretter während Rettungseinsätzen auf dem Mittelmeer beschreibt."
}

Sounds great!

Regarding the location challenge, we can take a cue from our approach to other challenges, such as pinpointing the exact geographic location from given strings. It might be beneficial to leverage Google Maps. Here I will use a custom geocoding service, which initially utilizes Google Maps search and then complements it with data from genomes.org.

Let’s see the result for “Demo-Kratiebahnhof, Anklam”.

{
    "geonamesId": 2956018,
    "googlePlaceId": "ChIJHWFbqNmtq0cRks5xlAk8oLM",
    "wikidataId": "Q488513",
    "googleMyBusinessId": null,
    "name": "Demokratiebahnhof Anklam",
    "localName": "Demokratiebahnhof",
    "type": "community",
    "geo": {
        "point": {
           "lat": 53.8558,
           "lng": 13.7018
        },
        "box": {
           "north": 53.8571600302915,
           "east": 13.7031130802915,
           "south": 53.8544620697085,
           "west": 13.7004151197085
        }
    },
    "location": "Demo-Kratiebahnhof, Anklam",
    "address": "Bahnhofstraße 1, 17389 Anklam, Deutschland",
    "hierarchy": {
        "community": {
           "geonameId": 2956018,
           "name": "Anklam",
           "wikidataId": "Q488513"
        },
        "municipality": {
           "geonameId": 6550720,
           "name": "Anklam",
           "zip": "17389",
           "wikidataId": null
        },
        "county": {
           "geonameId": 8648415,
           "name": "Vorpommern-Greifswald"
        },
        "state": {
           "geonameId": 2872567,
           "name": "Mecklenburg-Vorpommern"
        },
        "country": {
           "geonameId": 2921044,
           "ISO3166": "DE",
           "name": "Deutschland"
        }
    }
}

Excellent. So, even with the imperfect spelling from OCR, we can confidently proceed without encountering any issues in the end.

Check some more examples

A manual proof of concept will never cover all the details that are sure to arise with live mass data. Testing a single data item is insufficient, even for a conceptual check. Let’s explore a few more examples to gain a more comprehensive understanding.

Second example

Here’s a cropped image of another article:

Cropped

Here’s the text extracted by OCR:

Zum Tag der Bibliotheken

Bücher trödeln

ANKLAM. Bücherwürmer DVDs und natürlich jede aufgepasst! Am Dienstag, Menge Romane über den

  1. Oktober, ist nicht nur Ladentisch. Lediglich die Tag der Bibliotheken. In PS3-Konsolenspiele kosten der Rathaushalle in Ank- ein wenig mehr. Wer noch lam kann dann auch von keinen

Bibliotheksaus-

10 bis 17 Uhr der ein oder weis hat, kann an dem Tag andere Schatz gefunden zusätzlich sparen. Beim werden. Denn dann findet Abschließen eines Biblio-dort ein großer Bücher- theksausweises zahlt man flohmarkt statt. Verkauft dann nur die halbe Jahres-werden ausgesonderte Me- gebühr. Für Erwachsene dien und Geschenke. Zum macht das dann 10 Euro

Schnäppchenpreis von nur

für 365 Tage Lesevergnü-

50 Cent gehen dabei Kin- gen, Kinder von 3 bis 13

derbücher,

Sachbücher, Jahren zahlen nur 1,50

Reiseführer, Hörbücher, Euro.

Am 24. Oktober werden wieder ausgesonderte Medien der Stadtbibliothek zum Verkauf angeboten.

FOTO: MAXI KOGLIN

The ChatGPT response to this provided text is:

{
   "startDateTime": "2023-10-24T10:00:00Z",
   "endDateTime": "2023-10-24T17:00:00Z",
   "location": "Rathaushalle in Anklam",
   "title": "Tag der Bibliotheken - Büchertrödelmarkt",
   "description": "Am Dienstag, den 24. Oktober, findet der Tag der Bibliotheken statt. In der Rathaushalle in Anklam gibt es von 10:00 bis 17:00 Uhr einen großen Büchertrödelmarkt. Es werden ausgesonderte Medien der Stadtbibliothek verkauft, darunter Kinderbücher, Sachbücher, Reiseführer, Hörbücher und Geschenke. Erwachsene zahlen nur 10 Euro für 365 Tage Lesevergnügen, Kinder im Alter von 3 bis 13 Jahren zahlen nur 1,50 Euro. Nutzen Sie diesen Tag, um Schnäppchen zu ergattern und Ihre Bibliotheksausweisgebühr zu reduzieren."
}

Let’s conduct a manual assessment:

  • Date and time: The provided date, start time, and end time are all correct. Perfect.
  • Location: The location is accurate, and Google Maps successfully geocodes this string. Perfect.
  • Title and description: The title differs from the article’s title and text, but, in all seriousness, it serves as a better event announcement. However, the description is somewhat misleading, possibly due to the text’s inherent ambiguity.

How can we address the issue with the description? One factor contributing to this is the OCR’s confusion when dealing with two-column text. It might be beneficial to rectify this. To be on the safer side, we should place more trust in the original content and make fewer alterations.

Let’s temporarily split the snapshot manually to enable a more accurate OCR with the correct text flow.

Col 1

Col 2

Now, the text from the article reads as follows, which is a significant improvement:

ANKLAM. Bücherwürmer aufgepasst! Am Dienstag,

  1. Oktober, ist nicht nur Tag der Bibliotheken. In der Rathaushalle in Ank-lam kann dann auch von 10 bis 17 Uhr der ein oder andere Schatz gefunden werden. Denn dann findet dort ein großer Bücher-flohmarkt statt. Verkauft werden ausgesonderte Medien und Geschenke. Zum Schnäppchenpreis von nur

50 Cent gehen dabei Kin-derbücher,

Sachbücher,

Reiseführer, Hörbücher,

DVDs und natürlich jede Menge Romane über den Ladentisch. Lediglich die PS3-Konsolenspiele kosten ein wenig mehr. Wer noch keinen

_ Bibliotheksaus-

weis hat, kann an dem Tag zusätzlich sparen. Beim Abschließen eines Biblio-theksausweises zahlt man dann nur die halbe Jahres-gebühr. Für Erwachsene macht das dann 10 Euro für 365 Tage Lesevergnt-gen, Kinder von 3 bis 13

Jahren zahlen nur 1,50

Euro.

Furthermore, we’ll experiment with a modified prompt:

Act as an api. Return json with the interface.

interface eventAnnouncement { startDateTime: sting; // ISO endDateTime: string; // ISO location: string; // where does the event take place title: string; detailText: string; // text with improved writing }

Extract structured data for the following event announcement. Answer in German please.

The structured data produced by ChatGPT is as follows:

{
  "startDateTime": "2023-10-24T10:00:00Z",
  "endDateTime": "2023-10-24T17:00:00Z",
  "location": "Rathaushalle in Ank-lam",
  "title": "Großer Bücherflohmarkt in Ank-lam",
  "detailText": "Bücherwürmer aufgepasst! Am Dienstag, 24. Oktober, ist nicht nur Tag der Bibliotheken. In der Rathaushalle in Ank-lam kann dann auch von 10 bis 17 Uhr der ein oder andere Schatz gefunden werden. Denn dann findet dort ein großer Bücherflohmarkt statt. Verkauft werden ausgesonderte Medien und Geschenke. Zum Schnäppchenpreis von nur 50 Cent gehen dabei Kinderbücher, Sachbücher, Reiseführer, Hörbücher, DVDs und natürlich jede Menge Romane über den Ladentisch. Lediglich die PS3-Konsolenspiele kosten ein wenig mehr. Wer noch keinen Bibliotheksausweis hat, kann an dem Tag zusätzlich sparen. Beim Abschließen eines Bibliotheksausweises zahlt man dann nur die halbe Jahresgebühr. Für Erwachsene macht das dann 10 Euro für 365 Tage Lesevergnügen, Kinder von 3 bis 13 Jahren zahlen nur 1,50 Euro."
}

The result is significantly improved, and the text is in good shape. However, there is an issue with the city name “Anklam”, which appears to be broken by a hyphen. It’s challenging to envision a solution at the moment, so we will leave this as an open issue.

Third example

Drawing from the lessons learned in previous iterations, we have refined the process to some extent. Let’s reevaluate with another example.

Cropped

From the outset, we extract the text with respect to columns, which is still a manual process at this point.

Bei dieser Krimi-Lesung kann man sich gruseln

ANKLAM. Die Stadtbibliothek Anklam lädt am

  1. Oktober zum Gruseln

ein. Denn dann wird der Berliner Autor Richard Bandes aus seinem neusten Krimi: „Nebel über der Uckermark” lesen. Kriminalkommissarin Carla Stach bekommt es dabei mit einem rätselhaften Fall zu tun, in dem eine Hellseherin angeblich einen Mord vorausgesehen hat Die Lesung findet in der Rathaushalle am Markt um

19 Uhr statt. Der Eintritt kostet 10 Euro. Karten gibt es in der Bibliothek oder an der Abendkasse.

Once again, employing ChatGPT, we obtain this result:

{
    "startDateTime": "2023-10-26T19:00:00Z",
    "endDateTime": "2023-10-26T20:00:00Z",
    "location": "Rathaushalle am Markt, Anklam",
    "title": "Krimi-Lesung: 'Nebel über der Uckermark'",
    "detailText": "Die Stadtbibliothek Anklam lädt am 26. Oktober zum Gruseln ein. Denn dann wird der Berliner Autor Richard Bandes aus seinem neusten Krimi: 'Nebel über der Uckermark' lesen. Kriminalkommissarin Carla Stach bekommt es dabei mit einem rätselhaften Fall zu tun, in dem eine Hellseherin angeblich einen Mord vorausgesehen hat. Die Lesung findet in der Rathaushalle am Markt um 19 Uhr statt. Der Eintritt kostet 10 Euro. Karten gibt es in der Bibliothek oder an der Abendkasse."
}

Let’s perform a manual check:

  • Date and time: The date and start time are correct. In the absence of an end time, we assumed one hour, which is acceptable.
  • Location: Impressively, the location is precisely identified, even though the text starts with ‘Stadtbibliothek Anklam’ and later mentions ‘Rathaushalle am Markt, Anklam’. And we have already verified this with Google Maps.
  • Title and description: The title differs from the article title but aligns perfectly with the content. The description is the original text with hyphen-related issues resolved. So, in this case, it’s a remarkable outcome!

Here’s an improved phrasing for your statement:

What we have learned from this challenge?

By leveraging basic tools such as Mac Preview, ChatGPT, and Google Maps, we can address the challenge for a variety of scenarios. However, during our initial manual proof of concept, we identified some specific issues that require more efficient solutions:

  1. Automated Image Cropping: One pressing concern is how to automatically crop an image to the precise rectangle of the article. This process necessitates a more streamlined solution.

  2. Extracting Text from Multi-Column Layouts with OCR: Extracting text from documents with two or more columns has proven to be a challenge, as it required a workaround during manual efforts. We seek an improved method for this task.

  3. Handling Hyphens in OCR: OCR processes are currently struggling with hyphens, which can be quite bothersome. Exploring alternative OCR solutions or refining ChatGPT prompts for better precision might help address this issue. Notably, this is crucial for maintaining the accuracy of proper names, such as “Ank-lam,” which should correctly read as “Anklam.”

In addition to these specific challenges, the next step in this project involves implementing all these processes through API calls. While utilizing ChatGPT and geocoding via APIs is well-established, the two less familiar tasks are: 1) automating image cropping and 2) text extraction through API-based OCR.

This forward-looking approach will make the entire workflow more efficient and scalable, thus increasing the overall effectiveness of the solution.