Databases returns None, NoneType object

Hi, I tried out the code snipped below and it returns None, an object of type NoneType. Does this mean the databases is empty? or that my annotations did not get saved? because I have saved them through the UI. What do you think might be the problem?

Thanks in advance

from prodigy.components.db import connect
from collections import defaultdict

db = connect()
examples = db.get_dataset("Tabuk_city")
label_stats = defaultdict(list)
for eg in examples:
    if eg["answer"] == "accept":  # you probably want to exclude ignored/rejected answers?
        for span in eg.get("spans", []):
            word = eg["text"][span["start"]:span["end"]]  # slice of the text
            label = span["label"]


Hi! What exactly in your code is None? Could you post the exact traceback? That makes it a lot easier to help debugging.

If the examples are None, this indicates that there's no dataset of the given name in the database.

Thanks for replying so quickly.
Yes, it is the examples that's none. Even though I have saved the annotations through the UI, what could be the problem?
this is the error message:

   6 print(examples)
      7 label_stats = defaultdict(list)
----> 8 for eg in examples:
      9     if eg["answer"] == "accept":  # you probably want to exclude ignored/rejected answers?
     10         for span in eg.get("spans", []):

TypeError: 'NoneType' object is not iterable

Does creating different sessions makes a difference for when to retrieve the annotations? Do I need so specify which session's annotations or once I use the above code I am able to retrieve all annotations?

Are you sure this is the correct dataset name? Keep in mind that names are case-sensitive, so maybe you've spelled it differently? You can print(db.datasets) to see a list of all available dataset names in the database.

1 Like

I used db.datasets it returned an empty list. But when I use the following command I am able to retrieve the annotations: prodigy db-in dataset_name /path/to/data.jsonl. Idk what I'm missing here..

Hi Aisha,

It sounds like the annotations weren't actually saved on the Prodigy UI. I'm guessing /path/to/data.jsonl contains your input dataset? Which command did you use to run Prodigy? Did you hit the save button on the UI, and when you did, was there a log entry on the console? It should have said something like "Saved 10 annotations to DB ...". And then this DB should definitely show up when running print(db.datasets) like Ines said. Note that if you just do a couple of annotations on the UI, these won't be automatically be saved. For efficiency reasons, Prodigy saves the annotations out after every batch of 10 by default (though you can change this setting).

If you use db-in it's creating a new database from the input data, which is different to creating new annotations and saving these.

1 Like

Yes, /path/to/data.jsonl is my input dataset.
I did hit the save button and saw a message saying something like "annotations saved!" but no log entry on the console.
I have setup the prodigy.jsonl file as follows:

  "db": "sqlite",
  "db_settings": {
    "sqlite": {
      "name": "prodigy.db",
      "path": "/home/ubuntu/.prodigy"

Does everything look ok?

Never mind I got this. Thank!!!